Author vstinner
Recipients exarkun, irmen, loewis, pitrou, vstinner
Date 2015-01-16.11:16:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1421406981.41.0.690969235568.issue1103213@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2015-01-16 11:16:21vstinnersetrecipients: + vstinner, loewis, irmen, exarkun, pitrou
2015-01-16 11:16:21vstinnersetmessageid: <1421406981.41.0.690969235568.issue1103213@psf.upfronthosting.co.za>
2015-01-16 11:16:21vstinnerlinkissue1103213 messages
2015-01-16 11:16:20vstinnercreate