关闭关机套接字?(close vs shutdown socket?)

编程入门 行业动态 更新时间:2024-10-24 06:28:50
关闭关机套接字?(close vs shutdown socket?)

在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).

更多推荐

本文发布于:2023-08-03 08:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1385270.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:close   shutdown   socket

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!