diff options
| author | Mike Wang <mikewang000000@gmail.com> | 2025-09-21 01:44:59 +0800 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-09-23 14:06:37 +1000 |
| commit | cf097932a2a7ffd03958a8a14d9c87bd477ac5c3 (patch) | |
| tree | f9fe1663db78cc8a797e69910392edf87d8fbaf1 /tests/extmod/socket_fileno.py | |
| parent | a277fe4a36f09558e57c89b7e365e34af14b1cf3 (diff) | |
unix/modsocket: Set file descriptor to -1 on close.
After s.close(), s.fileno() now returns -1, matching CPython behavior.
Some code relies on this compatibility, as it allows checking whether
a socket is closed by testing its fileno() value. This change ensures
better interoperability with existing Python code and libraries.
Signed-off-by: Mike Wang <mikewang000000@gmail.com>
Diffstat (limited to 'tests/extmod/socket_fileno.py')
| -rw-r--r-- | tests/extmod/socket_fileno.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/extmod/socket_fileno.py b/tests/extmod/socket_fileno.py new file mode 100644 index 000000000..da15825e3 --- /dev/null +++ b/tests/extmod/socket_fileno.py @@ -0,0 +1,17 @@ +# Test socket.fileno() functionality + +try: + import socket +except ImportError: + print("SKIP") + raise SystemExit + +if not hasattr(socket.socket, "fileno"): + print("SKIP") + raise SystemExit + +s = socket.socket() +print(s.fileno() >= 0) + +s.close() +print(s.fileno()) # should print -1 |
