curl-fuzzer C++ reference
Loading...
Searching...
No Matches
proto_fuzzer::HappyEyeballsMockServer Class Reference

Resolver-lane peer that exposes two cached loopback addresses and returns unconnected non-blocking sockets, so every address reaches curl's normal TCP connect path. More...

#include <happy_eyeballs_mock_server.h>

Inheritance diagram for proto_fuzzer::HappyEyeballsMockServer:
proto_fuzzer::MockServerBase proto_fuzzer::InterfaceOptionMockServer

Public Member Functions

 HappyEyeballsMockServer ()
 Construct an idle peer with no listener or accepted connections.
 ~HappyEyeballsMockServer () override
 Release listeners and accepted loopback peers.
void Install (CURL *easy) override
 Install the shared socket callbacks and remember the easy handle for the later resolve/port/timeout setopts.
void ConfigureRequestData (ScenarioRequestData *request_data) override
 Replace the resolver lane's single-address mapping with a two-address entry for the fixed canonical host and point the URL's effective port at the ephemeral listener.
std::size_t opened_socket_count () const
std::size_t accepted_peer_count () const
int listener_port () const
Public Member Functions inherited from proto_fuzzer::MockServerBase
virtual ~MockServerBase ()
 Out-of-line destructor so MockConnection can stay forward-declared in the base header (its complete type is only needed where unique_ptr is instantiated for destruction).
virtual void ObserveState ()
 Default no-op for peers without protocol-specific observations.
CURLcode DriveScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Run 'scenario' to completion on 'easy': allocate a multi, attach 'easy', delegate protocol-specific work to RunLoop, consume its completion message, and clean up.
virtual CURLcode DriveEasyScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario, bool use_events=false)
 Run through the public easy entrypoint when a protocol mock can preload all peer work before curl takes control.
virtual ConnectOnlyRunStats DriveConnectOnlyScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Establish a CONNECT_ONLY transport, then perform bounded direct I/O.
void SetMultiObserver (MultiObserver observer)
 Register an observer invoked with the live multi handle after 'easy' is attached and before the drive loop starts.
MockConnection * connection ()

Protected Member Functions

curl_socket_t HandleOpenSocket (curlsocktype purpose, struct curl_sockaddr *address) override
 Hand curl a fresh unconnected socket for every address its happy-eyeballs filter decides to race.
SocketSetupDisposition GetSocketSetupDisposition (curl_socket_t curlfd, curlsocktype purpose) const override
 Stream peers must follow curl's ordinary connect path; unlike the socketpair mocks, the descriptor is deliberately not connected yet.
void RunLoop (CURLM *multi, CURL *easy, const curl::fuzzer::proto::Scenario &scenario) override
 Run a bounded perform loop that also accepts real loopback connections and serves their response scripts.
Protected Member Functions inherited from proto_fuzzer::MockServerBase
 MockServerBase (MultiDrivePolicy drive_policy=MultiDrivePolicy::kPerform)
 Construct an empty base instance with a fixed multi-drive policy.
virtual void HandleDetachedMulti (CurlMultiPtr multi)
 Dispose of or retain the multi after its easy handle has been removed.
MultiSocketDriver * multi_socket_driver ()
 Expose the callback state installed for the current socket-action drive.
std::size_t additional_handle_cleanup_count () const
void ResumeResponseIfRequested (CURL *easy)
 Resume receive-side callback output at one bounded drive boundary when the dedicated API plan requested it.
void ApplyPendingBackpressure ()
 Apply the BackpressureConfig cached by DriveScenario to the new connection_.

Additional Inherited Members

Public Types inherited from proto_fuzzer::MockServerBase
using MultiObserver = std::function<void(CURLM*)>
 Callback type used to publish the driving multi handle to observers.
Static Protected Member Functions inherited from proto_fuzzer::MockServerBase
static int WaitOnMultiFdset (CURLM *multi, CURLMcode *rc)
 Wait on curl's fdset with a short timeout.
static void ProbeMultiPollset (CURLM *multi)
 Ask curl to construct and inspect its connection-filter pollset without waiting.
static bool MultiPollsetWantsWrite (CURLM *multi, curl_socket_t socket)
 Inspect one socket's current writable interest through curl's public multi fdset API.
static bool UsesTimedDrive (const curl::fuzzer::proto::Scenario &scenario)
 Treat a non-default BackpressureConfig as an explicit request for the slower, timed drive policy.
Protected Attributes inherited from proto_fuzzer::MockServerBase
std::unique_ptr< MockConnection > connection_
 The per-scenario MockConnection, lazily created by HandleOpenSocket().
int pending_recv_buf_bytes_
 Cached SO_RCVBUF/SO_SNDBUF setting in bytes.
std::size_t pending_drain_limit_
 Cached per-call DrainIncoming byte budget.
MultiSocketDriver * multi_socket_driver_
 Non-owning pointer into DriveScenario's stack.
std::size_t additional_handle_cleanup_count_
 Number of application-created handles, excluding the caller's parent, successfully removed from the current multi and cleaned up.
bool resume_response_
 True only for an API-plan multi drive with its one-shot write callback.
MultiObserver multi_observer_
 Observer receiving the live multi handle at the start of a drive.
Static Protected Attributes inherited from proto_fuzzer::MockServerBase
static constexpr int kMaxDriveIterations = 512
 Hard operation budget for one scenario.
static constexpr int kMaxIdleIterations = 8
 Consecutive no-progress budget for ordinary scenarios.
static constexpr int kMaxTimedIdleIterations = 256
 Explicit backpressure scenarios get a larger idle budget and may use the short timed wait above.

Detailed Description

Resolver-lane peer that exposes two cached loopback addresses and returns unconnected non-blocking sockets, so every address reaches curl's normal TCP connect path.

The first address deliberately has a full accept queue and stays in progress; the second address has a real listener that serves the scenario response to the winner.

Definition at line 33 of file happy_eyeballs_mock_server.h.

Constructor & Destructor Documentation

◆ ~HappyEyeballsMockServer()

proto_fuzzer::HappyEyeballsMockServer::~HappyEyeballsMockServer ( )
override

Release listeners and accepted loopback peers.

curl owns every socket it received from HandleOpenSocket; only the accepted server halves, listeners, and backlog-filling clients are closed here.

Definition at line 113 of file happy_eyeballs_mock_server.cc.

Member Function Documentation

◆ accepted_peer_count()

std::size_t proto_fuzzer::HappyEyeballsMockServer::accepted_peer_count ( ) const
inline
Returns
Number of connections accepted by the serving listener.

Definition at line 49 of file happy_eyeballs_mock_server.h.

◆ ConfigureRequestData()

void proto_fuzzer::HappyEyeballsMockServer::ConfigureRequestData ( ScenarioRequestData * request_data)
overridevirtual

Replace the resolver lane's single-address mapping with a two-address entry for the fixed canonical host and point the URL's effective port at the ephemeral listener.

This runs after ScenarioRequestData has installed its own list, so the race mapping is the one curl loads.

Parameters
request_dataInstalled request state; unused by this transport.

Reimplemented from proto_fuzzer::MockServerBase.

Definition at line 140 of file happy_eyeballs_mock_server.cc.

◆ GetSocketSetupDisposition()

SocketSetupDisposition proto_fuzzer::HappyEyeballsMockServer::GetSocketSetupDisposition ( curl_socket_t curlfd,
curlsocktype purpose ) const
overrideprotectedvirtual

Stream peers must follow curl's ordinary connect path; unlike the socketpair mocks, the descriptor is deliberately not connected yet.

Parameters
curlfdDescriptor returned by HandleOpenSocket.
purposeSocket role assigned by curl.
Returns
Always kNeedsSetup.

Reimplemented from proto_fuzzer::MockServerBase.

Definition at line 199 of file happy_eyeballs_mock_server.cc.

◆ HandleOpenSocket()

curl_socket_t proto_fuzzer::HappyEyeballsMockServer::HandleOpenSocket ( curlsocktype purpose,
struct curl_sockaddr * address )
overrideprotectedvirtual

Hand curl a fresh unconnected socket for every address its happy-eyeballs filter decides to race.

The sockopt callback reports kNeedsSetup, so curl performs the real non-blocking connect on this descriptor.

Parameters
purposeSocket role; only outbound IPCXN sockets are produced.
addresscurl's mutable destination description.
Returns
A non-blocking socket, or CURL_SOCKET_BAD when the attempt budget or descriptor limits are reached.

Implements proto_fuzzer::MockServerBase.

Definition at line 174 of file happy_eyeballs_mock_server.cc.

◆ Install()

void proto_fuzzer::HappyEyeballsMockServer::Install ( CURL * easy)
overridevirtual

Install the shared socket callbacks and remember the easy handle for the later resolve/port/timeout setopts.

The zero happy-eyeballs delay makes the second address eligible as soon as the first connect is in progress.

Parameters
easyEasy handle that will drive this peer.

Reimplemented from proto_fuzzer::MockServerBase.

Reimplemented in proto_fuzzer::InterfaceOptionMockServer.

Definition at line 126 of file happy_eyeballs_mock_server.cc.

◆ listener_port()

int proto_fuzzer::HappyEyeballsMockServer::listener_port ( ) const
inline
Returns
Ephemeral loopback port, or zero when listener setup failed.

Definition at line 52 of file happy_eyeballs_mock_server.h.

◆ opened_socket_count()

std::size_t proto_fuzzer::HappyEyeballsMockServer::opened_socket_count ( ) const
inline
Returns
Number of sockets handed to curl through HandleOpenSocket.

Definition at line 46 of file happy_eyeballs_mock_server.h.

◆ RunLoop()

void proto_fuzzer::HappyEyeballsMockServer::RunLoop ( CURLM * multi,
CURL * easy,
const curl::fuzzer::proto::Scenario & scenario )
overrideprotectedvirtual

Run a bounded perform loop that also accepts real loopback connections and serves their response scripts.

Explicit short select waits let the kernel report connect completion without busy-spinning.

Parameters
multiMulti handle already containing easy.
easyEasy handle driving this peer.
scenarioSource of the bounded response scripts.

Implements proto_fuzzer::MockServerBase.

Definition at line 224 of file happy_eyeballs_mock_server.cc.


The documentation for this class was generated from the following files: