boost::corosio::tcp_socket::assign
Assign an existing native socket to this object.
Synopsis
Declared in <boost/corosio/tcp_socket.hpp>
[[nodiscard]]
std::error_code
assign(native_handle_type fd) noexcept;
Description
Adopts a TCP socket created outside the library — received from another process, inherited, or made natively — and registers it with the backend. The socket must be a stream socket in the AF_INET or AF_INET6 family. Adoption never alters the descriptor's flags or options: on POSIX the fd must already be non‐blocking, and on Windows the socket must be overlapped‐capable.
If this object is already open, pending operations complete with errc::operation_canceled and the held socket is closed before the new one is adopted.
Exception Safety
Strong guarantee on validation failure: the object is unchanged. If backend registration fails, the object either retains its previous socket or is left closed, depending on the backend. In all failure cases the caller retains ownership of fd.
Return Value
The error code, empty on success. Validation and registration failures are normal runtime conditions when adopting foreign descriptors.
|
The return value should not be discarded. |
Parameters
Name |
Description |
fd |
The native socket to adopt. On success the object owns it and will close it. |
Created with MrDocs