@@ -12,6 +12,7 @@ ChangeLog
|
|||||||
- fix typo in README.rst (#197)
|
- fix typo in README.rst (#197)
|
||||||
- introduce on_data callback to pass data type. (#198)
|
- introduce on_data callback to pass data type. (#198)
|
||||||
- WebSocketBadStatusException for Handshake error (#199)
|
- WebSocketBadStatusException for Handshake error (#199)
|
||||||
|
- set close timeout (#192)
|
||||||
|
|
||||||
- 0.32.0
|
- 0.32.0
|
||||||
|
|
||||||
|
@@ -422,13 +422,16 @@ class WebSocket(object):
|
|||||||
self.connected = False
|
self.connected = False
|
||||||
self.send(struct.pack('!H', status) + reason, ABNF.OPCODE_CLOSE)
|
self.send(struct.pack('!H', status) + reason, ABNF.OPCODE_CLOSE)
|
||||||
|
|
||||||
def close(self, status=STATUS_NORMAL, reason=six.b("")):
|
def close(self, status=STATUS_NORMAL, reason=six.b(""), timeout=3):
|
||||||
"""
|
"""
|
||||||
Close Websocket object
|
Close Websocket object
|
||||||
|
|
||||||
status: status code to send. see STATUS_XXX.
|
status: status code to send. see STATUS_XXX.
|
||||||
|
|
||||||
reason: the reason to close. This must be string.
|
reason: the reason to close. This must be string.
|
||||||
|
|
||||||
|
timeout: timeout until recieve a close frame.
|
||||||
|
If None, it will wait forever until recieve a close frame.
|
||||||
"""
|
"""
|
||||||
if self.connected:
|
if self.connected:
|
||||||
if status < 0 or status >= ABNF.LENGTH_16:
|
if status < 0 or status >= ABNF.LENGTH_16:
|
||||||
@@ -437,8 +440,8 @@ class WebSocket(object):
|
|||||||
try:
|
try:
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.send(struct.pack('!H', status) + reason, ABNF.OPCODE_CLOSE)
|
self.send(struct.pack('!H', status) + reason, ABNF.OPCODE_CLOSE)
|
||||||
timeout = self.sock.gettimeout()
|
sock_timeout = self.sock.gettimeout()
|
||||||
self.sock.settimeout(3)
|
self.sock.settimeout(timeout)
|
||||||
try:
|
try:
|
||||||
frame = self.recv_frame()
|
frame = self.recv_frame()
|
||||||
if isEnabledForError():
|
if isEnabledForError():
|
||||||
@@ -447,7 +450,7 @@ class WebSocket(object):
|
|||||||
error("close status: " + repr(recv_status))
|
error("close status: " + repr(recv_status))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.sock.settimeout(timeout)
|
self.sock.settimeout(sock_timeout)
|
||||||
self.sock.shutdown(socket.SHUT_RDWR)
|
self.sock.shutdown(socket.SHUT_RDWR)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user