File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -35,14 +35,24 @@ def write(self, data):
35
35
self .s .send (hdr )
36
36
self .s .send (data )
37
37
38
+ def recvexactly (self , sz ):
39
+ res = b""
40
+ while sz :
41
+ data = self .s .recv (sz )
42
+ if not data :
43
+ break
44
+ res += data
45
+ sz -= len (data )
46
+ return res
47
+
38
48
def read (self , sz ):
39
49
if not self .buf :
40
50
while True :
41
- hdr = self .s . recv (2 )
51
+ hdr = self .recvexactly (2 )
42
52
assert len (hdr ) == 2
43
53
fl , sz = struct .unpack (">BB" , hdr )
44
54
if sz == 126 :
45
- hdr = self .s . recv (2 )
55
+ hdr = self .recvexactly (2 )
46
56
assert len (hdr ) == 2
47
57
(sz ,) = struct .unpack (">H" , hdr )
48
58
if fl == 0x82 :
@@ -52,7 +62,7 @@ def read(self, sz):
52
62
skip = self .s .recv (sz )
53
63
print ("Skip data:" , skip )
54
64
sz -= len (skip )
55
- data = self .s . recv (sz )
65
+ data = self .recvexactly (sz )
56
66
assert len (data ) == sz
57
67
self .buf = data
58
68
You can’t perform that action at this time.
0 commit comments