RE: there's a socket.sendall(), so why no socket.recvall()?

Discussion in 'Python' started by Robert Brewer, Jan 8, 2005.

  1. Irmen de Jong wrote:
    > Subject says it all;
    > there's a socket.sendall(), so why no socket.recvall()?


    Good question! Something like:

    # Receive reply.
    data = []
    while True:
    try:
    chunk = conn.recv(8192)
    except Exception, x:
    if x.args[0] != 10035:
    raise x
    else:
    if chunk == '':
    break
    data.append(chunk)

    If you call .makefile() and then .read() the _fileobject, you get the
    same behavior (only better). Adding recvall would just duplicate that, I
    think. But that's desirable IMO.


    Robert Brewer
    MIS
    Amor Ministries
    Robert Brewer, Jan 8, 2005
    #1
    1. Advertising

  2. Robert Brewer wrote:
    > Irmen de Jong wrote:
    >
    >>Subject says it all;
    >>there's a socket.sendall(), so why no socket.recvall()?

    >

    [...]

    > If you call .makefile() and then .read() the _fileobject, you get the
    > same behavior (only better). Adding recvall would just duplicate that, I
    > think. But that's desirable IMO.


    Hm, I didn't consider makefile(). But I'm not sure if that
    works in all cases. Until now, I've been using a loop rather
    like the one you posted.

    But, as I pointed out earlier, there is the MSG_WAITALL option
    on various platforms (Linux for instance).

    So instead of sticking it in an explicitly programmed loop
    in Python, or using an extension module such as this one:
    http://mail.python.org/pipermail/python-list/2003-January/143051.html
    , I'd rather have a recvall method on the socket object that
    essentially uses MSG_WAITALL if available, and uses a
    loop construction if not.

    I may even write a patch for socketmodule.c right now :-D

    --Irmen de Jong
    Irmen de Jong, Jan 8, 2005
    #2
    1. Advertising

  3. Irmen de Jong wrote:
    >>> Subject says it all;
    >>> there's a socket.sendall(), so why no socket.recvall()?


    [...]

    > I may even write a patch for socketmodule.c right now :-D


    And here it is: the missing socket.recvall().

    http://www.python.org/sf/1103213


    --Irmen
    Irmen de Jong, Jan 16, 2005
    #3
  4. Robert Brewer

    Roger Binns Guest

    >>>> there's a socket.sendall(), so why no socket.recvall()?

    BTW socket.sendall() doesn't actually work for large amounts
    of data on Windows 2000 and probably other versions of
    Windows as well. Eg if you supply a 1MB buffer then you get
    an exception based on some internal Windows error code.
    I haven't experimented on Unix yet to see if it has the same
    issue.

    The workaround is to write a wrapper that really does send
    everything.

    Roger
    Roger Binns, Jan 16, 2005
    #4
  5. Roger Binns wrote:
    >>>>>there's a socket.sendall(), so why no socket.recvall()?

    >
    >
    > BTW socket.sendall() doesn't actually work for large amounts
    > of data on Windows 2000 and probably other versions of
    > Windows as well. Eg if you supply a 1MB buffer then you get
    > an exception based on some internal Windows error code.
    > I haven't experimented on Unix yet to see if it has the same
    > issue.


    I suspect that this is related to this issue:

    http://www.python.org/sf/853507
    socket.recv() raises MemoryError exception (WindowsXP ONLY)

    Also see:
    http://www.python.org/sf/1103350


    But I haven't yet experienced this problem yet with sendall
    (on linux and windows xp)

    --Irmen
    Irmen de Jong, Jan 16, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Black
    Replies:
    1
    Views:
    1,091
    Alan Kennedy
    Aug 3, 2004
  2. Irmen de Jong
    Replies:
    0
    Views:
    330
    Irmen de Jong
    Jan 8, 2005
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,804
    Smokey Grindel
    Dec 2, 2006
  4. Thomas Rachel
    Replies:
    0
    Views:
    195
    Thomas Rachel
    Jan 7, 2013
  5. Steven D'Aprano
    Replies:
    1
    Views:
    120
    Chris Angelico
    Jan 7, 2013
Loading...

Share This Page