Skip to content

Commit

Permalink
Force disconnect from chat if websocket is not connected
Browse files Browse the repository at this point in the history
or can't write
  • Loading branch information
Gatsik committed Jun 6, 2024
1 parent 45b407c commit b82e3d3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/chat/socketadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def on_bin_message_received(self, message: bytes) -> None:
self.message_received.emit()

def read(self, size: int) -> bytes:
if self.socket.state() != QAbstractSocket.SocketState.ConnectedState:
raise OSError
ans, self.buffer = self.buffer[:size], self.buffer[size:]
return ans

Expand All @@ -49,7 +51,9 @@ def shutdown(self, how: int) -> None:
self.socket.deleteLater()

def write(self, message: bytes) -> None:
self.socket.sendBinaryMessage(message.strip())
sent = self.socket.sendBinaryMessage(message.strip())
if sent == 0:
raise OSError

def send(self, message: bytes) -> None:
""" Alias for write, just in case """
Expand Down

0 comments on commit b82e3d3

Please sign in to comment.