File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -161,20 +161,24 @@ def recv(self, bufsize=0):
161
161
gc .collect ()
162
162
return ret
163
163
164
- def recv_into (self , buffer , nbytes = None ):
164
+ def recv_into (self , buffer , nbytes = 0 ):
165
165
"""Read some bytes from the connected remote address into a given buffer
166
166
167
167
:param bytearray buffer: The buffer to read into
168
- :param int nbytes: (Optional) Number of bytes to receive
169
- default is as many as possible before filling the
168
+ :param int nbytes: (Optional) Number of bytes to receive default is 0,
169
+ which will receive as many bytes as possible before filling the
170
170
buffer or timing out
171
171
"""
172
172
173
+ if not (0 <= nbytes <= len (buffer )):
174
+ raise ValueError (
175
+ "Can only read number of bytes between 0 and length of supplied buffer"
176
+ )
177
+
173
178
stamp = time .monotonic ()
174
179
to_read = len (buffer )
175
- limit = 0 if nbytes is None else to_read - nbytes
176
180
received = []
177
- while to_read > limit :
181
+ while to_read > nbytes :
178
182
# print("Bytes to read:", to_read)
179
183
avail = self .available ()
180
184
if avail :
You can’t perform that action at this time.
0 commit comments