Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Processes every client.
- *
- * Returns the number of clients processed.
- *
- * Returns -1 if error.
- */
- int runloop_process_clients(RunloopRef runloop, int timeout_seconds)
- {
- ListIteratorRef iter = ONew(listiterator,(runloop->clients));
- int fd;
- fd_set set;
- struct timeval timeout;
- int result;
- timeout.tv_sec = timeout_seconds;
- timeout.tv_usec = 0;
- FD_ZERO(&set);
- while( listiterator_next(iter, (void*)&fd) )
- {
- FD_SET(fd, &set);
- }
- ORelease(iter);
- result = select(FD_SETSIZE, &set, NULL, NULL, &timeout);
- if( result > 0 )
- {
- iter = ONew(listiterator,(runloop->clients));
- while( listiterator_next(iter, (void*)&fd) )
- {
- // file descriptor ready for reading
- if( FD_ISSET(fd, &set) )
- {
- if( ! fd )
- {
- runloop_process_stdin(runloop, fd);
- }
- else
- {
- runloop_process_socket(runloop, fd);
- }
- }
- }
- ORelease(iter);
- }
- return result;
- }
Add Comment
Please, Sign In to add comment