Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: why does socket.makefile require non-blocking mode?

Reply
Thread Tools

Re: why does socket.makefile require non-blocking mode?

 
 
Forest
Guest
Posts: n/a
 
      03-31-2008
Bryan Olson wrote:

>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.


Just as I thought. Thanks for being my extra set of eyes.

>>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.


Yeah, I'll give it some more thought.

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


I guess you mean that since _fileobject.read() calls recv() multiple
times, the second and later calls might block even if select() said the
socket was
readable. That should be fixable by catching EAGAIN / EWOULDBLOCK and
returning early, shouldn't it? This idea seems consistent with the normal
file object's read() method docs, which say, "in non-blocking mode, less
data than what was requested may be returned." Making write() and flush()
friendly in non-blocking mode might be at little trickier.


 
Reply With Quote
 
 
 
 
greg
Guest
Posts: n/a
 
      04-06-2008
Forest wrote:
> I guess you mean that since _fileobject.read() calls recv() multiple
> times, the second and later calls might block even if select() said the
> socket was
> readable.


The main problem is buffering. The select() may block on
the socket even though the file object has data in its
buffer waiting to be read.

When using select(), you really need to deal with the
socket directly, with no buffering in the way.

--
Greg
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why does a Microsoft wheel mouse require software installation ? wylbur37 Computer Support 5 01-18-2005 02:05 PM
Re: Why does using keyword require a new scope? Jip from Paris ASP .Net 0 08-25-2003 08:02 AM
Re: Why does using keyword require a new scope? Herman Eldering ASP .Net 0 08-23-2003 11:32 PM



Advertisments