Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

O_NONBLOCK vs. O_NDELAY for non-blocking sockets

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


hniksic at srce

May 24, 1999, 6:46 PM

Post #1 of 4 (2143 views)
Permalink
O_NONBLOCK vs. O_NDELAY for non-blocking sockets

Apparently the setblocking() method of socket objects is setting the
O_NDELAY flag to set the socket to non-blocking mode. However, _POSIX
Programmer's Guide_ by Donald Lewine says:

O_NONBLOCK: Do not wait for the device or file to be ready or
available. After the file is open, the read() and
write() calls always return immediately. If the
process would be delayed in the read or write
operation, -1 is returned and errno is set to EAGAIN
instead of blocking the caller.

System V provides a flag called O_NDELAY that is
similar to O_NONBLOCK. The O_NDELAY flag causes
read() or write() to return zero instead of blocking.
Since read() also returns zero on end-of-file, it is
difficult to distinguish the two cases. BSD also has
an O_NDELAY flag that causes the error EWOULDBLOCK to
be returned if the process would block. POSIX
resolved this incompatibility by inventing the
O_NONBLOCK flag. Port with care!

Based on this, I believe Python should use O_NONBLOCK where available,
O_NDELAY otherwise. On Linux, both are the same thing, but on Solaris
they are not, and O_NONBLOCK should be preferred.


hniksic at srce

May 25, 1999, 6:28 AM

Post #2 of 4 (2108 views)
Permalink
O_NONBLOCK vs. O_NDELAY for non-blocking sockets [In reply to]

"Gordon McMillan" <gmcm [at] hypernet> writes:

> All these flavors of sockets are available on HPUX. Python manages
> to build with BSD semantics. Maybe it's just dumb luck though
> <wink>, when I glance at configure, I don't see anything that sets
> this.

Huh? Just look at Modules/socketmodule.c, the definition of
setblocking(), and use of O_NDELAY is right there.


gmcm at hypernet

May 25, 1999, 6:59 AM

Post #3 of 4 (2107 views)
Permalink
O_NONBLOCK vs. O_NDELAY for non-blocking sockets [In reply to]

Hrvoje Niksic writes:

> Apparently the setblocking() method of socket objects is setting the
> O_NDELAY flag to set the socket to non-blocking mode. However,
> _POSIX Programmer's Guide_ by Donald Lewine says:

[. when nothing there yet:
POSIX: O_NONBLOCK
-1; errno == EAGAIN
BSD: O_NDELAY
-1; errno == EWOULDBLOCK
SYSV: O_NDELAY
0; errno == EWOULDBLOCK ]

All these flavors of sockets are available on HPUX. Python manages to
build with BSD semantics. Maybe it's just dumb luck though <wink>,
when I glance at configure, I don't see anything that sets this.

Don't have the docs around at the moment to check, but I think there
some other subtle differences between BSD and POSIX sockets. As I
recall, in the handling of OOB.

Cherry-red-Camaro-with-original-BSD-sockets-ly y'rs

- Gordon


gmcm at hypernet

May 25, 1999, 7:47 PM

Post #4 of 4 (2083 views)
Permalink
O_NONBLOCK vs. O_NDELAY for non-blocking sockets [In reply to]

Hrvoje Niksic writes:

> "Gordon McMillan" <gmcm [at] hypernet> writes:
>
> > All these flavors of sockets are available on HPUX. Python manages
> > to build with BSD semantics. Maybe it's just dumb luck though
> > <wink>, when I glance at configure, I don't see anything that sets
> > this.
>
> Huh? Just look at Modules/socketmodule.c, the definition of
> setblocking(), and use of O_NDELAY is right there.

I meant setting BSD semantics vs SysV.

- Gordon

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.