| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2026 Steve Gerbino
|
2 |
|
// Copyright (c) 2026 Steve Gerbino
|
| 3 |
|
|
3 |
|
|
| 4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
| 5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
| 6 |
|
|
6 |
|
|
| 7 |
|
// Official repository: https://github.com/cppalliance/corosio
|
7 |
|
// Official repository: https://github.com/cppalliance/corosio
|
| 8 |
|
|
8 |
|
|
| 9 |
|
|
9 |
|
|
| 10 |
|
#ifndef BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_OP_HPP
|
10 |
|
#ifndef BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_OP_HPP
|
| 11 |
|
#define BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_OP_HPP
|
11 |
|
#define BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_OP_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
#include <boost/corosio/detail/platform.hpp>
|
13 |
|
#include <boost/corosio/detail/platform.hpp>
|
| 14 |
|
|
14 |
|
|
| 15 |
|
#if BOOST_COROSIO_HAS_EPOLL
|
15 |
|
#if BOOST_COROSIO_HAS_EPOLL
|
| 16 |
|
|
16 |
|
|
| 17 |
|
#include <boost/corosio/detail/config.hpp>
|
17 |
|
#include <boost/corosio/detail/config.hpp>
|
| 18 |
|
#include <boost/corosio/io/io_object.hpp>
|
18 |
|
#include <boost/corosio/io/io_object.hpp>
|
| 19 |
|
#include <boost/corosio/endpoint.hpp>
|
19 |
|
#include <boost/corosio/endpoint.hpp>
|
| 20 |
|
#include <boost/capy/ex/executor_ref.hpp>
|
20 |
|
#include <boost/capy/ex/executor_ref.hpp>
|
| 21 |
|
|
21 |
|
|
| 22 |
|
#include <boost/capy/error.hpp>
|
22 |
|
#include <boost/capy/error.hpp>
|
| 23 |
|
|
23 |
|
|
| 24 |
|
|
24 |
|
|
| 25 |
|
#include <boost/corosio/detail/make_err.hpp>
|
25 |
|
#include <boost/corosio/detail/make_err.hpp>
|
| 26 |
|
#include <boost/corosio/detail/dispatch_coro.hpp>
|
26 |
|
#include <boost/corosio/detail/dispatch_coro.hpp>
|
| 27 |
|
#include <boost/corosio/detail/scheduler_op.hpp>
|
27 |
|
#include <boost/corosio/detail/scheduler_op.hpp>
|
| 28 |
|
#include <boost/corosio/detail/endpoint_convert.hpp>
|
28 |
|
#include <boost/corosio/detail/endpoint_convert.hpp>
|
| 29 |
|
|
29 |
|
|
| 30 |
|
|
30 |
|
|
| 31 |
|
|
31 |
|
|
| 32 |
|
|
32 |
|
|
| 33 |
|
|
33 |
|
|
| 34 |
|
|
34 |
|
|
| 35 |
|
|
35 |
|
|
| 36 |
|
|
36 |
|
|
| 37 |
|
|
37 |
|
|
| 38 |
|
|
38 |
|
|
| 39 |
|
|
39 |
|
|
| 40 |
|
|
40 |
|
|
| 41 |
|
|
41 |
|
|
| 42 |
|
|
42 |
|
|
| 43 |
|
|
43 |
|
|
| 44 |
|
|
44 |
|
|
| 45 |
|
|
45 |
|
|
| 46 |
|
|
46 |
|
|
| 47 |
|
|
47 |
|
|
| 48 |
|
Each async I/O operation has a corresponding epoll_op-derived struct that
|
48 |
|
Each async I/O operation has a corresponding epoll_op-derived struct that
|
| 49 |
|
holds the operation's state while it's in flight. The socket impl owns
|
49 |
|
holds the operation's state while it's in flight. The socket impl owns
|
| 50 |
|
fixed slots for each operation type (conn_, rd_, wr_), so only one
|
50 |
|
fixed slots for each operation type (conn_, rd_, wr_), so only one
|
| 51 |
|
operation of each type can be pending per socket at a time.
|
51 |
|
operation of each type can be pending per socket at a time.
|
| 52 |
|
|
52 |
|
|
| 53 |
|
|
53 |
|
|
| 54 |
|
|
54 |
|
|
| 55 |
|
File descriptors are registered with epoll once (via descriptor_state) and
|
55 |
|
File descriptors are registered with epoll once (via descriptor_state) and
|
| 56 |
|
stay registered until closed. The descriptor_state tracks which operations
|
56 |
|
stay registered until closed. The descriptor_state tracks which operations
|
| 57 |
|
are pending (read_op, write_op, connect_op). When an event arrives, the
|
57 |
|
are pending (read_op, write_op, connect_op). When an event arrives, the
|
| 58 |
|
reactor dispatches to the appropriate pending operation.
|
58 |
|
reactor dispatches to the appropriate pending operation.
|
| 59 |
|
|
59 |
|
|
| 60 |
|
|
60 |
|
|
| 61 |
|
|
61 |
|
|
| 62 |
|
When cancel() posts an op to the scheduler's ready queue, the socket impl
|
62 |
|
When cancel() posts an op to the scheduler's ready queue, the socket impl
|
| 63 |
|
might be destroyed before the scheduler processes the op. The `impl_ptr`
|
63 |
|
might be destroyed before the scheduler processes the op. The `impl_ptr`
|
| 64 |
|
member holds a shared_ptr to the impl, keeping it alive until the op
|
64 |
|
member holds a shared_ptr to the impl, keeping it alive until the op
|
| 65 |
|
completes. This is set by cancel() and cleared in operator() after the
|
65 |
|
completes. This is set by cancel() and cleared in operator() after the
|
| 66 |
|
|
66 |
|
|
| 67 |
|
|
67 |
|
|
| 68 |
|
|
68 |
|
|
| 69 |
|
|
69 |
|
|
| 70 |
|
For reads, 0 bytes with no error means EOF. But an empty user buffer also
|
70 |
|
For reads, 0 bytes with no error means EOF. But an empty user buffer also
|
| 71 |
|
returns 0 bytes. The `empty_buffer_read` flag distinguishes these cases.
|
71 |
|
returns 0 bytes. The `empty_buffer_read` flag distinguishes these cases.
|
| 72 |
|
|
72 |
|
|
| 73 |
|
|
73 |
|
|
| 74 |
|
|
74 |
|
|
| 75 |
|
Writes use sendmsg() with MSG_NOSIGNAL instead of writev() to prevent
|
75 |
|
Writes use sendmsg() with MSG_NOSIGNAL instead of writev() to prevent
|
| 76 |
|
SIGPIPE when the peer has closed.
|
76 |
|
SIGPIPE when the peer has closed.
|
| 77 |
|
|
77 |
|
|
| 78 |
|
|
78 |
|
|
| 79 |
|
namespace boost::corosio::detail {
|
79 |
|
namespace boost::corosio::detail {
|
| 80 |
|
|
80 |
|
|
| 81 |
|
|
81 |
|
|
| 82 |
|
|
82 |
|
|
| 83 |
|
|
83 |
|
|
| 84 |
|
|
84 |
|
|
| 85 |
|
|
85 |
|
|
| 86 |
|
|
86 |
|
|
| 87 |
|
|
87 |
|
|
| 88 |
|
|
88 |
|
|
| 89 |
|
/** Per-descriptor state for persistent epoll registration.
|
89 |
|
/** Per-descriptor state for persistent epoll registration.
|
| 90 |
|
|
90 |
|
|
| 91 |
|
Tracks pending operations for a file descriptor. The fd is registered
|
91 |
|
Tracks pending operations for a file descriptor. The fd is registered
|
| 92 |
|
once with epoll and stays registered until closed.
|
92 |
|
once with epoll and stays registered until closed.
|
| 93 |
|
|
93 |
|
|
| 94 |
|
This struct extends scheduler_op to support deferred I/O processing.
|
94 |
|
This struct extends scheduler_op to support deferred I/O processing.
|
| 95 |
|
When epoll events arrive, the reactor sets ready_events and queues
|
95 |
|
When epoll events arrive, the reactor sets ready_events and queues
|
| 96 |
|
this descriptor for processing. When popped from the scheduler queue,
|
96 |
|
this descriptor for processing. When popped from the scheduler queue,
|
| 97 |
|
operator() performs the actual I/O and queues completion handlers.
|
97 |
|
operator() performs the actual I/O and queues completion handlers.
|
| 98 |
|
|
98 |
|
|
| 99 |
|
|
99 |
|
|
| 100 |
|
The reactor no longer performs I/O directly. Instead:
|
100 |
|
The reactor no longer performs I/O directly. Instead:
|
| 101 |
|
1. Reactor sets ready_events and queues descriptor_state
|
101 |
|
1. Reactor sets ready_events and queues descriptor_state
|
| 102 |
|
2. Scheduler pops descriptor_state and calls operator()
|
102 |
|
2. Scheduler pops descriptor_state and calls operator()
|
| 103 |
|
3. operator() performs I/O under mutex and queues completions
|
103 |
|
3. operator() performs I/O under mutex and queues completions
|
| 104 |
|
|
104 |
|
|
| 105 |
|
This eliminates per-descriptor mutex locking from the reactor hot path.
|
105 |
|
This eliminates per-descriptor mutex locking from the reactor hot path.
|
| 106 |
|
|
106 |
|
|
| 107 |
|
|
107 |
|
|
| 108 |
|
The mutex protects operation pointers and ready flags during I/O.
|
108 |
|
The mutex protects operation pointers and ready flags during I/O.
|
| 109 |
|
ready_events_ and is_enqueued_ are atomic for lock-free reactor access.
|
109 |
|
ready_events_ and is_enqueued_ are atomic for lock-free reactor access.
|
| 110 |
|
|
110 |
|
|
| 111 |
|
struct descriptor_state final : scheduler_op
|
111 |
|
struct descriptor_state final : scheduler_op
|
| 112 |
|
|
112 |
|
|
| 113 |
|
|
113 |
|
|
| 114 |
|
|
114 |
|
|
| 115 |
|
|
115 |
|
|
| 116 |
|
epoll_op* read_op = nullptr;
|
116 |
|
epoll_op* read_op = nullptr;
|
| 117 |
|
epoll_op* write_op = nullptr;
|
117 |
|
epoll_op* write_op = nullptr;
|
| 118 |
|
epoll_op* connect_op = nullptr;
|
118 |
|
epoll_op* connect_op = nullptr;
|
| 119 |
|
|
119 |
|
|
| 120 |
|
// Caches edge events that arrived before an op was registered
|
120 |
|
// Caches edge events that arrived before an op was registered
|
| 121 |
|
|
121 |
|
|
| 122 |
|
bool write_ready = false;
|
122 |
|
bool write_ready = false;
|
| 123 |
|
|
123 |
|
|
| 124 |
|
// Deferred cancellation: set by cancel() when the target op is not
|
124 |
|
// Deferred cancellation: set by cancel() when the target op is not
|
| 125 |
|
// parked (e.g. completing inline via speculative I/O). Checked when
|
125 |
|
// parked (e.g. completing inline via speculative I/O). Checked when
|
| 126 |
|
// the next op parks; if set, the op is immediately self-cancelled.
|
126 |
|
// the next op parks; if set, the op is immediately self-cancelled.
|
| 127 |
|
// This matches IOCP semantics where CancelIoEx always succeeds.
|
127 |
|
// This matches IOCP semantics where CancelIoEx always succeeds.
|
| 128 |
|
bool read_cancel_pending = false;
|
128 |
|
bool read_cancel_pending = false;
|
| 129 |
|
bool write_cancel_pending = false;
|
129 |
|
bool write_cancel_pending = false;
|
| 130 |
|
bool connect_cancel_pending = false;
|
130 |
|
bool connect_cancel_pending = false;
|
| 131 |
|
|
131 |
|
|
| 132 |
|
// Set during registration only (no mutex needed)
|
132 |
|
// Set during registration only (no mutex needed)
|
| 133 |
|
std::uint32_t registered_events = 0;
|
133 |
|
std::uint32_t registered_events = 0;
|
| 134 |
|
|
134 |
|
|
| 135 |
|
|
135 |
|
|
| 136 |
|
// For deferred I/O - set by reactor, read by scheduler
|
136 |
|
// For deferred I/O - set by reactor, read by scheduler
|
| 137 |
|
std::atomic<std::uint32_t> ready_events_{0};
|
137 |
|
std::atomic<std::uint32_t> ready_events_{0};
|
| 138 |
|
std::atomic<bool> is_enqueued_{false};
|
138 |
|
std::atomic<bool> is_enqueued_{false};
|
| 139 |
|
epoll_scheduler const* scheduler_ = nullptr;
|
139 |
|
epoll_scheduler const* scheduler_ = nullptr;
|
| 140 |
|
|
140 |
|
|
| 141 |
|
// Prevents impl destruction while this descriptor_state is queued.
|
141 |
|
// Prevents impl destruction while this descriptor_state is queued.
|
| 142 |
|
// Set by close_socket() when is_enqueued_ is true, cleared by operator().
|
142 |
|
// Set by close_socket() when is_enqueued_ is true, cleared by operator().
|
| 143 |
|
std::shared_ptr<void> impl_ref_;
|
143 |
|
std::shared_ptr<void> impl_ref_;
|
| 144 |
|
|
144 |
|
|
| 145 |
|
/// Add ready events atomically.
|
145 |
|
/// Add ready events atomically.
|
| 146 |
|
void add_ready_events(std::uint32_t ev) noexcept
|
146 |
|
void add_ready_events(std::uint32_t ev) noexcept
|
| 147 |
|
|
147 |
|
|
| 148 |
|
ready_events_.fetch_or(ev, std::memory_order_relaxed);
|
148 |
|
ready_events_.fetch_or(ev, std::memory_order_relaxed);
|
| 149 |
|
|
149 |
|
|
| 150 |
|
|
150 |
|
|
| 151 |
|
/// Perform deferred I/O and queue completions.
|
151 |
|
/// Perform deferred I/O and queue completions.
|
| 152 |
|
void operator()() override;
|
152 |
|
void operator()() override;
|
| 153 |
|
|
153 |
|
|
| 154 |
|
/// Destroy without invoking.
|
154 |
|
/// Destroy without invoking.
|
| 155 |
|
/// Called during scheduler::shutdown() drain. Clear impl_ref_ to break
|
155 |
|
/// Called during scheduler::shutdown() drain. Clear impl_ref_ to break
|
| 156 |
|
/// the self-referential cycle set by close_socket().
|
156 |
|
/// the self-referential cycle set by close_socket().
|
| 157 |
|
|
157 |
|
|
| 158 |
|
|
158 |
|
|
| 159 |
|
|
159 |
|
|
| 160 |
|
|
160 |
|
|
| 161 |
|
|
161 |
|
|
| 162 |
|
|
162 |
|
|
| 163 |
|
struct epoll_op : scheduler_op
|
163 |
|
struct epoll_op : scheduler_op
|
| 164 |
|
|
164 |
|
|
| 165 |
|
|
165 |
|
|
| 166 |
|
|
166 |
|
|
| 167 |
|
|
167 |
|
|
| 168 |
|
void operator()() const noexcept;
|
168 |
|
void operator()() const noexcept;
|
| 169 |
|
|
169 |
|
|
| 170 |
|
|
170 |
|
|
| 171 |
|
std::coroutine_handle<> h;
|
171 |
|
std::coroutine_handle<> h;
|
| 172 |
|
|
172 |
|
|
| 173 |
|
std::error_code* ec_out = nullptr;
|
173 |
|
std::error_code* ec_out = nullptr;
|
| 174 |
|
std::size_t* bytes_out = nullptr;
|
174 |
|
std::size_t* bytes_out = nullptr;
|
| 175 |
|
|
175 |
|
|
| 176 |
|
|
176 |
|
|
| 177 |
|
|
177 |
|
|
| 178 |
|
std::size_t bytes_transferred = 0;
|
178 |
|
std::size_t bytes_transferred = 0;
|
| 179 |
|
|
179 |
|
|
| 180 |
|
std::atomic<bool> cancelled{false};
|
180 |
|
std::atomic<bool> cancelled{false};
|
| 181 |
|
std::optional<std::stop_callback<canceller>> stop_cb;
|
181 |
|
std::optional<std::stop_callback<canceller>> stop_cb;
|
| 182 |
|
|
182 |
|
|
| 183 |
|
// Prevents use-after-free when socket is closed with pending ops.
|
183 |
|
// Prevents use-after-free when socket is closed with pending ops.
|
| 184 |
|
// See "Impl Lifetime Management" in file header.
|
184 |
|
// See "Impl Lifetime Management" in file header.
|
| 185 |
|
std::shared_ptr<void> impl_ptr;
|
185 |
|
std::shared_ptr<void> impl_ptr;
|
| 186 |
|
|
186 |
|
|
| 187 |
|
// For stop_token cancellation - pointer to owning socket/acceptor impl.
|
187 |
|
// For stop_token cancellation - pointer to owning socket/acceptor impl.
|
| 188 |
|
// When stop is requested, we call back to the impl to perform actual I/O cancellation.
|
188 |
|
// When stop is requested, we call back to the impl to perform actual I/O cancellation.
|
| 189 |
|
epoll_socket* socket_impl_ = nullptr;
|
189 |
|
epoll_socket* socket_impl_ = nullptr;
|
| 190 |
|
epoll_acceptor* acceptor_impl_ = nullptr;
|
190 |
|
epoll_acceptor* acceptor_impl_ = nullptr;
|
| 191 |
|
|
191 |
|
|
| 192 |
|
|
192 |
|
|
| 193 |
|
|
193 |
|
|
| 194 |
|
|
194 |
|
|
| 195 |
|
|
195 |
|
|
| 196 |
|
|
196 |
|
|
| 197 |
|
|
197 |
|
|
| 198 |
|
|
198 |
|
|
| 199 |
|
cancelled.store(false, std::memory_order_relaxed);
|
199 |
|
cancelled.store(false, std::memory_order_relaxed);
|
| 200 |
|
|
200 |
|
|
| 201 |
|
|
201 |
|
|
| 202 |
|
acceptor_impl_ = nullptr;
|
202 |
|
acceptor_impl_ = nullptr;
|
| 203 |
|
|
203 |
|
|
| 204 |
|
|
204 |
|
|
| 205 |
|
// Defined in sockets.cpp where epoll_socket is complete
|
205 |
|
// Defined in sockets.cpp where epoll_socket is complete
|
| 206 |
|
void operator()() override;
|
206 |
|
void operator()() override;
|
| 207 |
|
|
207 |
|
|
| 208 |
|
virtual bool is_read_operation() const noexcept
|
208 |
|
virtual bool is_read_operation() const noexcept
|
| 209 |
|
|
209 |
|
|
| 210 |
|
|
210 |
|
|
| 211 |
|
|
211 |
|
|
| 212 |
|
virtual void cancel() noexcept = 0;
|
212 |
|
virtual void cancel() noexcept = 0;
|
| 213 |
|
|
213 |
|
|
| 214 |
|
|
214 |
|
|
| 215 |
|
|
215 |
|
|
| 216 |
|
|
216 |
|
|
| 217 |
|
|
217 |
|
|
| 218 |
|
|
218 |
|
|
| 219 |
|
|
219 |
|
|
| 220 |
|
void request_cancel() noexcept
|
220 |
|
void request_cancel() noexcept
|
| 221 |
|
|
221 |
|
|
| 222 |
|
cancelled.store(true, std::memory_order_release);
|
222 |
|
cancelled.store(true, std::memory_order_release);
|
| 223 |
|
|
223 |
|
|
| 224 |
|
|
224 |
|
|
| 225 |
|
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
225 |
|
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
| 226 |
|
void start(std::stop_token token, epoll_socket* impl)
|
226 |
|
void start(std::stop_token token, epoll_socket* impl)
|
| 227 |
|
|
227 |
|
|
| 228 |
|
cancelled.store(false, std::memory_order_release);
|
228 |
|
cancelled.store(false, std::memory_order_release);
|
| 229 |
|
|
229 |
|
|
| 230 |
|
|
230 |
|
|
| 231 |
|
acceptor_impl_ = nullptr;
|
231 |
|
acceptor_impl_ = nullptr;
|
| 232 |
|
|
232 |
|
|
| 233 |
|
if (token.stop_possible())
|
233 |
|
if (token.stop_possible())
|
| 234 |
|
stop_cb.emplace(token, canceller{this});
|
234 |
|
stop_cb.emplace(token, canceller{this});
|
| 235 |
|
|
235 |
|
|
| 236 |
|
|
236 |
|
|
| 237 |
|
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
237 |
|
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
| 238 |
|
void start(std::stop_token token, epoll_acceptor* impl)
|
238 |
|
void start(std::stop_token token, epoll_acceptor* impl)
|
| 239 |
|
|
239 |
|
|
| 240 |
|
cancelled.store(false, std::memory_order_release);
|
240 |
|
cancelled.store(false, std::memory_order_release);
|
| 241 |
|
|
241 |
|
|
| 242 |
|
|
242 |
|
|
| 243 |
|
|
243 |
|
|
| 244 |
|
|
244 |
|
|
| 245 |
|
if (token.stop_possible())
|
245 |
|
if (token.stop_possible())
|
| 246 |
|
stop_cb.emplace(token, canceller{this});
|
246 |
|
stop_cb.emplace(token, canceller{this});
|
| 247 |
|
|
247 |
|
|
| 248 |
|
|
248 |
|
|
| 249 |
|
void complete(int err, std::size_t bytes) noexcept
|
249 |
|
void complete(int err, std::size_t bytes) noexcept
|
| 250 |
|
|
250 |
|
|
| 251 |
|
|
251 |
|
|
| 252 |
|
bytes_transferred = bytes;
|
252 |
|
bytes_transferred = bytes;
|
| 253 |
|
|
253 |
|
|
| 254 |
|
|
254 |
|
|
| 255 |
|
virtual void perform_io() noexcept {}
|
255 |
|
virtual void perform_io() noexcept {}
|
| 256 |
|
|
256 |
|
|
| 257 |
|
|
257 |
|
|
| 258 |
|
struct epoll_connect_op final : epoll_op
|
258 |
|
struct epoll_connect_op final : epoll_op
|
| 259 |
|
|
259 |
|
|
| 260 |
|
endpoint target_endpoint;
|
260 |
|
endpoint target_endpoint;
|
| 261 |
|
|
261 |
|
|
| 262 |
|
|
262 |
|
|
| 263 |
|
|
263 |
|
|
| 264 |
|
|
264 |
|
|
| 265 |
|
target_endpoint = endpoint{};
|
265 |
|
target_endpoint = endpoint{};
|
| 266 |
|
|
266 |
|
|
| 267 |
|
|
267 |
|
|
| 268 |
|
void perform_io() noexcept override
|
268 |
|
void perform_io() noexcept override
|
| 269 |
|
|
269 |
|
|
| 270 |
|
// connect() completion status is retrieved via SO_ERROR, not return value
|
270 |
|
// connect() completion status is retrieved via SO_ERROR, not return value
|
| 271 |
|
|
271 |
|
|
| 272 |
|
socklen_t len = sizeof(err);
|
272 |
|
socklen_t len = sizeof(err);
|
| 273 |
|
if (::getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0)
|
273 |
|
if (::getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0)
|
| 274 |
|
|
274 |
|
|
| 275 |
|
|
275 |
|
|
| 276 |
|
|
276 |
|
|
| 277 |
|
|
277 |
|
|
| 278 |
|
// Defined in sockets.cpp where epoll_socket is complete
|
278 |
|
// Defined in sockets.cpp where epoll_socket is complete
|
| 279 |
|
void operator()() override;
|
279 |
|
void operator()() override;
|
| 280 |
|
void cancel() noexcept override;
|
280 |
|
void cancel() noexcept override;
|
| 281 |
|
|
281 |
|
|
| 282 |
|
|
282 |
|
|
| 283 |
|
struct epoll_read_op final : epoll_op
|
283 |
|
struct epoll_read_op final : epoll_op
|
| 284 |
|
|
284 |
|
|
| 285 |
|
static constexpr std::size_t max_buffers = 16;
|
285 |
|
static constexpr std::size_t max_buffers = 16;
|
| 286 |
|
iovec iovecs[max_buffers];
|
286 |
|
iovec iovecs[max_buffers];
|
| 287 |
|
|
287 |
|
|
| 288 |
|
bool empty_buffer_read = false;
|
288 |
|
bool empty_buffer_read = false;
|
| 289 |
|
|
289 |
|
|
| 290 |
|
bool is_read_operation() const noexcept override
|
290 |
|
bool is_read_operation() const noexcept override
|
| 291 |
|
|
291 |
|
|
| 292 |
|
return !empty_buffer_read;
|
292 |
|
return !empty_buffer_read;
|
| 293 |
|
|
293 |
|
|
| 294 |
|
|
294 |
|
|
| 295 |
|
|
295 |
|
|
| 296 |
|
|
296 |
|
|
| 297 |
|
|
297 |
|
|
| 298 |
|
|
298 |
|
|
| 299 |
|
empty_buffer_read = false;
|
299 |
|
empty_buffer_read = false;
|
| 300 |
|
|
300 |
|
|
| 301 |
|
|
301 |
|
|
| 302 |
|
void perform_io() noexcept override
|
302 |
|
void perform_io() noexcept override
|
| 303 |
|
|
303 |
|
|
| 304 |
|
|
304 |
|
|
| 305 |
|
|
305 |
|
|
| 306 |
|
|
306 |
|
|
| 307 |
|
n = ::readv(fd, iovecs, iovec_count);
|
307 |
|
n = ::readv(fd, iovecs, iovec_count);
|
| 308 |
|
|
308 |
|
|
| 309 |
|
while (n < 0 && errno == EINTR);
|
309 |
|
while (n < 0 && errno == EINTR);
|
| 310 |
|
|
310 |
|
|
| 311 |
|
|
311 |
|
|
| 312 |
|
complete(0, static_cast<std::size_t>(n));
|
312 |
|
complete(0, static_cast<std::size_t>(n));
|
| 313 |
|
|
313 |
|
|
| 314 |
|
|
314 |
|
|
| 315 |
|
|
315 |
|
|
| 316 |
|
|
316 |
|
|
| 317 |
|
void cancel() noexcept override;
|
317 |
|
void cancel() noexcept override;
|
| 318 |
|
|
318 |
|
|
| 319 |
|
|
319 |
|
|
| 320 |
|
struct epoll_write_op final : epoll_op
|
320 |
|
struct epoll_write_op final : epoll_op
|
| 321 |
|
|
321 |
|
|
| 322 |
|
static constexpr std::size_t max_buffers = 16;
|
322 |
|
static constexpr std::size_t max_buffers = 16;
|
| 323 |
|
iovec iovecs[max_buffers];
|
323 |
|
iovec iovecs[max_buffers];
|
| 324 |
|
|
324 |
|
|
| 325 |
|
|
325 |
|
|
| 326 |
|
|
326 |
|
|
| 327 |
|
|
327 |
|
|
| 328 |
|
|
328 |
|
|
| 329 |
|
|
329 |
|
|
| 330 |
|
|
330 |
|
|
| 331 |
|
|
331 |
|
|
| 332 |
|
void perform_io() noexcept override
|
332 |
|
void perform_io() noexcept override
|
| 333 |
|
|
333 |
|
|
| 334 |
|
|
334 |
|
|
| 335 |
|
|
335 |
|
|
| 336 |
|
msg.msg_iovlen = static_cast<std::size_t>(iovec_count);
|
336 |
|
msg.msg_iovlen = static_cast<std::size_t>(iovec_count);
|
| 337 |
|
|
337 |
|
|
| 338 |
|
|
338 |
|
|
| 339 |
|
|
339 |
|
|
| 340 |
|
|
340 |
|
|
| 341 |
|
n = ::sendmsg(fd, &msg, MSG_NOSIGNAL);
|
341 |
|
n = ::sendmsg(fd, &msg, MSG_NOSIGNAL);
|
| 342 |
|
|
342 |
|
|
| 343 |
|
while (n < 0 && errno == EINTR);
|
343 |
|
while (n < 0 && errno == EINTR);
|
| 344 |
|
|
344 |
|
|
| 345 |
|
|
345 |
|
|
| 346 |
|
complete(0, static_cast<std::size_t>(n));
|
346 |
|
complete(0, static_cast<std::size_t>(n));
|
| 347 |
|
|
347 |
|
|
| 348 |
|
|
348 |
|
|
| 349 |
|
|
349 |
|
|
| 350 |
|
|
350 |
|
|
| 351 |
|
void cancel() noexcept override;
|
351 |
|
void cancel() noexcept override;
|
| 352 |
|
|
352 |
|
|
| 353 |
|
|
353 |
|
|
| 354 |
|
struct epoll_accept_op final : epoll_op
|
354 |
|
struct epoll_accept_op final : epoll_op
|
| 355 |
|
|
355 |
|
|
| 356 |
|
|
356 |
|
|
| 357 |
|
io_object::implementation** impl_out = nullptr;
|
357 |
|
io_object::implementation** impl_out = nullptr;
|
| 358 |
|
|
358 |
|
|
| 359 |
|
|
359 |
|
|
| 360 |
|
|
360 |
|
|
| 361 |
|
|
361 |
|
|
| 362 |
|
|
362 |
|
|
| 363 |
|
|
363 |
|
|
| 364 |
|
|
364 |
|
|
| 365 |
|
|
365 |
|
|
| 366 |
|
|
366 |
|
|
| 367 |
|
|
367 |
|
|
| 368 |
|
void perform_io() noexcept override
|
368 |
|
void perform_io() noexcept override
|
| 369 |
|
|
369 |
|
|
| 370 |
|
socklen_t addrlen = sizeof(peer_addr);
|
370 |
|
socklen_t addrlen = sizeof(peer_addr);
|
| 371 |
|
|
371 |
|
|
| 372 |
|
|
372 |
|
|
| 373 |
|
|
373 |
|
|
| 374 |
|
|
374 |
|
|
| 375 |
|
fd, reinterpret_cast<sockaddr*>(&peer_addr), &addrlen,
|
375 |
|
fd, reinterpret_cast<sockaddr*>(&peer_addr), &addrlen,
|
| 376 |
|
SOCK_NONBLOCK | SOCK_CLOEXEC);
|
376 |
|
SOCK_NONBLOCK | SOCK_CLOEXEC);
|
| 377 |
|
|
377 |
|
|
| 378 |
|
while (new_fd < 0 && errno == EINTR);
|
378 |
|
while (new_fd < 0 && errno == EINTR);
|
| 379 |
|
|
379 |
|
|
| 380 |
|
|
380 |
|
|
| 381 |
|
|
381 |
|
|
| 382 |
|
|
382 |
|
|
| 383 |
|
|
383 |
|
|
| 384 |
|
|
384 |
|
|
| 385 |
|
|
385 |
|
|
| 386 |
|
|
386 |
|
|
| 387 |
|
|
387 |
|
|
| 388 |
|
|
388 |
|
|
| 389 |
|
|
389 |
|
|
| 390 |
|
|
390 |
|
|
| 391 |
|
// Defined in acceptors.cpp where epoll_acceptor is complete
|
391 |
|
// Defined in acceptors.cpp where epoll_acceptor is complete
|
| 392 |
|
void operator()() override;
|
392 |
|
void operator()() override;
|
| 393 |
|
void cancel() noexcept override;
|
393 |
|
void cancel() noexcept override;
|
| 394 |
|
|
394 |
|
|
| 395 |
|
|
395 |
|
|
| 396 |
|
} // namespace boost::corosio::detail
|
396 |
|
} // namespace boost::corosio::detail
|
| 397 |
|
|
397 |
|
|
| 398 |
|
#endif // BOOST_COROSIO_HAS_EPOLL
|
398 |
|
#endif // BOOST_COROSIO_HAS_EPOLL
|
| 399 |
|
|
399 |
|
|
| 400 |
|
#endif // BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_OP_HPP
|
400 |
|
#endif // BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_OP_HPP
|