Skip to content

Commit e9c80aa

Browse files
committed
Merge branch 'master' of https://github.com/msnatepg/websockify
2 parents 7133f85 + caef680 commit e9c80aa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

websockify/websocketproxy.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ def do_proxy(self, target):
222222
tqueue.extend(bufs)
223223

224224
if closed:
225+
226+
while (len(tqueue) != 0):
227+
# Send queued client data to the target
228+
dat = tqueue.pop(0)
229+
sent = target.send(dat)
230+
if sent == len(dat):
231+
self.print_traffic(">")
232+
else:
233+
# requeue the remaining data
234+
tqueue.insert(0, dat[sent:])
235+
self.print_traffic(".>")
236+
225237
# TODO: What about blocking on client socket?
226238
if self.verbose:
227239
self.log_message("%s:%s: Client closed connection",
@@ -245,6 +257,16 @@ def do_proxy(self, target):
245257
# Receive target data, encode it and queue for client
246258
buf = target.recv(self.buffer_size)
247259
if len(buf) == 0:
260+
261+
# Target socket closed, flushing queues and closing client-side websocket
262+
# Send queued target data to the client
263+
if len(cqueue) != 0:
264+
c_pend = True
265+
while(c_pend):
266+
c_pend = self.send_frames(cqueue)
267+
268+
cqueue = []
269+
248270
if self.verbose:
249271
self.log_message("%s:%s: Target closed connection",
250272
self.server.target_host, self.server.target_port)

0 commit comments

Comments
 (0)