在C中,我了解到,如果我们关闭一个套接字,这意味着套接字将被破坏,可以在以后重新使用。
关机怎么样? 说明说它关闭了与该套接字的双工连接的一半。 但是这个套接字会像close系统调用一样被销毁吗?
In C, I understood that if we close a socket, it means the socket will be destroyed and can be re-used later.
How about shutdown? The description said it closes half of a duplex connection to that socket. But will that socket be destroyed like close system call?
最满意答案
这在Beej的网络指南中有所解释 。 shutdown是在一个或两个方向阻止通信的灵活方式。 当第二个参数是SHUT_RDWR ,它将阻止发送和接收(如close )。 但是, close是实际销毁套接字的方法。
shutdown ,您仍然可以收到对方已经发送的待处理数据(感谢Joey Adams注意到)。
This is explained in Beej's networking guide. shutdown is a flexible way to block communication in one or both directions. When the second parameter is SHUT_RDWR, it will block both sending and receiving (like close). However, close is the way to actually destroy a socket.
With shutdown, you will still be able to receive pending data the peer already sent (thanks to Joey Adams for noting this).
更多推荐
发布评论