Quote:
Originally Posted by oddabe
How do I use select()?
Select lets the system efficiently wait for events on a number of file descriptors or else timeout. Any X application has select as the call that is executed when the application has nothing to do.
There are three sets of filedescriptors, those for reading, those for writing and those for exceptional conditions, a file descriptor may be in multiple sets.
When you get EGAIN or EWOULDBLOCK use select to tell you when the filedescriptor is ready again.
fd_set fds;
FD_ZERO(&fds);
FD_SET(fd,&fds);
i=select(fd+1,&fds,NULL,NULL,NULL);
if (i>0)
{
if (FD_ISSET(fd,&fds)) { do your thing )
}