Added ncftp to rosapps
[reactos.git] / rosapps / net / ncftp / sio / SSelect.c
1 #include "syshdrs.h"
2
3 void
4 SelectSetInit(SelectSetPtr const ssp, const double timeout)
5 {
6 double i;
7 long l;
8
9 /* Inititalize SelectSet, which will clear the fd_set, the
10 * timeval, and the maxfd and numfds to 0.
11 */
12 memset(ssp, 0, sizeof(SelectSet));
13 l = (long) timeout;
14 i = (double) l;
15 ssp->timeout.tv_sec = l;
16 ssp->timeout.tv_usec = (long) ((timeout - i) * 1000000.0);
17 } /* SelectSetInit */
18
19
20
21
22 void
23 SelectSetAdd(SelectSetPtr const ssp, const int fd)
24 {
25 if (fd >= 0) {
26 FD_SET(fd, &ssp->fds);
27 if (ssp->maxfd < (fd + 1))
28 ssp->maxfd = (fd + 1);
29 ++ssp->numfds;
30 }
31 } /* SelectSetAdd */
32
33
34
35
36 void
37 SelectSetRemove(SelectSetPtr const ssp, const int fd)
38 {
39 if ((fd >= 0) && (FD_ISSET(fd, &ssp->fds))) {
40 FD_CLR(fd, &ssp->fds);
41 /* Note that maxfd is left alone, even if maxfd was
42 * this one. That is okay.
43 */
44 --ssp->numfds;
45 }
46 } /* SelectSetRemove */
47
48
49
50 int
51 SelectW(SelectSetPtr ssp, SelectSetPtr resultssp)
52 {
53 int rc;
54
55 do {
56 memcpy(resultssp, ssp, sizeof(SelectSet));
57 rc = select(resultssp->maxfd, NULL, SELECT_TYPE_ARG234 &resultssp->fds, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
58 } while ((rc < 0) && (errno == EINTR));
59 return (rc);
60 } /* SelectW */
61
62
63
64 int
65 SelectR(SelectSetPtr ssp, SelectSetPtr resultssp)
66 {
67 int rc;
68
69 do {
70 memcpy(resultssp, ssp, sizeof(SelectSet));
71 rc = select(resultssp->maxfd, SELECT_TYPE_ARG234 &resultssp->fds, NULL, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
72 } while ((rc < 0) && (errno == EINTR));
73 return (rc);
74 } /* SelectR */