why does socket.makefile require non-blocking mode?

F

Forest

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
 
B

Bryan Olson

Forest said:
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().
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top