Multiplexing Multiple Clients (Cont) Here is how to use 'select': #include /* 'struct timeval'. */ #include /* fd_set and its macros. */ #include /* 'select'. */ fd_set rfd; /* file descriptors to read from. */ int s1, s2; /* socket file descriptors. */ struct timeval timeout; /* time to wait in select. */ int rc; /* store our file descriptors in the given set. */ FD_ZERO(&rfd); FD_SET(s1, &rfd); FD_SET(s2, &rfd); /* prepare to wait up to 10 seconds. */ timeout.tv_sec = 10; timeout.tv_usec = 0; rc = select(max(s1, s2), &rfd, NULL, NULL, &timeout); if (rc > 0) { /* we got some input. */ if (FD_ISSET(s1, &rfd) ... /* there's input on descriptor 's1'. */ if (FD_ISSET(s2, &rfd) ... /* there's input on descriptor 's2'. */ }