Suppose I have a TCP client and a TCP server. First, the client sends some data to the server, but the server is busy doing something else, so it does not read this connection. The data is kept in the TCP receive buffer on the server host. At this point, please help me clarify what will happen in the following different scenarios:
- Before the server call read, the client calls
closeon this connection. And theFINhas arrived in the server TCP, and the server TCP has sentACK. At this point, if the server callsreadon this socket, what will it return? Does it return the unread data in TCP receive buffer? Or does it just return 0 to indicateEOF, and the unread data is discarded? - Before the server calls
read, the client callsshutdownwithSHUT_WRon this connection. And theFINhas arrived in the server TCP, and the server TCP has sentACK. At this point, if the server callsreadon this socket, what will it return? Does it return the unread data in TCP receive buffer? Or does it just return 0 to indicateEOF, and the unread data is discarded? - Before the server calls
read, the client just exits without calling eithercloseorshutdown. And the TCP in client host will send theFIN, thisFINhas arrived in the server TCP, and the server TCP has sentACK. At this point, if the server callsreadon this socket, what will it return? Does it return the unread data in TCP receive buffer? Or does it just return 0 to indicateEOF, and the unread data is discarded?