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

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

问题描述

我最近看到一个有点code的,看起来像这样(用袜子当然是一个套接字对象):

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

到底是什么调用套接字上关机,然后关闭它的目的是什么?如果有差别,被用于这个插座非阻塞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.

推荐答案

这里有一个<一个href=\"http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.progcomm/doc/progcomc/skt_shutdn.htm\">explanation:

在一个插座不再需要,
  调用程序可以放弃
  插座通过应用紧密子程序
  向套接字描述符。如果一个
  可靠的交付插座有数据
  用它当一个紧密相关的花费
  的地方,该系统继续尝试
  数据传输。然而,如果数据是
  仍然未交付,系统丢弃
  数据。如若申请
  程序有没有使用任何未决
  数据,它可以使用在关机
  子程序之前插槽上
  关闭它。

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 VS socket.close的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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