← index #16803PR #17369
Duplicate · high · value 2.672
QUERY · ISSUE

UNIX build missing socket.sendall() method

openby petrkropened 2025-02-24updated 2025-06-04
bugport-unix

Port, board and/or hardware

UNIX

MicroPython version

$ micropython 
MicroPython v1.24.1 on 2025-02-24; linux [GCC 14.2.1] version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import socket
>>> s = socket.socket()
>>> dir(s)
['__class__', 'close', 'read', 'readinto', 'readline', 'send', 'write', 'accept', 'bind', 'connect', 'fileno', 'listen', 'makefile', 'recv', 'recvfrom', 'sendto', 'setblocking', 'setsockopt', 'settimeout']
>>> 

Regarding to documentation, sendall is supported. On ESP32 build it is available

MicroPython v1.24.1 on 2024-11-29; Generic ESP32 module with ESP32                                        
Type "help()" for more information.                                                                       
>>>                                                                                                       
>>> import socket                                                                                         
>>> s = socket.socket()                                                                                                                                                                                          
>>> dir (s)                                                                                                                                                                                                      
['__class__', 'close', 'read', 'readinto', 'readline', 'send', 'write', '__del__', 'accept', 'bind', 'conn
ect', 'fileno', 'listen', 'makefile', 'recv', 'recvfrom', 'sendall', 'sendto', 'setblocking', 'setsockopt'
, 'settimeout']                                                                                           

Unix build was created by using AUR package https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=micropython

Reproduction

Build unix version of uPy
import socket

try to call sendall(packet)

Expected behaviour

Method will be there, so do not need rewrite libraries just for one port

Observed behaviour

what is this ?

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

unix/modsocket: Add "sendall" method to socket class.

openby agattiopened 2025-05-27updated 2026-03-20
port-unix

Summary

This PR adds an implementation for "socket.sendall" to the Unix port.

Right now the implementation is a wrapper over a single "socket.send" call, since it wasn't possible to let "socket.send" perform a partial transfer. With no partial transfers it is not possible to have a testable implementation following the expected behaviour, so a single send operation is done and OSErr(EINTR) is raised if a partial transfer occurs.

The discussion for the issue linked to this PR contains more information about the efforts made to let partial transfers happen.

This fixes #16803.

Testing

A new test is introduced to exercise socket.sendall, called tests/multi_net/tcp_sendall.py. This could have been folded into tests/multi_net/tcp_data.py, but the Zephyr port doesn't have a socket.sendall implementation.

Trade-offs and Alternatives

There's a modest size increase. The footprint increase could have been smaller if socket.sendall was aliased to socket.send like the CC3200 port does, but then the behaviour would be slightly incompatible with CPython (socket.sendall is supposed to return None, not the sent bytes count).

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