近VS关机插座? [英] close vs shutdown socket?

查看:114
本文介绍了近VS关机插座?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C,我的理解,如果我们关闭套接字,这意味着套接字将被破坏,以后可以重新使用。

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的网络指南。 关机是阻止在单向或双向通信的灵活方式。当第二个参数是 SHUT_RDWR ,它会阻止发送和接收(如关闭)。然而,关闭是实际摧毁一个插座的方式。

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

这篇关于近VS关机插座?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆