Reputation: 213
Consider a TCP connection established between two TCP endpoints, where one of them calls either:
close()
:
Here, no further read or write is permitted.
shutdown(fd, SHUT_WR)
:
This converts the full duplex connection to simplex, where the endpoint invoking SHUT_WR
can still read.
However, in both the cases a FIN packet is sent on the wire to the peer endpoint. So the question is, how can the TCP endpoint which receives the FIN distinguish whether the other endpoint has used close()
or SHUT_WR
, since in the latter scenario it should still be able to send data?
Upvotes: 4
Views: 1018
Reputation: 50358
Basically, the answer is, it doesn't. Or, rather, the only general way to find out is to try to send some data and see if you get an ACK or an RST in response.
Of course, the application protocol might provide some mechanism for one side of the connection to indicate in advance that it no longer wants to receive any more data. But TCP itself doesn't provide any such mechanism.
Upvotes: 2