1 '\" te
2 .\" Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH POLL 7D "Mar 28, 2007"
7 .SH NAME
8 poll \- driver for fast poll on many file descriptors
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fB#include <sys/devpoll.h>
13 int fd = open("/dev/poll", O_RDWR);
14 ssize_t n = write(int fd, struct pollfd buf[], int bufsize);
15 int n = ioctl(int fd, DP_POLL, struct dvpoll* arg);
16 int n = ioctl(int fd, DP_ISPOLLED, struct pollfd* pfd);\fR
17 .fi
18
19 .SH PARAMETERS
20 .sp
21 .ne 2
22 .na
23 \fB\fIfd\fR \fR
24 .ad
25 .RS 12n
26 Open file descriptor that refers to the \fB/dev/poll\fR driver.
231 ...
232
233 loopcnt = 0;
234 while (loopcnt < ITERATION) {
235 rn = random();
236 rn %= RANGE;
237 if (write(fds[rn], TESTSTRING, strlen(TESTSTRING)) !=
238 strlen(TESTSTRING)) {
239 perror("write to fifo failed.");
240 close (wfd);
241 free(pollfd);
242 error = 1;
243 goto out1;
244 }
245 dpfd.fd = fds[rn];
246 dpfd.events = 0;
247 dpfd.revents = 0;
248 result = ioctl(wfd, DP_ISPOLLED, &dpfd);
249 if (result < 0) {
250 perror("/dev/poll ioctl DP_ISPOLLED failed");
251 printf("errno = %d\n", errno);
252 close (wfd);
253 free(pollfd);
254 error = 1;
255 goto out1;
256 }
257 if (result != 1) {
258 printf("DP_ISPOLLED returned incorrect result: %d.\n",
259 result);
260 close (wfd);
261 free(pollfd);
262 error = 1;
263 goto out1;
264 }
265 if (dpfd.fd != fds[rn]) {
266 printf("DP_ISPOLLED returned wrong fd %d, expect %d\n",
267 dpfd.fd, fds[rn]);
268 close (wfd);
269 free(pollfd);
270 error = 1;
271 goto out1;
272 }
273 if (dpfd.revents != POLLIN) {
274 printf("DP_ISPOLLED returned unexpected revents %d\n",
275 dpfd.revents);
276 close (wfd);
277 free(pollfd);
278 error = 1;
279 goto out1;
280 }
281 if (read(dpfd.fd, rbuf, strlen(TESTSTRING)) !=
282 strlen(TESTSTRING)) {
283 perror("read from fifo failed");
284 close (wfd);
285 free(pollfd);
286 error = 1;
287 goto out1;
288 }
289 loopcnt++;
290 }
291
292 .fi
293 .in -2
294
|
1 '\" te
2 .\" Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH POLL 7D "Sep 10, 2013"
7 .SH NAME
8 poll \- driver for fast poll on many file descriptors
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fB#include <sys/devpoll.h>
13 int fd = open("/dev/poll", O_RDWR);
14 ssize_t n = write(int fd, struct pollfd buf[], int bufsize);
15 int n = ioctl(int fd, DP_POLL, struct dvpoll* arg);
16 int n = ioctl(int fd, DP_ISPOLLED, struct pollfd* pfd);\fR
17 .fi
18
19 .SH PARAMETERS
20 .sp
21 .ne 2
22 .na
23 \fB\fIfd\fR \fR
24 .ad
25 .RS 12n
26 Open file descriptor that refers to the \fB/dev/poll\fR driver.
231 ...
232
233 loopcnt = 0;
234 while (loopcnt < ITERATION) {
235 rn = random();
236 rn %= RANGE;
237 if (write(fds[rn], TESTSTRING, strlen(TESTSTRING)) !=
238 strlen(TESTSTRING)) {
239 perror("write to fifo failed.");
240 close (wfd);
241 free(pollfd);
242 error = 1;
243 goto out1;
244 }
245 dpfd.fd = fds[rn];
246 dpfd.events = 0;
247 dpfd.revents = 0;
248 result = ioctl(wfd, DP_ISPOLLED, &dpfd);
249 if (result < 0) {
250 perror("/dev/poll ioctl DP_ISPOLLED failed");
251 printf("errno = %d\en", errno);
252 close (wfd);
253 free(pollfd);
254 error = 1;
255 goto out1;
256 }
257 if (result != 1) {
258 printf("DP_ISPOLLED returned incorrect result: %d.\en",
259 result);
260 close (wfd);
261 free(pollfd);
262 error = 1;
263 goto out1;
264 }
265 if (dpfd.fd != fds[rn]) {
266 printf("DP_ISPOLLED returned wrong fd %d, expect %d\en",
267 dpfd.fd, fds[rn]);
268 close (wfd);
269 free(pollfd);
270 error = 1;
271 goto out1;
272 }
273 if (dpfd.revents != POLLIN) {
274 printf("DP_ISPOLLED returned unexpected revents %d\en",
275 dpfd.revents);
276 close (wfd);
277 free(pollfd);
278 error = 1;
279 goto out1;
280 }
281 if (read(dpfd.fd, rbuf, strlen(TESTSTRING)) !=
282 strlen(TESTSTRING)) {
283 perror("read from fifo failed");
284 close (wfd);
285 free(pollfd);
286 error = 1;
287 goto out1;
288 }
289 loopcnt++;
290 }
291
292 .fi
293 .in -2
294
|