Eugene> Hi, This may be trivial, but I was not able to find an answer
Eugene> in any faq... I want to use the standard unix sockets in an
Eugene> asynchronous way. I.e. I want a send/recv command to return
Eugene> immediately. I am sure there is a way to specify a
Eugene> non-blocking socket, but I can not find it.
Careful; "asynchronous" and "non-blocking" are different terms; you need
to be sure which one you want.
If a socket is in non-blocking mode, then send() & recv() calls will not
block. Non-blocking mode is set by doing:
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
or
int i = 1;
ioctl(fd, FIONBIO, &i);
If a socket is in asynchronous mode, then SIGIO will be sent to the owning
process (or process group) when data is available. This is more complex to
handle, and much less portable.
Non-blocking mode + select() is usually much cleaner than asynchronous mode.
--
"Ceterum censeo Microsoftam delendam esse" - Alain Knaff in nanam