[Python-checkins] r46642 - in python/trunk: Lib/socket.py Lib/struct.py Lib/test/test_socket.py Lib/test/test_struct.py Modules/_struct.c Modules/socketmodule.c
"Martin v. Löwis"
martin at v.loewis.de
Mon Jun 5 00:29:32 CEST 2006
Thomas Wouters wrote:
> Martin, any comments about the availability of ssize_t and the use of
> Py_ssize_t instead?
In general, return values should be stored in a variable of the same
type as the return type of the function being called. Single Unix 2
documents recv as
ssize_t recv(int socket, void *buffer, size_t length, int flags);
so it is safe to use ssize_t on all systems conforming to Single
Unix. OTOH, WinSock declares recv as
int recv(SOCKET s, char FAR* buf, int len, int flags);
So apparently, WinSock2 is limited to 2GiB of data per receive call.
socketmodule currently also limits the size of recv buffers to 2GiB
(the entire socket module isn't Py_ssize_t-clean). So the code was
actually correct before the patch.
If ssize_t variables are used, that must be conditional on the return
type of recv actually being ssize_t. That, in turn, might be difficult
to determine; HAVE_SSIZE_T is probably a good-enough approximation.
If the patch is reverted, a cast to (int) could be added, along with
a comment that this shouldn't truncate, as recv shouldn't return a
value larger than the length being passed in.
Regards,
Martin
More information about the Python-checkins
mailing list