diff options
-rw-r--r-- | websocket/_app.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/websocket/_app.py b/websocket/_app.py index a05a2e3..81aa1fc 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -217,12 +217,16 @@ class WebSocketApp(object): if self.sock: raise WebSocketException("socket is already opened") thread = None - close_frame = None self.keep_running = True self.last_ping_tm = 0 self.last_pong_tm = 0 - def teardown(): + def teardown(close_frame=None): + """ + Tears down the connection. + If close_frame is set, we will invoke the on_close handler with the + statusCode and reason from there. + """ if thread and thread.isAlive(): event.set() thread.join() @@ -266,8 +270,7 @@ class WebSocketApp(object): op_code, frame = self.sock.recv_data_frame(True) if op_code == ABNF.OPCODE_CLOSE: - close_frame = frame - return teardown() + return teardown(frame) elif op_code == ABNF.OPCODE_PING: self._callback(self.on_ping, frame.data) elif op_code == ABNF.OPCODE_PONG: |