Boy, I hope this hasn't been addressed already...
I have an application which builds and runs correctly under a wide variety
of Unicies (ULTRIX, AIX, SUN, NeXT, etc.) It is a daemon which listens
on a port, and does things when a client connects to it (TCP socket streams).
The main body of the daemon is a tight loop which does read(2) on a socket
descriptor returned earlier by an accept(2). As you might suspect, the
socket ought to be non-blocking, so that work can continue if there is no
data waiting to be processed, and so it is. After the call to socket(2),
I do a fcntl(2) on the descriptor setting the O_NDELAY flag (that's
O_NONBLOCK to you POSIX types...) This correctly makes the socket and
subsequent calls to read(2) non-blocking on all other platforms. But
the read() blocks under Linux (1.2.9 kernel).
I was able to fix the problem by also doing a fcntl() on the socket descriptor
returned by accept() and setting the O_NDELAY flag there too (it has to be
set on _both_; just setting it on the one returned by accept makes the
read() block). Weird. I read the man pages again, and I saw nothing to
indicate that it didn't have to be done that way... but, as I said, this
code worked fine on tons of other platforms.
So, am I on *? Is this a known bug? An unknown bug? Any help would
be appreciated (though, as I said, the code now works -- I'm just curious
as to what the deal is...)
Thanks!
--
===========================================================================
| Peter (Z-Man) Zatloukal | That is not dead, which may forever lie, |
===========================================================================