summaryrefslogtreecommitdiff
path: root/websockify/websocketproxy.py
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2022-10-10 10:13:01 +0200
committerPierre Ossman <ossman@cendio.se>2022-10-10 10:13:01 +0200
commite9c80aa32a49c2ac83984f6f509c50d6c400c527 (patch)
tree092fbd8c42be7fed6f1952bc8cf2c1684de69af6 /websockify/websocketproxy.py
parent7133f85df6a2a18c6c686f6fe18237be42961ef3 (diff)
parentcaef680ffffc5eb9d07c671a5e9d836c3e585dd9 (diff)
downloadwebsockify-e9c80aa32a49c2ac83984f6f509c50d6c400c527.tar.gz
Merge branch 'master' of https://github.com/msnatepg/websockify
Diffstat (limited to 'websockify/websocketproxy.py')
-rw-r--r--websockify/websocketproxy.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/websockify/websocketproxy.py b/websockify/websocketproxy.py
index 7805fea..087e47c 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)