summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaximilian Sesterhenn <maximilian.sesterhenn@epg.com>2022-10-07 14:24:53 +0200
committerMaximilian Sesterhenn <maximilian.sesterhenn@epg.com>2022-10-07 14:24:53 +0200
commitcaef680ffffc5eb9d07c671a5e9d836c3e585dd9 (patch)
treef47ee1886a54358d40ba5f25d033fa245b2d46f2
parent33910d758d2c495dd1d380729c31bacbf8229ed0 (diff)
downloadwebsockify-caef680ffffc5eb9d07c671a5e9d836c3e585dd9.tar.gz
ensure that queues are empty when closing connections
-rw-r--r--websockify/websocketproxy.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/websockify/websocketproxy.py b/websockify/websocketproxy.py
index 7260d2e..98ded61 100644
--- a/websockify/websocketproxy.py
+++ b/websockify/websocketproxy.py
@@ -222,6 +222,18 @@ Traffic Legend:
tqueue.extend(bufs)
if closed:
+
+ while (len(tqueue) != 0):
+ # Send queued client data to the target
+ dat = tqueue.pop(0)
+ sent = target.send(dat)
+ if sent == len(dat):
+ self.print_traffic(">")
+ else:
+ # requeue the remaining data
+ tqueue.insert(0, dat[sent:])
+ self.print_traffic(".>")
+
# TODO: What about blocking on client socket?
if self.verbose:
self.log_message("%s:%s: Client closed connection",
@@ -245,6 +257,16 @@ Traffic Legend:
# Receive target data, encode it and queue for client
buf = target.recv(self.buffer_size)
if len(buf) == 0:
+
+ # Target socket closed, flushing queues and closing client-side websocket
+ # Send queued target data to the client
+ if len(cqueue) != 0:
+ c_pend = True
+ while(c_pend):
+ c_pend = self.send_frames(cqueue)
+
+ cqueue = []
+
if self.verbose:
self.log_message("%s:%s: Target closed connection",
self.server.target_host, self.server.target_port)