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.
The object must be closed. To replace a held socket, close() or release() it first.
Exception Safety
Throws nothing. On failure the object is unchanged and the caller retains ownership of fd.
Return Value
error::already_open if this object is open. Otherwise 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 closes it. |
Created with MrDocs