File: SSelect.c

package info (click to toggle)
ncftp 2%3A3.2.5-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 3,376 kB
  • ctags: 3,358
  • sloc: ansic: 39,640; sh: 3,560; makefile: 897; cpp: 612; perl: 101
file content (91 lines) | stat: -rw-r--r-- 1,915 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "syshdrs.h"
#ifdef PRAGMA_HDRSTOP
#	pragma hdrstop
#endif

void
SelectSetInit(SelectSetPtr const ssp, const double timeout)
{
	double i;
	tv_sec_t l;

	/* Inititalize SelectSet, which will clear the fd_set, the
	 * timeval, and the maxfd and numfds to 0.
	 */
	memset(ssp, 0, sizeof(SelectSet));
	l = (tv_sec_t) timeout;
	i = (double) l;
	ssp->timeout.tv_sec = l;
	ssp->timeout.tv_usec = (tv_usec_t) ((timeout - i) * 1000000.0);
}	/* SelectSetInit */




void
SelectSetAdd(SelectSetPtr const ssp, const int fd)
{
	if (fd >= 0) {
#if defined(__DECC) || defined(__DECCXX)
#pragma message save
#pragma message disable trunclongint
#endif
		MY_FD_SET(fd, &ssp->fds);
#if defined(__DECC) || defined(__DECCXX)
#pragma message restore
#endif
		if (ssp->maxfd < (fd + 1))
			ssp->maxfd = (fd + 1);
		++ssp->numfds;
	}
}	/* SelectSetAdd */




void
SelectSetRemove(SelectSetPtr const ssp, const int fd)
{
#if defined(__DECC) || defined(__DECCXX)
#pragma message save
#pragma message disable trunclongint
#endif
	if ((fd >= 0) && (MY_FD_ISSET(fd, &ssp->fds))) {
		MY_FD_CLR(fd, &ssp->fds);
		/* Note that maxfd is left alone, even if maxfd was
		 * this one.  That is okay.
		 */
		--ssp->numfds;
	}
#if defined(__DECC) || defined(__DECCXX)
#pragma message restore
#endif
}	/* SelectSetRemove */



int
SelectW(SelectSetPtr ssp, SelectSetPtr resultssp)
{
	int rc;

	do {
		memcpy(resultssp, ssp, sizeof(SelectSet));
		rc = select(resultssp->maxfd, NULL, SELECT_TYPE_ARG234 &resultssp->fds, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
	} while ((rc < 0) && (errno == EINTR));
	return (rc);
}	/* SelectW */



int
SelectR(SelectSetPtr ssp, SelectSetPtr resultssp)
{
	int rc;

	do {
		memcpy(resultssp, ssp, sizeof(SelectSet));
		rc = select(resultssp->maxfd, SELECT_TYPE_ARG234 &resultssp->fds, NULL, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
	} while ((rc < 0) && (errno == EINTR));
	return (rc);
}	/* SelectR */