boost::corosio::tcp_socket::shutdown
Disable sends or receives on the socket.
Synopsis
Declared in <boost/corosio/tcp_socket.hpp>
void
shutdown(shutdown_type what);
Description
TCP connections are full‐duplex: each direction (send and receive) operates independently. This function allows you to close one or both directions without destroying the socket.
-
shutdown_sendsends a TCP FIN packet to the peer, signaling that you have no more data to send. You can still receive data until the peer also closes their send direction. This is the most common use case, typically called before close() to ensure graceful connection termination. -
shutdown_receivedisables reading on the socket. This does NOT send anything to the peer ‐ they are not informed and may continue sending data. Subsequent reads will fail or return end‐of‐file. Incoming data may be discarded or buffered depending on the operating system. -
shutdown_bothcombines both effects: sends a FIN and disables reading.
When the peer shuts down their send direction (sends a FIN), subsequent read operations will complete with capy::cond::eof. Use the portable condition test rather than comparing error codes directly:
auto [ec, n] = co_await sock.read_some(buffer);
if (ec == capy::cond::eof)
{
// Peer closed their send direction
}
Any error from the underlying system call is silently discarded because it is unlikely to be helpful.
Parameters
| Name | Description |
|---|---|
what |
Determines what operations will no longer be allowed. |
Created with MrDocs