问题描述
在 C 中,我明白如果我们关闭一个套接字,这意味着该套接字将被销毁并且可以在以后重新使用.
In C, I understood that if we close a socket, it means the socket will be destroyed and can be re-used later.
关机怎么样?描述说它关闭了与该套接字的双工连接的一半.但是这个套接字会像 close
系统调用一样被销毁吗?
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
是实际销毁套接字的方法.
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.
使用 shutdown
,您仍然可以接收对等方已经发送的待处理数据(感谢 Joey Adams 注意到这一点).
With shutdown
, you will still be able to receive pending data the peer already sent (thanks to Joey Adams for noting this).
这篇关于关闭与关闭套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!