#include #include #include #include #include #include #define max(a,b) ((a)<(b)?(a):(b)) int main (int argc, char **argv) { fd_set fdRead; struct timeval tv; int lastFh; FD_ZERO (fdRead); FD_SET (clientHandle, fdRead); FD_SET (serverHandle, fdRead); lastFH = max (clientHandle, serverHandle) + 1; tv.tv_sec = 1; tv.tv_usec = 0; switch (select (lastFH, &fdRead, NULL, NULL, &tv)) { case -1 : exit (0); // bad juju, should never happen case 0 : printf ("1 second timeout\n"); o break; default : { if (FD_ISSET (clientHandle, fdRead)) readClientWriteToServer (); if (FD_ISSET (serverHandle, fdRead)) readServerWriteToClient (); } break; } exit (0); }