Skip to content

Commit

Permalink
#3376 simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Nov 10, 2022
1 parent 7a02bc2 commit 30b9438
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions xpra/net/quic/websocket_request_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Copyright (c) 2018-2019 Jeremy Lainé.
#Copyright (C) 2022 Antoine Martin <[email protected]>
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -48,16 +49,18 @@
HttpConnection = Union[H0Connection, H3Connection]


class WebSocketHandler:
class WebSocketConnection(Connection):
def __init__(self, connection: HttpConnection, scope: Dict,
stream_id: int, transmit: Callable[[], None]) -> None:
self.closed = False
self.connection = connection
Connection.__init__(self, ("quic", 0), "wss")
self.socktype_wrapped = "quic"
self.connection: HttpConnection = connection
self.data_queue: Queue[bytes] = Queue()
self.scope = scope
self.stream_id = stream_id
self.transmit = transmit
self.scope: Dict = scope
self.stream_id: int = stream_id
self.transmit: Callable[[], None] = transmit
self.accepted : bool = False
self.closed : bool = False

def __repr__(self):
return f"WebSocketHandler<{self.stream_id}>"
Expand All @@ -76,15 +79,15 @@ def http_event_received(self, event: H3Event) -> None:
return
log.info("websocket request at %s", self.scope.get("path", "/"))
self.send_accept()
else:
log.warn(f"Warning: unhandled websocket http event {event}")


def close(self):
log("WebSocketConnection.close()")
if not self.closed:
self.send_close(1000)

def receive(self) -> Dict:
log("ws:receive()")
return self.data_queue.get()
Connection.close(self)


def send_accept(self):
Expand Down Expand Up @@ -118,25 +121,9 @@ def send_bytes(self, bdata : bytes):
self.transmit()


class WebSocketConnection(Connection, WebSocketHandler):

def __init__(self, connection: HttpConnection, scope: Dict,
stream_id: int, transmit: Callable[[], None]) -> None:
#def __init__(self, endpoint, socktype, info=None, options=None):
Connection.__init__(self, ("udp", 0), "wss")
self.socktype_wrapped = "quic"
WebSocketHandler.__init__(self, connection, scope, stream_id, transmit)


def close(self):
log("WebSocketConnection.close()")
WebSocketHandler.close(self)
Connection.close(self)

def write(self, buf):
self.send_bytes(buf)
return len(buf)

def read(self, n):
log(f"read({n})")
return self.receive()
return self.data_queue.get()

0 comments on commit 30b9438

Please sign in to comment.