Re: select.select and socket.setblocking

2009-01-03 Thread Roy Smith
Bryan Olson wrote: > There are cases where a socket can select() as readable, but not be > readable by the time of a following recv() or accept() call. All such > cases with which I'm familiar call for a non-blocking socket. I used to believe that if select() said data was ready for reading, a

Re: select.select and socket.setblocking

2009-01-03 Thread Saju Pillai
Bryan Olson wrote: > >Where does this come up? Suppose that to take advantage of multi-core >processors, our server runs as four processes, each with a single thread >that responds to events via select(). Clients all connect to the same >server port, so the socket listening on that port is sh

Re: select.select and socket.setblocking

2009-01-03 Thread Bryan Olson
Laszlo Nagy wrote: [...] I have read the socket programming howto ( http://docs.python.org/howto/sockets.html#sockets ) but it does not explain how a blocking socket + select is different from a non blocking socket + select. Is there any difference? There is, but it may not effect you. There ar

Re: select.select and socket.setblocking

2009-01-01 Thread Francesco Bochicchio
Can you post an example program that exhibits the behavior you describe? I was forgetting about the MSG_WAITALL flag ... When I started programming with sockets, it was on a platform (IIRC Solaris) that by default behaved like MSG_WAITALL was set by default (actually, I don't remember it be

Re: select.select and socket.setblocking

2008-12-31 Thread Hendrik van Rooyen
"Francesco Bochicchio" wrote: > but then, IIRC TCP guarantees that the packet is fully received by > hand-shaking at transport level between sender and receiver. Ad once the > packet is fully in the receiver buffer, why should recv choose to give > back to the application only a piece of it? T

Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio
Saju Pillai ha scritto: On Dec 31, 7:48 pm, Francesco Bochicchio wrote: Is this correct ? IIRC even in blocking mode recv() can return with less bytes than requested, unless the MSG_WAITALL flag is supplied. Blocking mode only guarantees that recv() will wait for a message if none is available

Re: select.select and socket.setblocking

2008-12-31 Thread Scott David Daniels
Jean-Paul Calderone wrote: ... On a LAN, it's likely that you'll generally get the exact number of bytes which the sender passed to one call of send (until the sender starts to pass really huge strings to send, then it'll get split up) just because the network has lots of capacity compared to the

Re: select.select and socket.setblocking

2008-12-31 Thread Grant Edwards
On 2008-12-31, Francesco Bochicchio wrote: > Grant Edwards ha scritto: >> On 2008-12-30, Francesco Bochicchio wrote: >> >>> 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in >>> select between blocking and non-blocking mode. The difference is in the >>> recv (again, assumin

Re: select.select and socket.setblocking

2008-12-31 Thread Jean-Paul Calderone
On Wed, 31 Dec 2008 15:48:50 +0100, Francesco Bochicchio wrote: < ... > Uhm. In my experience, with TCP protocol recv only returned less than the required bytes if the remote end disconnects. I always check the What if the sending end actually sent less than you asked for ? -srp In blocki

Re: select.select and socket.setblocking

2008-12-31 Thread Karen Tracey
On Wed, Dec 31, 2008 at 5:39 AM, Francesco Bochicchio wrote: > Francesco Bochicchio ha scritto: > >> >>> No, in blocking mode it will wait to receive _some_ data (1 or >>> more bytes). The "requested" amount is strictly an upper >>> limit: recv won't return more than the requested number of >>> b

Re: select.select and socket.setblocking

2008-12-31 Thread Saju Pillai
On Dec 31, 7:48 pm, Francesco Bochicchio wrote: > < ... > > > >> Uhm. In my experience, with TCP protocol recv only returned less than > >> the required bytes if the remote end disconnects. I always check the > > > What if the sending end actually sent less than you asked for ? > > > -srp > > In b

Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio
< ... > Uhm. In my experience, with TCP protocol recv only returned less than the required bytes if the remote end disconnects. I always check the What if the sending end actually sent less than you asked for ? -srp In blocking mode and with TCP protocol, the recv waits until more bytes a

Re: select.select and socket.setblocking

2008-12-31 Thread Saju Pillai
On Dec 31, 2:01 pm, Francesco Bochicchio wrote: > Grant Edwards ha scritto: > > > On 2008-12-30, Francesco Bochicchio wrote: > > >> 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in > >> select between blocking and non-blocking mode. The difference is in the > >> recv (again,

Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio
Francesco Bochicchio ha scritto: No, in blocking mode it will wait to receive _some_ data (1 or more bytes). The "requested" amount is strictly an upper limit: recv won't return more than the requested number of bytes, but it might return less. Uhm. In my experience, with TCP protocol recv o

Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio
Jean-Paul Calderone ha scritto: On Tue, 30 Dec 2008 19:19:08 +0100, Francesco Bochicchio wrote: [snip] If you are interested in socket errors, you should also fill the third 'fd-set' in the select call, and after select returns check that fd is not in it anymore: ready = select.select( [fd]

Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio
Grant Edwards ha scritto: On 2008-12-30, Francesco Bochicchio wrote: 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in select between blocking and non-blocking mode. The difference is in the recv (again, assuming that you use TCP as protocol, that is AF_INET, SOCK_STREAM)

Re: select.select and socket.setblocking

2008-12-30 Thread Jean-Paul Calderone
On Tue, 30 Dec 2008 15:55:51 -0500, Jean-Paul Calderone wrote: On Tue, 30 Dec 2008 14:41:17 -0600, Grant Edwards wrote: On 2008-12-30, Francesco Bochicchio wrote: 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in select between blocking and non-blocking mode. The differ

Re: select.select and socket.setblocking

2008-12-30 Thread Jean-Paul Calderone
On Tue, 30 Dec 2008 14:41:17 -0600, Grant Edwards wrote: On 2008-12-30, Francesco Bochicchio wrote: 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in select between blocking and non-blocking mode. The difference is in the recv (again, assuming that you use TCP as protocol

Re: select.select and socket.setblocking

2008-12-30 Thread Grant Edwards
On 2008-12-30, Francesco Bochicchio wrote: > 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in > select between blocking and non-blocking mode. The difference is in the > recv (again, assuming that you use TCP as protocol, that is AF_INET, > SOCK_STREAM), which in the block

Re: select.select and socket.setblocking

2008-12-30 Thread Jean-Paul Calderone
On Tue, 30 Dec 2008 19:19:08 +0100, Francesco Bochicchio wrote: [snip] If you are interested in socket errors, you should also fill the third 'fd-set' in the select call, and after select returns check that fd is not in it anymore: ready = select.select( [fd],[], [fd] ) if fd in ready[2]:

Re: select.select and socket.setblocking

2008-12-30 Thread Francesco Bochicchio
Laszlo Nagy ha scritto: I'm using this method to read from a socket: def read_data(self,size): """Read data from connection until a given size.""" res = "" fd = self.socket.fileno() while not self.stop_requested.isSet(): remaining = size - len(res)

Re: select.select and socket.setblocking

2008-12-30 Thread Steve Holden
Laszlo Nagy wrote: > I'm using this method to read from a socket: > >def read_data(self,size): >"""Read data from connection until a given size.""" >res = "" >fd = self.socket.fileno() >while not self.stop_requested.isSet(): >remaining = size - len(r