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
10 changes: 6 additions & 4 deletions adafruit_esp32spi/adafruit_esp32spi_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,21 @@ def write(self, data):
"""
self.send(data)

def readline(self):
"""Attempt to return as many bytes as we can up to but not including '\r\n'"""
def readline(self, eol=b"\r\n"):
"""Attempt to return as many bytes as we can up to but not including
end-of-line character (default is '\\r\\n')"""

# print("Socket readline")
stamp = time.monotonic()
while b"\r\n" not in self._buffer:
while eol not in self._buffer:
# there's no line already in there, read some more
avail = self.available()
if avail:
self._buffer += _the_interface.socket_read(self._socknum, avail)
elif self._timeout > 0 and time.monotonic() - stamp > self._timeout:
self.close() # Make sure to close socket so that we don't exhaust sockets.
raise RuntimeError("Didn't receive full response, failing out")
firstline, self._buffer = self._buffer.split(b"\r\n", 1)
firstline, self._buffer = self._buffer.split(eol, 1)
gc.collect()
return firstline

Expand Down