home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / libncftp / libncftp-3.2.5-src.zip / libncftp-3.2.5 / sio / SSelect.c < prev    next >
C/C++ Source or Header  |  2001-11-19  |  2KB  |  92 lines

  1. #include "syshdrs.h"
  2. #ifdef PRAGMA_HDRSTOP
  3. #    pragma hdrstop
  4. #endif
  5.  
  6. void
  7. SelectSetInit(SelectSetPtr const ssp, const double timeout)
  8. {
  9.     double i;
  10.     tv_sec_t l;
  11.  
  12.     /* Inititalize SelectSet, which will clear the fd_set, the
  13.      * timeval, and the maxfd and numfds to 0.
  14.      */
  15.     memset(ssp, 0, sizeof(SelectSet));
  16.     l = (tv_sec_t) timeout;
  17.     i = (double) l;
  18.     ssp->timeout.tv_sec = l;
  19.     ssp->timeout.tv_usec = (tv_usec_t) ((timeout - i) * 1000000.0);
  20. }    /* SelectSetInit */
  21.  
  22.  
  23.  
  24.  
  25. void
  26. SelectSetAdd(SelectSetPtr const ssp, const int fd)
  27. {
  28.     if (fd >= 0) {
  29. #if defined(__DECC) || defined(__DECCXX)
  30. #pragma message save
  31. #pragma message disable trunclongint
  32. #endif
  33.         MY_FD_SET(fd, &ssp->fds);
  34. #if defined(__DECC) || defined(__DECCXX)
  35. #pragma message restore
  36. #endif
  37.         if (ssp->maxfd < (fd + 1))
  38.             ssp->maxfd = (fd + 1);
  39.         ++ssp->numfds;
  40.     }
  41. }    /* SelectSetAdd */
  42.  
  43.  
  44.  
  45.  
  46. void
  47. SelectSetRemove(SelectSetPtr const ssp, const int fd)
  48. {
  49. #if defined(__DECC) || defined(__DECCXX)
  50. #pragma message save
  51. #pragma message disable trunclongint
  52. #endif
  53.     if ((fd >= 0) && (MY_FD_ISSET(fd, &ssp->fds))) {
  54.         MY_FD_CLR(fd, &ssp->fds);
  55.         /* Note that maxfd is left alone, even if maxfd was
  56.          * this one.  That is okay.
  57.          */
  58.         --ssp->numfds;
  59.     }
  60. #if defined(__DECC) || defined(__DECCXX)
  61. #pragma message restore
  62. #endif
  63. }    /* SelectSetRemove */
  64.  
  65.  
  66.  
  67. int
  68. SelectW(SelectSetPtr ssp, SelectSetPtr resultssp)
  69. {
  70.     int rc;
  71.  
  72.     do {
  73.         memcpy(resultssp, ssp, sizeof(SelectSet));
  74.         rc = select(resultssp->maxfd, NULL, SELECT_TYPE_ARG234 &resultssp->fds, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
  75.     } while ((rc < 0) && (errno == EINTR));
  76.     return (rc);
  77. }    /* SelectW */
  78.  
  79.  
  80.  
  81. int
  82. SelectR(SelectSetPtr ssp, SelectSetPtr resultssp)
  83. {
  84.     int rc;
  85.  
  86.     do {
  87.         memcpy(resultssp, ssp, sizeof(SelectSet));
  88.         rc = select(resultssp->maxfd, SELECT_TYPE_ARG234 &resultssp->fds, NULL, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
  89.     } while ((rc < 0) && (errno == EINTR));
  90.     return (rc);
  91. }    /* SelectR */
  92.