The select() function can be used to block on more than descriptor
simultaneously.
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
...
int err;
fd_set readfds;
FD_ZERO (&readfds);
FD_SET (s, &readfds);
FD_SET (STDIN_FILENO, &readfds);
err = select (s + 1, &readfds, NULL, NULL, NULL);
if (err < 0) perror ("select failed");
else {
if (FD_ISSET (s, &readfds)) handle_socket (s);
if (FD_ISSET (STDIN_FILENO, &readfds)) handle_user ();
}
|