Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions adafruit_esp32spi/adafruit_esp32spi_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,36 @@ def recv(self, bufsize=0):
gc.collect()
return ret

def recv_into(self, buffer):
"""Read some bytes from the connected remote address into a given buffer

:param bytearray buffer: The buffer to read into
"""

stamp = time.monotonic()
to_read = len(buffer)
received = []
while to_read > 0:
# print("Bytes to read:", to_read)
avail = self.available()
if avail:
stamp = time.monotonic()
recv = _the_interface.socket_read(self._socknum, min(to_read, avail))
# received.append(recv)
start = len(buffer) - to_read
to_read -= len(recv)
end = len(buffer) - to_read
buffer[start:end] = bytearray(recv)
gc.collect()
elif received:
# We've received some bytes but no more are available. So return
# what we have.
break
if self._timeout > 0 and time.monotonic() - stamp > self._timeout:
break
gc.collect()
return len(buffer) - to_read

def read(self, size=0):
"""Read up to 'size' bytes from the socket, this may be buffered internally!
If 'size' isnt specified, return everything in the buffer.
Expand Down