Sockets: Sending/receiving arbitrary amounts of data

Alex Martelli aleaxit at yahoo.com
Wed May 2 04:29:26 EDT 2001


"Greg Ewing" <see at my.signature> wrote in message
news:3AEF82C7.F4FAD345 at my.signature...
> "Doobee R. Tzeck" wrote:
> >
> > Considering Python is a high level Language I ask myself
> > if there shouldend be a way in Python to optionally shield the
> > user (programmer) from the hassle of handling of short socket
> > reads.
>
> I think so, too. I once suggested that file.read(),
> socket.recv() and similar methods should have an
> optional two-argument form:
>
>    recv(min, max)
>
> This would block until at least min bytes had
> arrived, and return at most max bytes. If EOF
> occurs before min bytes have arrived, an exception
> is raised.
>
> Putting min == 0 gives the current behaviour.
> Putting min == max gives you a fixed-length read.
>
> Perhaps I'll PEP this one day, too.

Seems an elegant solution to me.  Perhaps backwards
compatibility would be better if the "min" argument
_followed_ the "max" one, so it could be more easily
given a default value of 0 to revert to current
behavior... that 'max' comes first might not be
very intuitive, but maybe renaming 'min' to some
very descriptive alternative, such as, I dunno,
'min_guaranteed', might help with that?


Alex






More information about the Python-list mailing list