why does socket.makefile require non-blocking mode?

Discussion in 'Python' started by Forest, Mar 28, 2008.

  1. Forest

    Forest Guest

    The socket.makefile() docs say, "the socket must be in blocking mode." I
    don't see any explanation of why blocking mode is required, and I'm not sure
    whether that means timeout mode is forbidden as well. Can someone clarify
    this?

    I wanted to use file-like objects with socket timeouts, so I ended up writing
    my own replacement for socket._fileobject. I'd appreciate it if someone could
    either explain to my why my new class was unnecessary, or else encourage me to
    contribute it as a patch to the socket module.

    Cheers,

    Forest
    Forest, Mar 28, 2008
    #1
    1. Advertising

  2. Forest

    Bryan Olson Guest

    Forest wrote:
    > The socket.makefile() docs say, "the socket must be in blocking mode." I
    > don't see any explanation of why blocking mode is required, and I'm not sure
    > whether that means timeout mode is forbidden as well. Can someone clarify
    > this?


    Looking at the code for the existing _fileobject's read method, it
    will loose data it has already read if a socket.recv() call raises
    an exception. The function keeps buffers in a local variable that
    will be lost if an exception exits the scope. That much could be
    fixed with a try...finally. Other methods have similar problems.

    > I wanted to use file-like objects with socket timeouts, so I ended up writing
    > my own replacement for socket._fileobject. I'd appreciate it if someone could
    > either explain to my why my new class was unnecessary, or else encourage me to
    > contribute it as a patch to the socket module.


    Sure, fix it. A harder problem is that it doesn't play nice with select().


    --
    --Bryan
    Bryan Olson, Mar 29, 2008
    #2
    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,093
    Alan Kennedy
    Aug 3, 2004
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,842
    Smokey Grindel
    Dec 2, 2006
  3. Forest
    Replies:
    1
    Views:
    426
  4. Serge Savoie
    Replies:
    4
    Views:
    267
    Serge Savoie
    Oct 1, 2008
  5. Antoon Pardon
    Replies:
    0
    Views:
    134
    Antoon Pardon
    Jan 9, 2013
Loading...

Share This Page