curl-fuzzer C++ reference
Loading...
Searching...
No Matches
multi_socket_driver.h
Go to the documentation of this file.
1/*
2 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3 *
4 * SPDX-License-Identifier: curl
5 */
6
9
10#ifndef PROTO_FUZZER_MULTI_SOCKET_DRIVER_H_
11#define PROTO_FUZZER_MULTI_SOCKET_DRIVER_H_
12
13#include <curl/curl.h>
14
15#include <array>
16#include <cstddef>
17#include <cstdint>
18
19namespace proto_fuzzer {
20
31 public:
33 struct DriveResult {
35 CURLMcode code = CURLM_OK;
37 bool made_progress = false;
38 };
39
42
43 MultiSocketDriver(const MultiSocketDriver&) = delete;
44 MultiSocketDriver& operator=(const MultiSocketDriver&) = delete;
45
46 bool Install(CURLM* multi);
47
48 CURLMcode Start(int* running_handles);
49
50 DriveResult DriveReady(int* running_handles);
51
52 void ProbeControlApis();
53
55 bool watch_exhausted() const { return watch_exhausted_; }
56
57 private:
59 struct Watch {
60 curl_socket_t socket = CURL_SOCKET_BAD;
61 int interest = CURL_POLL_NONE;
62 bool active = false;
63 };
64
65 static int SocketCallback(CURL* easy, curl_socket_t socket, int what, void* user_data, void* socket_data);
66
67 static int TimerCallback(CURLM* multi, long timeout_ms, void* user_data);
68
69 int UpdateSocket(curl_socket_t socket, int what, void* socket_data);
70
71 int UpdateTimer(long timeout_ms);
72
73 Watch* FindWatch(curl_socket_t socket);
74
75 Watch* FindFreeWatch();
76
81 static constexpr std::size_t kMaxWatches = 16;
82
83 CURLM* multi_;
84 std::array<Watch, kMaxWatches> watches_;
85 long timeout_ms_;
86 bool timer_pending_;
87 bool watch_exhausted_;
88 std::uint64_t generation_;
89};
90
91} // namespace proto_fuzzer
92
93#endif // PROTO_FUZZER_MULTI_SOCKET_DRIVER_H_
CURLMcode Start(int *running_handles)
Start libcurl's socket state machine through the documented timeout pseudo-socket without waiting for...
bool Install(CURLM *multi)
Install socket/timer callbacks on a caller-owned multi before adding an easy handle.
MultiSocketDriver()
Construct detached callback state.
void ProbeControlApis()
Exercise the wakeup and timeout-query APIs from a valid live-multi state.
~MultiSocketDriver()
The owner deliberately destroys this after curl_multi_cleanup, so there is no callback deregistration...
DriveResult DriveReady(int *running_handles)
Run one bounded, non-blocking event-loop turn: poll the callback-provided watch set with a zero timeo...
Result from one non-blocking event-loop turn.
bool made_progress
True when an action ran or callback/handle state changed.
CURLMcode code
libcurl's result for the last socket action in the turn.