Skip to content

Commit d8f6bba

Browse files
author
Paul Sokolovsky
committed
webrepl_cli.py: Expect textual webrepl data anytime and skip it.
As WebREPL is multiplexed protocol, textual data may be interspersed with binary protocol records.
1 parent 612eea6 commit d8f6bba

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

webrepl_cli.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,21 @@ def write(self, data):
3737

3838
def read(self, sz):
3939
if not self.buf:
40-
hdr = self.s.recv(2)
41-
assert len(hdr) == 2
42-
fl, sz = struct.unpack(">BB", hdr)
43-
assert fl == 0x82
44-
if sz == 126:
40+
while True:
4541
hdr = self.s.recv(2)
4642
assert len(hdr) == 2
47-
(sz,) = struct.unpack(">H", hdr)
43+
fl, sz = struct.unpack(">BB", hdr)
44+
if sz == 126:
45+
hdr = self.s.recv(2)
46+
assert len(hdr) == 2
47+
(sz,) = struct.unpack(">H", hdr)
48+
if fl == 0x82:
49+
break
50+
print("Got unexpected websocket record of type %x, skipping it" % fl)
51+
while sz:
52+
skip = self.s.recv(sz)
53+
print("Skip data:", skip)
54+
sz -= len(skip)
4855
data = self.s.recv(sz)
4956
assert len(data) == sz
5057
self.buf = data

0 commit comments

Comments
 (0)