QUERY · ISSUE
Add function 'settimeout' to class SSLSocket
enhancementextmod
Description
After wrapping a micropython socket to get a SSLSocket, the function 'settimeout()' fails, reporting that feature doesn't exist (same with 'gettimeout()'). Interestingly though, the 'setblocking()' function does exist and seemingly work.
AttributeError: 'SSLSocket' object has no attribute 'settimeout'
Code Size
Irrelevant (the feature was most likely already supposed to be there but overlooked?)
Implementation
I hope the MicroPython maintainers or community will implement this feature
Code of Conduct
Yes, I agree
[MODERATOR: This topic may have been better posted under 'micropython-lib' instead of plain micropython...
CANDIDATE · PULL REQUEST
unix/modusocket: Finish socket.settimeout() implementation.
unix/modusocket: Initial implementation of socket.settimeout().
unix/modusocket: Finish socket.settimeout() implementation.
1. Return correct error code for non-blocking vs timed out socket
(POSIX returns EAGAIN for both, we want ETIMEDOUT in case of timed
out socket). To achieve this, blocking/non-blocking flag is added
to the mp_obj_socket_t, to avoid issuing fcntl() syscall each time
EAGAIN occurs. (mp_obj_socket_t used to be 8 bytes, having some room
in a standard 16-byte alloc block.)
2. Handle socket.settimeout(0) properly - in Python, that means
non-blocking mode, but SO_RCVTIMEO/SO_SNDTIMEO of 0 is infinite
timeout.
3. Overall, make sure that socket.settimeout() call switches blocking
state as expected.