Skip to content

Commit 15c5c82

Browse files
committed
feat: Integrate timers with epoll loop, implement posix signals
Windows build fixes: - Add BOOST_COROSIO_DECL to tcp_server nested classes (worker_base, workers, launcher) for proper DLL export - Delete copy operations on workers class to prevent MSVC from instantiating copy constructor for vector<unique_ptr<>> - Suppress C4251 warnings for private members with #pragma - Convert push_aw/pop_aw::await_suspend to templates matching IoAwaitable concept POSIX signal_set implementation: - Add posix_signals service using C signal() handlers - Implement global signal state for cross-service coordination - Support signal registration, async wait, cancellation, and queuing Timer service fixes: - Integrate timer_service with posix_scheduler epoll loop - Add calculate_timeout() to wake epoll for timer deadlines - Fix work tracking: use post() instead of dispatch() to prevent premature io_context::run() exit Lambda coroutine lifetime fixes: - Fix stack-use-after-scope bugs in mocket source and tests - Fix 19 lambda coroutines in timer.cpp tests - Fix 15 lambda coroutines in signal_set.cpp tests - Change [&] captures to explicit parameter passing Build system: - Add mocket, signal_set, timer tests to Jamfile
1 parent 05ae342 commit 15c5c82

File tree

14 files changed

+1149
-400
lines changed

14 files changed

+1149
-400
lines changed

include/boost/corosio/tcp_server.hpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
namespace boost {
3131
namespace corosio {
3232

33+
#ifdef _MSC_VER
34+
#pragma warning(push)
35+
#pragma warning(disable: 4251) // class needs to have dll-interface
36+
#endif
37+
3338
class BOOST_COROSIO_DECL
3439
tcp_server
3540
{
@@ -126,7 +131,15 @@ class BOOST_COROSIO_DECL
126131
public:
127132
push_aw(tcp_server& self, worker_base& w) noexcept;
128133
bool await_ready() const noexcept;
129-
std::coroutine_handle<> await_suspend(std::coroutine_handle<> h) noexcept;
134+
135+
template<typename Ex>
136+
std::coroutine_handle<>
137+
await_suspend(std::coroutine_handle<> h, Ex const&, std::stop_token) noexcept
138+
{
139+
// Dispatch to server's executor before touching shared state
140+
return self_.dispatch_.dispatch(h);
141+
}
142+
130143
void await_resume() noexcept;
131144
};
132145

@@ -142,7 +155,18 @@ class BOOST_COROSIO_DECL
142155
public:
143156
pop_aw(tcp_server& self) noexcept;
144157
bool await_ready() const noexcept;
145-
bool await_suspend(std::coroutine_handle<> h) noexcept;
158+
159+
template<typename Ex>
160+
bool
161+
await_suspend(std::coroutine_handle<> h, Ex const&, std::stop_token) noexcept
162+
{
163+
wait_.h = h;
164+
wait_.w = nullptr;
165+
wait_.next = self_.waiters_;
166+
self_.waiters_ = &wait_;
167+
return true;
168+
}
169+
146170
system::result<worker_base&> await_resume() noexcept;
147171
};
148172

@@ -151,7 +175,7 @@ class BOOST_COROSIO_DECL
151175
capy::task<void> do_accept(acceptor& acc);
152176

153177
protected:
154-
class worker_base
178+
class BOOST_COROSIO_DECL worker_base
155179
{
156180
worker_base* next = nullptr;
157181

@@ -171,13 +195,21 @@ class BOOST_COROSIO_DECL
171195
}
172196
};
173197

174-
class workers
198+
class BOOST_COROSIO_DECL workers
175199
{
176200
friend class tcp_server;
177201

178202
std::vector<std::unique_ptr<worker_base>> v_;
179203
worker_base* idle_ = nullptr;
180204

205+
public:
206+
workers() = default;
207+
workers(workers const&) = delete;
208+
workers& operator=(workers const&) = delete;
209+
workers(workers&&) = default;
210+
workers& operator=(workers&&) = default;
211+
212+
private:
181213
void push(worker_base& w) noexcept
182214
{
183215
w.next = idle_;
@@ -208,7 +240,7 @@ class BOOST_COROSIO_DECL
208240

209241
workers wv_;
210242

211-
class launcher
243+
class BOOST_COROSIO_DECL launcher
212244
{
213245
tcp_server* srv_;
214246
worker_base* w_;
@@ -283,6 +315,10 @@ class BOOST_COROSIO_DECL
283315
void start();
284316
};
285317

318+
#ifdef _MSC_VER
319+
#pragma warning(pop)
320+
#endif
321+
286322
} // corosio
287323
} // boost
288324

src/corosio/src/detail/posix_op.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ struct posix_op : scheduler_op
5656
system::error_code* ec_out = nullptr;
5757
std::size_t* bytes_out = nullptr;
5858

59-
int fd = -1; // Socket file descriptor
60-
std::uint32_t events = 0; // Requested epoll events (EPOLLIN/EPOLLOUT)
61-
int error = 0; // errno on completion
59+
int fd = -1;
60+
std::uint32_t events = 0;
61+
int error = 0;
6262
std::size_t bytes_transferred = 0;
6363

6464
std::atomic<bool> cancelled{false};
@@ -101,7 +101,6 @@ struct posix_op : scheduler_op
101101
d.dispatch(h).resume();
102102
}
103103

104-
// Returns true if this is a read operation (for EOF detection)
105104
virtual bool is_read_operation() const noexcept { return false; }
106105

107106
void destroy() override
@@ -219,7 +218,6 @@ struct posix_accept_op : posix_op
219218
io_object::io_object_impl* peer_impl = nullptr;
220219
io_object::io_object_impl** impl_out = nullptr;
221220

222-
// Function to create peer impl - set by posix_sockets
223221
using create_peer_fn = io_object::io_object_impl* (*)(void*, int);
224222
create_peer_fn create_peer = nullptr;
225223
void* service_ptr = nullptr;
@@ -269,14 +267,12 @@ struct posix_accept_op : posix_op
269267

270268
if (success && accepted_fd >= 0 && peer_impl)
271269
{
272-
// Pass impl to awaitable for assignment to peer socket
273270
if (impl_out)
274271
*impl_out = peer_impl;
275272
peer_impl = nullptr;
276273
}
277274
else
278275
{
279-
// Cleanup on failure
280276
if (accepted_fd >= 0)
281277
{
282278
::close(accepted_fd);

0 commit comments

Comments
 (0)