Skip to content

Commit

Permalink
Fixed an infinite closing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jgelens committed Jan 10, 2014
1 parent 7a63fd7 commit 0d1f7d8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions geventwebsocket/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

MSG_SOCKET_DEAD = "Socket is dead"
MSG_ALREADY_CLOSED = "Connection is already closed"
MSG_CLOSED = "Connection closed"


class WebSocket(object):
Expand Down Expand Up @@ -306,9 +307,10 @@ def receive(self):
except ProtocolError:
self.close(1002)
except error:
self.current_app.on_close(MSG_SOCKET_DEAD)
self.close()
self.current_app.on_close(MSG_CLOSED)

return None
return None

def send_frame(self, message, opcode):
"""
Expand All @@ -328,7 +330,7 @@ def send_frame(self, message, opcode):
try:
self.raw_write(header + message)
except error:
raise WebSocketError("Socket is dead")
raise WebSocketError(MSG_SOCKET_DEAD)

def send(self, message, binary=None):
"""
Expand Down Expand Up @@ -375,7 +377,7 @@ def close(self, code=1000, message=''):

self.environ = None

self.current_app.on_close("Connection closed")
self.current_app.on_close(MSG_ALREADY_CLOSED)


class Stream(object):
Expand Down

0 comments on commit 0d1f7d8

Please sign in to comment.