aboutsummaryrefslogtreecommitdiff
path: root/sys/libc/cpoll.c
blob: 65f05274e2b92bbc570bb1273f0473f209888bed (plain) (blame)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/

#define import_spp
#define import_libc
#define import_fpoll
#define import_xnames
#include <iraf.h>


/* C_POLL --  LIBC binding to the FIO polling interface.
**
**       fds = c_poll_open ()                   # open a poll descriptor set
**         npolls = c_poll (fds, nfds, timeout) # poll the set
**            c_poll_close (fds)                # free the poll descriptor set
**
**             c_poll_zero (fds)                # zero the poll array
**              c_poll_set (fds, fd, type)      # set fd to poll for type
**            c_poll_clear (fds, fd, type)      # unset type on fd poll
**       y/n = c_poll_test (fds, fd, type)      # test fd for type event
**            c_poll_print (fds)                # print the poll array
**     N = c_poll_get_nfds (fds)                # get size of descriptor set
*/


/* C_POLL_OPEN -- Open a poll descriptor set.
*/
XINT
c_poll_open ( void )
{
	XINT	fds;

	iferr ((fds = (XINT) POLL_OPEN ()))
	    return (NULL);
	else 
	    return (fds);
}


/* C_POLL -- Poll the descriptor set.
*/
int
c_poll (
  XINT	fds,					/* descriptor set ptr	*/
  int	nfds,					/* no. descriptors	*/
  int	timeout					/* poll timeout		*/
)
{
	XINT  x_fds = fds, x_nfds = nfds, x_timeout = timeout;

	return ((int) POLL (&x_fds, &x_nfds, &x_timeout));
}


/* C_POLL_CLOSE -- Close and free a poll descriptor set.
*/
void
c_poll_close (
  XINT	fds					/* descriptor set ptr	*/
)
{
	XINT  x_fds = fds;

	POLL_CLOSE (&x_fds);
}


/* C_POLL_ZERO -- Zero the descriptor set.
*/
void
c_poll_zero (
  XINT	fds					/* descriptor set ptr	*/
)
{
	XINT  x_fds = fds;

	POLL_ZERO (&x_fds);
}


/* C_POLL_SET --  Add a descriptor to the set, and/or modify the event type.
** The type may be a bitwise or of testable events.
*/
void
c_poll_set (
  XINT	fds,					/* descriptor set ptr	*/
  XINT	fd,					/* no. descriptors	*/
  int	type					/* event type		*/
)
{
	XINT  x_fds = fds, x_fd = fd, x_type = type;

	POLL_SET (&x_fds, &x_fd, &x_type);
}


/* C_POLL_CLEAR --  Remove a descriptor or event type from the set.  The type
** may be a bitwise or of testable events.  If the event mask becomes NULL the
** descriptor is removed entirely from the set.
*/
void
c_poll_clear (
  XINT	fds,					/* descriptor set ptr	*/
  XINT	fd,					/* no. descriptors	*/
  int	type					/* event type		*/
)
{
	XINT  x_fds = fds, x_fd = fd, x_type = type;

	POLL_CLEAR (&x_fds, &x_fd, &x_type);
}


/* C_POLL_TEST -- Test the descriptor for the given event type.
*/
int
c_poll_test (
  XINT	fds,					/* descriptor set ptr	*/
  XINT	fd,					/* no. descriptors	*/
  int	type					/* event type		*/
)
{
	XINT  x_fds = fds, x_fd = fd, x_type = type;

	return ((int) POLL_TEST (&x_fds, &x_fd, &x_type));
}


/* C_POLL_GET_NFDS -- Return the size of the descriptor set.
*/
int
c_poll_get_nfds (
  XINT	fds					/* descriptor set ptr	*/
)
{
	XINT  x_fds = fds;

	return (POLL_GET_NFDS (&x_fds));
}


/* C_POLL_PRINT --  Debug print utility.
*/
void
c_poll_print (XINT fds) 
{ 
	XINT  x_fds = fds;

	POLL_PRINT (&x_fds); 
}