← index #18531PR #4219
Related · high · value 0.192
QUERY · ISSUE

Add function 'settimeout' to class SSLSocket

openby magnus-0opened 2025-12-08updated 2026-03-09
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.

closedby pfalconopened 2018-10-07updated 2018-10-17
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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied