select.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #define _XOPEN_SOURCE 600 /* Get pselect() in <sys/select.h> */
  2. #include "xmlrpc_config.h"
  3. #ifdef WIN32
  4. #include <winsock.h>
  5. #else
  6. /* In some systems (SUS), the select() interface comes from <sys/time.h>;
  7. in others, from <sys/select.h>, and other from both. Including both
  8. in this order appears to work on all.
  9. */
  10. #include <sys/time.h>
  11. #if HAVE_SYS_SELECT_H
  12. #include <sys/select.h>
  13. #endif
  14. #endif
  15. #include <signal.h>
  16. #include "xmlrpc-c/select_int.h"
  17. /* xmlrpc_pselect() is just for use with sockets. In a POSIX system,
  18. it technically works for any file descriptor, but in Windows, select()
  19. is part of the socket facility.
  20. */
  21. int
  22. xmlrpc_pselect(int const n,
  23. fd_set * const readfdsP,
  24. fd_set * const writefdsP,
  25. fd_set * const exceptfdsP,
  26. const xmlrpc_timespec * const timeoutP,
  27. sigset_t * const sigmaskP) {
  28. int retval;
  29. #if HAVE_PSELECT
  30. #if !HAVE_TIMESPEC
  31. #error "Impossible configuration -- has pselect(), but not struct timespec"
  32. #else
  33. retval = pselect(n, readfdsP, writefdsP, exceptfdsP, timeoutP, sigmaskP);
  34. #endif
  35. #else /* HAVE_PSELECT */
  36. struct timeval timeout;
  37. timeout.tv_sec = timeoutP->tv_sec;
  38. timeout.tv_usec = timeoutP->tv_nsec/1000;
  39. #ifdef WIN32
  40. retval = select(n, readfdsP, writefdsP, exceptfdsP, &timeout);
  41. #else
  42. {
  43. sigset_t origmask;
  44. sigprocmask(SIG_SETMASK, sigmaskP, &origmask);
  45. retval = select(n, readfdsP, writefdsP, exceptfdsP, &timeout);
  46. sigprocmask(SIG_SETMASK, &origmask, NULL);
  47. }
  48. #endif
  49. #endif
  50. return retval;
  51. }