def _closeSocket(self, orderly):
# The call to shutdown() before close() isn't really necessary, because
# we set FD_CLOEXEC now, which will ensure this is the only process
# holding the FD, thus ensuring close() really will shutdown the TCP
# socket. However, do it anyways, just to be safe.
skt = self.socket
try:
if orderly:
if self._shouldShutdown:
skt.shutdown(2)
else:
# Set SO_LINGER to 1,0 which, by convention, causes a
# connection reset to be sent when close is called,
# instead of the standard FIN shutdown sequence.
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack("ii", 1, 0))
except socket.error:
pass
try:
skt.close()
except socket.error:
pass
评论列表
文章目录