Current API
corosio::tcp_socket peer(ioc);
auto [ec] = co_await acc.accept(peer);
The caller must pre-construct a tcp_socket and pass it to accept().
Proposed addition
Add an overload that returns the peer socket directly:
auto [ec, peer] = co_await acc.accept();
The existing accept(tcp_socket&) overload is retained for callers that want to manage socket lifetime themselves (e.g., pre-allocated or recycled sockets).
Motivation
The current interface requires the caller to construct a socket before accepting. This has a design issue: the caller can pass a socket associated with a different io_context than the acceptor's, creating a failure mode that doesn't exist at the POSIX level (where accept() simply returns a new file descriptor).
The acceptor already knows its io_context, and the underlying accept(2) returns a new fd — it doesn't write into a pre-existing one. A returning overload:
- Eliminates a misuse vector — no way to pass a socket bound to the wrong
io_context
- Matches POSIX semantics —
accept(2) returns a new fd
- Simplifies common usage — one line instead of two
Retaining the existing overload gives callers who pre-allocate or recycle sockets a way to continue doing so.
Affected code
include/boost/corosio/tcp_acceptor.hpp — add returning overload and corresponding awaitable
- Backend implementations (epoll, select, kqueue, iocp) — may need a new virtual or the returning overload can be built on top of the existing one
Current API
The caller must pre-construct a
tcp_socketand pass it toaccept().Proposed addition
Add an overload that returns the peer socket directly:
The existing
accept(tcp_socket&)overload is retained for callers that want to manage socket lifetime themselves (e.g., pre-allocated or recycled sockets).Motivation
The current interface requires the caller to construct a socket before accepting. This has a design issue: the caller can pass a socket associated with a different
io_contextthan the acceptor's, creating a failure mode that doesn't exist at the POSIX level (whereaccept()simply returns a new file descriptor).The acceptor already knows its
io_context, and the underlyingaccept(2)returns a new fd — it doesn't write into a pre-existing one. A returning overload:io_contextaccept(2)returns a new fdRetaining the existing overload gives callers who pre-allocate or recycle sockets a way to continue doing so.
Affected code
include/boost/corosio/tcp_acceptor.hpp— add returning overload and corresponding awaitable