File: poll.2

package info (click to toggle)
manpages 1.29-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,796 kB
  • ctags: 5
  • sloc: sh: 79; makefile: 61
file content (124 lines) | stat: -rw-r--r-- 4,046 bytes parent folder | download | duplicates (3)
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
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (C) 1997 Andries Brouwer (aeb@cwi.nl)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\" 
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein.  The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\" 
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Additions from Richard Gooch <rgooch@atnf.CSIRO.AU> and aeb, 971207
.\"
.TH POLL 2 "7 December 1997" "Linux 2.1.23" "Linux Programmer's Manual"
.SH NAME
poll \- wait for some event on a file descriptor
.SH SYNOPSIS
.B #include <sys/poll.h>
.sp
.BI "int poll(struct pollfd *" ufds ", unsigned int " nfds ", int " timeout );
.SH DESCRIPTION
.B poll
is a variation on the theme of 
.BR select .
It specifies an array of
.I nfds
structures of type
.br
.nf
        struct pollfd {
                int fd;           /* file descriptor */
                short events;     /* requested events */
                short revents;    /* returned events */
        };
.fi
and a
.I timeout
in milliseconds. A negative value means infinite timeout.
The field
.I fd
contains a file descriptor for an open file.
The field
.I events
is an input parameter, a bitmask specifying the events the application
is interested in.
The field
.I revents
is an output parameter, filled by the kernel with the events that
actually occurred, either of the type requested, or of one of the
types
.B POLLERR
or
.B POLLHUP
or
.BR POLLNVAL .
(These three bits are meaningless in the
.I events
field, and will be set in the
.I revents
field whenever the corresponding condition is true.)
If none of the events requested (and no error) has occurred for any
of the file descriptors, the kernel waits for
.I timeout
milliseconds for one of these events to occur.
The following possible bits in these masks are defined in <sys/poll.h>
.br
.nf
    #define POLLIN      0x0001    /* There is data to read */
    #define POLLPRI     0x0002    /* There is urgent data to read */
    #define POLLOUT     0x0004    /* Writing now will not block */
    #define POLLERR     0x0008    /* Error condition */
    #define POLLHUP     0x0010    /* Hung up */
    #define POLLNVAL    0x0020    /* Invalid request: fd not open */
.fi
In <asm/poll.h> also the values
.BR POLLRDNORM ,
.BR POLLRDBAND ,
.BR POLLWRNORM ,
.B POLLWRBAND
and
.B POLLMSG
are defined.
.SH "RETURN VALUE"
On success, a positive number is returned, where the number returned
is the number of structures which have non-zero
.I revents
fields (in other words, those descriptors with events or errors reported).
A value of 0 indicates that the call timed out and no file
descriptors have been selected. On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B ENOMEM
There was no space to allocate file descriptor tables.
.TP
.B EFAULT
The array given as argument was not contained in the calling program's
address space.
.TP
.B EINTR
A signal occurred before any requested event.
.SH "CONFORMING TO"
XPG4-UNIX.
.SH AVAILABILITY
The poll() systemcall was introduced in Linux 2.1.23.
The poll() library call was introduced in libc 5.4.28
(and provides emulation using select if your kernel does not
have a poll syscall).
.SH "SEE ALSO"
.BR select (2)