A handle to a datagram-oriented transport socket.
Socket is the base interface for reading and writing datagrams over some underlying transport. All reads and writes operate using Buf objects, which represent views into some memory region specific to the socket. This makes zero-copy reads and writes possible, if the implementation chooses to support it.
A future byte-oriented socket will be ByteSocket (which is reliable).
Unlike ReliableSocket, a Socket does not guarantee reliable or in-order delivery; datagrams may be dropped, duplicated, or reordered depending on the underlying transport. However, any ReliableSocket can be implicitly converted to and used as a Socket.
The underlying socket begins open, but may close at any time. Once closed, all operations on the socket will report failures. A Socket cannot be reopened. A new one must be provisioned from a Listener or a Connector.
A Socket is cheaply copyable and always safe to access, ensuring that the underlying socket state is valid as long as a handle is held. Users should drop their handles once no longer needed to ensure prompt resource reclamation.
Public Member Functions | |
| constexpr | Socket (std::nullptr_t) |
| Socket (const Socket &other)=default | |
| Socket (Socket &&other) noexcept=default | |
| Socket & | operator= (const Socket &other)=default |
| Socket & | operator= (Socket &&other) noexcept=default |
| Socket & | operator= (std::nullptr_t) noexcept |
| Socket (ReliableSocket &&other) noexcept | |
| Socket & | operator= (ReliableSocket &&other) noexcept |
| operator bool () const | |
| size_t | max_write_message_size_bytes () const |
The maximum size in bytes that can be requested in a ReserveWrite. | |
| size_t | max_read_message_size_bytes () const |
| The maximum size in bytes of a single datagram received from the peer. | |
| ReadFuture | Read () const |
| ReserveWriteFuture | ReserveWrite (size_t min_size_bytes) const |
| std::optional< WriteReservation > | TryReserveWrite (size_t min_size_bytes) const |
| CloseFuture | Close () const |
| CloseFuture | WhenClosed () const |
Friends | |
| class | SocketImpl |
| class | ReliableSocket |
| class | Listener |
| class | Connector |
| class | WriteReservation |
| bool | operator== (const Socket &lhs, const Socket &rhs) |
| bool | operator!= (const Socket &lhs, const Socket &rhs) |