Skip to content
Search

C:shutdown

lastmod 2018-11-13created 2018-11-132 edits

Syntax

#include <sys/socket.h>
int shutdown(int sock, int howto);

What is Half-close?

The problem with a one-sided close()
Host A and host B are communicating over TCP. If host A unilaterally ends the connection with close(), host B cannot send data to host A even if it has something to send. Since unilaterally cutting off both the send and receive streams is a problem, closing only one stream (usually closing the send side and leaving the receive side open) is called the Half-close technique.
Why Half-close is needed
The server simply has to send data continuously, but the client cannot know until when it should keep receiving data. If it calls read() periodically, it may end up in a blocking state (the called function does not return). So the server can send an EOF to signal that the data transfer is finished. However, sending EOF via close() makes it impossible to receive any data that might come afterward, so only the output stream is closed to send the EOF.

See also

Favorite site

author Zer0 sitemap