Skip to content

Commit

Permalink
Merge pull request #9 from brentru/fix-socket
Browse files Browse the repository at this point in the history
Fix TypeError on recv
  • Loading branch information
brentru authored Mar 12, 2020
2 parents e7306cd + c9a5d31 commit e41dccf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion adafruit_wiznet5k/adafruit_wiznet5k_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None, sockn

self._socknum = _the_interface.get_socket(SOCKETS)
SOCKETS.append(self._socknum)
self.settimeout(1)
self.settimeout(self._timeout)

@property
def socknum(self):
Expand Down Expand Up @@ -186,9 +186,11 @@ def recv(self, bufsize=0): #pylint: disable=too-many-branches
return ret
stamp = time.monotonic()


to_read = bufsize - len(self._buffer)
received = []
while to_read > 0:
# print("Bytes to read:", to_read)
if self._sock_type == SOCK_STREAM:
avail = self.available()
elif self._sock_type == SOCK_DGRAM:
Expand All @@ -199,6 +201,7 @@ def recv(self, bufsize=0): #pylint: disable=too-many-branches
recv = _the_interface.socket_read(self.socknum, min(to_read, avail))[1]
elif self._sock_type == SOCK_DGRAM:
recv = _the_interface.read_udp(self.socknum, min(to_read, avail))[1]
recv = bytes(recv)
received.append(recv)
to_read -= len(recv)
gc.collect()
Expand Down

0 comments on commit e41dccf

Please sign in to comment.