Skip to content

Commit ba7f418

Browse files
committed
Fix tcp_server::bind() to use non-throwing listen()
tcp_server::bind() could throw because tcp_acceptor::listen() had throwing overloads. This changes listen() to return [[nodiscard]] std::error_code, allowing bind() to properly propagate errors without throwing. API change for tcp_acceptor::listen(): Before: void listen(endpoint, int backlog = 128) // throws void listen(endpoint, std::error_code&) // out-param void listen(endpoint, int, std::error_code&) // out-param After: [[nodiscard]] std::error_code listen(endpoint, int backlog = 128) The [[nodiscard]] attribute ensures callers cannot accidentally ignore errors. This aligns with signal_set and socket options which already use non-throwing return values. Changes: - Fix tcp_server::bind() to capture and return listen() error code - Consolidate tcp_acceptor::listen() to single non-throwing overload - Document error conditions (address_in_use, address_not_available, permission_denied, operation_not_supported) and @throws Nothing - Update test utilities (socket_pair, mocket) with error checks - Update all unit tests (~20 call sites) to check return values - Update documentation (tcp_acceptor.adoc, tls.adoc, signals.adoc, endpoints.adoc) with new error-handling pattern
1 parent e56eb71 commit ba7f418

13 files changed

Lines changed: 602 additions & 507 deletions

File tree

‎doc/modules/ROOT/pages/guide/endpoints.adoc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ auto [ec] = co_await s.connect(target);
202202
[source,cpp]
203203
----
204204
corosio::tcp_acceptor acc(ioc);
205-
acc.listen(corosio::endpoint(8080)); // Bind to all interfaces
205+
if (auto ec = acc.listen(corosio::endpoint(8080))) // Bind to all interfaces
206+
return ec;
206207
----
207208

208209
== From Resolver Results

0 commit comments

Comments
 (0)