QUERY · ISSUE
esp8266 nonblocking ussl: `read(N)` never returns any data
port-esp8266
MicroPython version: esp8266-20210618-v1.16, esp8266-20210629-unstable-v1.16-39-g4ada56d4c
s = usocket.socket()
s.connect(usocket.getaddrinfo(server, port)[0][-1])
conn = ussl.wrap_socket(s, server_hostname=server)
s.settimeout(0) # or s.setblocking(False)
conn.write(b"some data") # OK: server gets the data and replies
while True:
data = conn.read(1) # increasing count doesn't help
print('>', data)
Outputs:
> None
> None
> None
> None
> None
> None
> None
> None
> None
> None
> None
> None
> b''
> b''
> b''
> b''
> b''
...
No data is received.
Observations:
- If I set
conn = s(i.e. use plain insecure TCP), it works - If I replace
s.settimeout(0)withs.settimeout(1), it works for for some 5-10 seconds, thenconn.readstops blocking for 1 second, returns quickly and no more data is received - If I replace
s.settimeout(0)withs.settimeout(0.1), I getOSError: -261onconn.read - Same code works on ESP32
CANDIDATE · ISSUE
Non-blocking UDP socket returns ETIMEDOUT on recv instead on EAGAIN on ESP8266
extmod
When reading from non-blocking UDP socket with no data available ETIMEDOUT error is returned. One would expect EAGAIN or EWOULDBLOCK in such situation.
For example:
>>> import usocket
>>> s = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)
>>> address = usocket.getaddrinfo('192.168.0.24', 4005)[0][-1]
>>> s.bind(address)
>>> s.settimeout(0)
>>> s
<socket state=0 timeout=0 incoming=0 off=0>
>>> s.recv(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 110] ETIMEDOUT
The incorrect behaviour is observed for ESP8266 platform:
>>> sys.platform
'esp8266'
>>> sys.implementation
(name='micropython', version=(1, 12, 0), mpy=9733)
Looking at the modlwip.c code, there seems to be no special treatment applied for timeout value of 0:
https://github.com/micropython/micropython/blob/master/extmod/modlwip.c#L597