File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 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):
161161 gc .collect ()
162162 return ret
163163
164- def recv_into (self , buffer , nbytes = None ):
164+ def recv_into (self , buffer , nbytes = 0 ):
165165 """Read some bytes from the connected remote address into a given buffer
166166
167167 :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
170170 buffer or timing out
171171 """
172172
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+
173178 stamp = time .monotonic ()
174179 to_read = len (buffer )
175- limit = 0 if nbytes is None else to_read - nbytes
176180 received = []
177- while to_read > limit :
181+ while to_read > nbytes :
178182 # print("Bytes to read:", to_read)
179183 avail = self .available ()
180184 if avail :
You can’t perform that action at this time.
0 commit comments