socket.shutdown 与 socket.close [英] socket.shutdown vs socket.close

查看:49
本文介绍了socket.shutdown 与 socket.close的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近看到了一些看起来像这样的代码(当然,sock 是一个套接字对象):

I recently saw a bit of code that looked like this (with sock being a socket object of course):

sock.shutdown(socket.SHUT_RDWR)
sock.close()

在套接字上调用shutdown然后关闭它的目的究竟是什么?如果有所不同,则此套接字用于非阻塞 IO.

What exactly is the purpose of calling shutdown on the socket and then closing it? If it makes a difference, this socket is being used for non-blocking IO.

推荐答案

这里有一个 说明:

一旦不再需要套接字,调用程序可以丢弃通过应用关闭子例程进行套接字到套接字描述符.如果一个可靠的传送套接字有数据当关闭时与之相关联地方,系统继续尝试数据传输.但是,如果数据是仍未送达,系统丢弃数据.是否应申请程序对任何待处理的都没有用数据,它可以使用关机之前套接字上的子程序关闭它.

Once a socket is no longer required, the calling program can discard the socket by applying a close subroutine to the socket descriptor. If a reliable delivery socket has data associated with it when a close takes place, the system continues to attempt data transfer. However, if the data is still undelivered, the system discards the data. Should the application program have no use for any pending data, it can use the shutdown subroutine on the socket prior to closing it.

这篇关于socket.shutdown 与 socket.close的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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