NIO CommKit Host Interface Installation and System Administration Manual

6-29
Porting CommKit Applications To Release 4.x
Examples
8 ** Do some processing but look for data on file
9 ** descriptor ’fd’.
10 */
11 procl(fd)
12 {
13
14 static struct pollfd dkxpoll;
15 static struct pollfd *fds = &dkxpoll;
16
17 /* arrange to catch SIGPOLL */
18 (void) signal(SIGPOLL, catchpoll);
19
20 fds->fd = fd;
21 fds->events = POLLIN;
22
23 /*
24 ** Watch for data on fd with the I_SETSIG ioctl.
25 */
26
27 ioctl(fd, I_SETSIG, S_RDNORM);
28 if ( poll( fds, 1, 0 ) == 1 ) {
29 /*
30 ** If there is data on the stream from
31 ** before the ioctl call, process it here.
32 */
33-42
43 }
44
45 /*
46 ** Continue processing, if data arrives on fd this code
47 ** will be interrupted and the new data will be serviced
48 ** by the signal catching function. Remember that while
49 ** we have I_SETSIG active system calls may return -1
50 ** with errno set to EINTR. */
51-87
88 /*
89 ** Stop watching for data on fd with the I_SETSIG ioctl.
90 */
91
92 ioctl(fd, I_SETSIG, 0);
93 }
94
95 static void
96 catchpoll (signo)
97 {
98 /* data has arrived on file descriptor fd */
99
100 /* reset the signal catching */
101 (void) signal(SIGPOLL, catchpoll);
102
103 /*
104 ** read and process new data
105 */
106-116
117 }