Skip to content

Commit a5f1be2

Browse files
author
brentru
committed
fix socket bytearray issue
1 parent e7306cd commit a5f1be2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None, sockn
9797

9898
self._socknum = _the_interface.get_socket(SOCKETS)
9999
SOCKETS.append(self._socknum)
100-
self.settimeout(1)
100+
self.settimeout(self._timeout)
101101

102102
@property
103103
def socknum(self):
@@ -144,6 +144,7 @@ def connect(self, address, conntype=None):
144144
assert conntype != 0x03, "Error: SSL/TLS is not currently supported by CircuitPython."
145145
host, port = address
146146

147+
print(address)
147148
if hasattr(host, 'split'):
148149
host = tuple(map(int, host.split('.')))
149150
if not _the_interface.socket_connect(self.socknum, host, port, conn_mode=self._sock_type):
@@ -164,7 +165,7 @@ def recv(self, bufsize=0): #pylint: disable=too-many-branches
164165
"""Reads some bytes from the connected remote address.
165166
:param int bufsize: Maximum number of bytes to receive.
166167
"""
167-
# print("Socket read", bufsize)
168+
print("Socket read", bufsize)
168169
if bufsize == 0:
169170
# read everything on the socket
170171
while True:
@@ -186,24 +187,31 @@ def recv(self, bufsize=0): #pylint: disable=too-many-branches
186187
return ret
187188
stamp = time.monotonic()
188189

190+
189191
to_read = bufsize - len(self._buffer)
190192
received = []
191193
while to_read > 0:
194+
print("Bytes to read:", to_read)
192195
if self._sock_type == SOCK_STREAM:
193196
avail = self.available()
194197
elif self._sock_type == SOCK_DGRAM:
195198
avail = _the_interface.udp_remaining()
199+
#print('Bytes Avail: ', avail)
196200
if avail:
197201
stamp = time.monotonic()
198202
if self._sock_type == SOCK_STREAM:
203+
print("to_read: {}\navail:{}\n".format(to_read, avail))
199204
recv = _the_interface.socket_read(self.socknum, min(to_read, avail))[1]
200205
elif self._sock_type == SOCK_DGRAM:
201206
recv = _the_interface.read_udp(self.socknum, min(to_read, avail))[1]
207+
print('RCV: ', recv)
208+
recv = bytes(recv)
202209
received.append(recv)
203210
to_read -= len(recv)
204211
gc.collect()
205212
if self._timeout > 0 and time.monotonic() - stamp > self._timeout:
206213
break
214+
print("{}, \nType:{}".format(received, type(received)))
207215
self._buffer += b''.join(received)
208216

209217
ret = None

0 commit comments

Comments
 (0)