3 Commits

View File

@@ -7,6 +7,8 @@ import socket
import threading import threading
import time import time
from typing import Any
from judas_protocol import Category, ControlAction, Message from judas_protocol import Category, ControlAction, Message
from judas_server.backend.client import Client from judas_server.backend.client import Client
@@ -103,14 +105,11 @@ class BackendServer:
client.disconnect() client.disconnect()
def _send_outbound( def _send_outbound(self, sock: socket.socket, client: Client) -> None:
self, sock: socket.socket, client: Client, data: bytes
) -> None:
"""Queue data to be sent to a client. """Queue data to be sent to a client.
Args: Args:
client (Client): The client to send data to. client (Client): The client to send data to.
data (bytes): The data to send.
""" """
self.logger.debug(f"[>] Sending data to {client}: {client.outbound!r}") self.logger.debug(f"[>] Sending data to {client}: {client.outbound!r}")
sent = sock.send(client.outbound) sent = sock.send(client.outbound)
@@ -219,7 +218,7 @@ class BackendServer:
if mask & selectors.EVENT_WRITE: if mask & selectors.EVENT_WRITE:
if client.outbound: if client.outbound:
self._send_outbound(sock, client, client.outbound) self._send_outbound(sock, client)
except ConnectionResetError as e: except ConnectionResetError as e:
self.logger.error(f"Connection reset by {client}, disconnect: {e}") self.logger.error(f"Connection reset by {client}, disconnect: {e}")
@@ -243,7 +242,7 @@ class BackendServer:
events = self.selector.select(timeout=1) events = self.selector.select(timeout=1)
for key, mask in events: for key, mask in events:
if key.data is None: if key.data is None:
self._accept_connection(key.fileobj) self._accept_connection(key.fileobj) # type: ignore
else: else:
self._handle_connection(key, mask) self._handle_connection(key, mask)
time.sleep(0.001) # prevent 100% CPU usage time.sleep(0.001) # prevent 100% CPU usage