File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,36 @@ def recv(self, bufsize=0):
159
159
gc .collect ()
160
160
return ret
161
161
162
+ def recv_into (self , buffer ):
163
+ """Read some bytes from the connected remote address into a given buffer
164
+
165
+ :param bytearray buffer: The buffer to read into
166
+ """
167
+
168
+ stamp = time .monotonic ()
169
+ to_read = len (buffer )
170
+ received = []
171
+ while to_read > 0 :
172
+ # print("Bytes to read:", to_read)
173
+ avail = self .available ()
174
+ if avail :
175
+ stamp = time .monotonic ()
176
+ recv = _the_interface .socket_read (self ._socknum , min (to_read , avail ))
177
+ # received.append(recv)
178
+ start = len (buffer ) - to_read
179
+ to_read -= len (recv )
180
+ end = len (buffer ) - to_read
181
+ buffer [start :end ] = bytearray (recv )
182
+ gc .collect ()
183
+ elif received :
184
+ # We've received some bytes but no more are available. So return
185
+ # what we have.
186
+ break
187
+ if self ._timeout > 0 and time .monotonic () - stamp > self ._timeout :
188
+ break
189
+ gc .collect ()
190
+ return len (buffer ) - to_read
191
+
162
192
def read (self , size = 0 ):
163
193
"""Read up to 'size' bytes from the socket, this may be buffered internally!
164
194
If 'size' isnt specified, return everything in the buffer.
You can’t perform that action at this time.
0 commit comments