Callingcloseandshutdownhave two different effects on the underlying socket.

The first thing to point out is that the socket is a resource in the underlying OS andmultiple processes can have a handle for the same underlying socket.

When you callcloseit decrements the handle count by one and if the handle count has reached zero then the socket and associated connection goes through the normal close procedure (effectively sending a FIN / EOF to the peer) and the socket is deallocated.

The thing to pay attention to here is that if the handle count does not reach zero because another process still has a handle to the socket then the connectionis not closed and the socket is not deallocated.

On the other hand callingshutdownfor reading and writing closes the underlying connection and sends a FIN / EOF to the peer regardless of how many processes have handles to the socket. However, itdoes notdeallocate the socket and you still need to call close afterward.


icheeringsoul
48 声望6 粉丝

« 上一篇
tcp rst包

引用和评论

0 条评论