STINNER Victor added the comment:
The patch uses the flag MSG_WAITALL for recv() if available. Extract of the
manual page:
MSG_WAITALL (since Linux 2.2)
This flag requests that the operation block until the full
request is satisfied. However, the call may still return less
data than requested if a signal is caught, an error or discon-
nect occurs, or the next data to be received is of a different
type than that returned.
It looks interesting, but it doesn't guarantee that you will always get exactly
the expected size. You still have to call again recv() to get more data if a
signal was received.
Jean-Paul Calderone wrote:
> Since MSG_WAITALL is already exposed to Python (when the underlying platform
> provides it), I wonder if this could all be implemented more simply in pure
> Python. Can you elaborate on the motivation to use C?
sendall() is implemented in C while it would be possible to implement it in
Python. The same rationale can be used on a large part of the stdlib :-) (The
io module is implemented in Python in Python 2.6!)
The C gives you a full control on the GIL, signal handle, and it might be
faster.
Antoine Pitrou wrote:
> I'm frankly not sure why this is useful.
recvall() allows to easily fix existing code: just replace recv() with
recvall(), no need to refactor code to call makefile() which has a different
API (ex: read/recv, write/send).
The addition is small and well defined.
--
About the exception: asyncio.StreamReader.read_exactly() raises an
IncompleteReadError which contains the read bytes and inherits from EOFError:
see
https://docs.python.org/dev/library/asyncio-stream.html#asyncio.StreamReader.readexactly
and
https://docs.python.org/dev/library/asyncio-stream.html#asyncio.IncompleteReadError
The following issue discussed the design on this exception in asyncio:
https://code.google.com/p/tulip/issues/detail?id=111
http.client uses an IncompleteRead (which inherits from HTTPException):
https://docs.python.org/dev/library/http.client.html#http.client.IncompleteRead
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue1103213>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com