CSCI.4220 Network Programming
Class 7,Thursday Feb 10, 2005
The select function and socket options

The book covers this material pretty exhaustively, so this page is sparser than most.

Here are the sample programs

simpleselect.c
select.c
getsockopt.c

Here is the code for a non-blocking read on a file or socket

int flags;
flags = fcntl(sock, F_GETFL,0);
fcntl(sock,F_SETFL,flags | O_NONBLOCK);
Now a call to read or recv will return immediately with a negative return value if there is nothing to read, and errno will be set to EWOULDBLOCK