66
77
88This module provides access to the :c:func: `select ` and :c:func: `poll ` functions
9- available in most operating systems, :c:func: `epoll ` available on Linux 2.5+ and
9+ available in most operating systems, :c:func: `devpoll ` available on
10+ Solaris and derivatives, :c:func: `epoll ` available on Linux 2.5+ and
1011:c:func: `kqueue ` available on most BSD.
1112Note that on Windows, it only works for sockets; on other operating systems,
1213it also works for other file types (in particular, on Unix, it works on pipes).
@@ -24,6 +25,19 @@ The module defines the following:
2425 Following :pep: `3151 `, this class was made an alias of :exc: `OSError `.
2526
2627
28+ .. function :: devpoll()
29+ (Only supported on Solaris and derivatives.) Returns a ``/dev/poll ``
30+ polling object; see section :ref: `devpoll-objects ` below for the
31+ methods supported by devpoll objects.
32+
33+ :c:func: `devpoll ` objects are linked to the number of file
34+ descriptors allowed at the time of instantiation. If your program
35+ reduces this value, :c:func: `devpoll ` will fail. If your program
36+ increases this value, c:func: `devpoll ` may return an
37+ incomplete list of active file descriptors.
38+
39+ .. versionadded :: 3.3
40+
2741.. function :: epoll(sizehint=-1)
2842
2943 (Only supported on Linux 2.5.44 and newer.) Returns an edge polling object,
@@ -107,6 +121,74 @@ The module defines the following:
107121 .. versionadded :: 3.2
108122
109123
124+ .. _devpoll-objects :
125+
126+ ``/dev/poll `` Polling Objects
127+ ----------------------------------------------
128+
129+ http://developers.sun.com/solaris/articles/using_devpoll.html
130+ http://developers.sun.com/solaris/articles/polling_efficient.html
131+
132+ Solaris and derivatives have ``/dev/poll ``. While :c:func: `select ` is
133+ O(highest file descriptor) and :c:func: `poll ` is O(number of file
134+ descriptors), ``/dev/poll `` is O(active file descriptors).
135+
136+ ``/dev/poll `` behaviour is very close to the standard :c:func: `poll `
137+ object.
138+
139+
140+ .. method :: devpoll.register(fd[, eventmask])
141+
142+ Register a file descriptor with the polling object. Future calls to the
143+ :meth: `poll ` method will then check whether the file descriptor has any pending
144+ I/O events. *fd * can be either an integer, or an object with a :meth: `fileno `
145+ method that returns an integer. File objects implement :meth: `fileno `, so they
146+ can also be used as the argument.
147+
148+ *eventmask * is an optional bitmask describing the type of events you want to
149+ check for. The constants are the same that with :c:func: `poll `
150+ object. The default value is a combination of the constants :const: `POLLIN `,
151+ :const: `POLLPRI `, and :const: `POLLOUT `.
152+
153+ .. warning ::
154+
155+ Registering a file descriptor that's already registered is not an
156+ error, but the result is undefined. The appropiate action is to
157+ unregister or modify it first. This is an important difference
158+ compared with :c:func: `poll `.
159+
160+
161+ .. method :: devpoll.modify(fd[, eventmask])
162+
163+ This method does an :meth: `unregister ` followed by a
164+ :meth: `register `. It is (a bit) more efficient that doing the same
165+ explicitly.
166+
167+
168+ .. method :: devpoll.unregister(fd)
169+
170+ Remove a file descriptor being tracked by a polling object. Just like the
171+ :meth: `register ` method, *fd * can be an integer or an object with a
172+ :meth: `fileno ` method that returns an integer.
173+
174+ Attempting to remove a file descriptor that was never registered is
175+ safely ignored.
176+
177+
178+ .. method :: devpoll.poll([timeout])
179+
180+ Polls the set of registered file descriptors, and returns a possibly-empty list
181+ containing ``(fd, event) `` 2-tuples for the descriptors that have events or
182+ errors to report. *fd * is the file descriptor, and *event * is a bitmask with
183+ bits set for the reported events for that descriptor --- :const: `POLLIN ` for
184+ waiting input, :const: `POLLOUT ` to indicate that the descriptor can be written
185+ to, and so forth. An empty list indicates that the call timed out and no file
186+ descriptors had any events to report. If *timeout * is given, it specifies the
187+ length of time in milliseconds which the system will wait for events before
188+ returning. If *timeout * is omitted, -1, or :const: `None `, the call will
189+ block until there is an event for this poll object.
190+
191+
110192.. _epoll-objects :
111193
112194Edge and Level Trigger Polling (epoll) Objects
0 commit comments