Skip to content

Add wait() on sockets for readiness without I/O #246

@sgerbino

Description

@sgerbino

corosio's socket types (tcp_socket, udp_socket, local_stream_socket, local_datagram_socket) only expose readiness through read_some / write_some, which require a non-empty buffer. There is no way to suspend until a socket is readable or writable without actually moving bytes.

This blocks a common integration pattern: wrapping a C library that owns the I/O (it does its own recv/send on the fd in O_NONBLOCK mode) and just needs a notification of readiness. Today the only workaround would be a 1-byte peek, which consumes data from the stream.

Proposal

Add an awaitable wait operation, e.g.:

enum class wait_type { read, write, error };

auto [ec] = co_await sock.wait(wait_type::read);

Equivalent to asio's socket_base::wait_read / wait_write / wait_error and async_wait. On the reactor backends this is a one-shot EPOLLIN / EPOLLOUT / EVFILT_READ etc. registration with no buffer; on IOCP it can be emulated via WSAEventSelect or a zero-byte WSARecv (a real Windows pattern for this use case).

Would unblock wrapping O_NONBLOCK C APIs (e.g. libssh, libpq async mode, custom protocol parsers) with corosio as the reactor.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions