Guest User

Untitled

a guest
Jul 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. /**
  2. * Processes every client.
  3. *
  4. * Returns the number of clients processed.
  5. *
  6. * Returns -1 if error.
  7. */
  8. int runloop_process_clients(RunloopRef runloop, int timeout_seconds)
  9. {
  10. ListIteratorRef iter = ONew(listiterator,(runloop->clients));
  11. int fd;
  12. fd_set set;
  13. struct timeval timeout;
  14. int result;
  15.  
  16. timeout.tv_sec = timeout_seconds;
  17. timeout.tv_usec = 0;
  18.  
  19. FD_ZERO(&set);
  20.  
  21. while( listiterator_next(iter, (void*)&fd) )
  22. {
  23. FD_SET(fd, &set);
  24. }
  25.  
  26. ORelease(iter);
  27.  
  28. result = select(FD_SETSIZE, &set, NULL, NULL, &timeout);
  29.  
  30. if( result > 0 )
  31. {
  32. iter = ONew(listiterator,(runloop->clients));
  33.  
  34. while( listiterator_next(iter, (void*)&fd) )
  35. {
  36. // file descriptor ready for reading
  37. if( FD_ISSET(fd, &set) )
  38. {
  39. if( ! fd )
  40. {
  41. runloop_process_stdin(runloop, fd);
  42. }
  43. else
  44. {
  45. runloop_process_socket(runloop, fd);
  46. }
  47. }
  48. }
  49.  
  50. ORelease(iter);
  51. }
  52.  
  53. return result;
  54. }
Add Comment
Please, Sign In to add comment