blob: 02ce775461bbac828abd13bfa5323c7d2fb742d7 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`select` --- Waiting for I/O completion
2============================================
3
4.. module:: select
5 :synopsis: Wait for I/O completion on multiple streams.
6
7
Georg Brandl60203b42010-10-06 10:11:56 +00008This module provides access to the :c:func:`select` and :c:func:`poll` functions
Jesus Cead8b9ae62011-11-14 19:07:41 +01009available in most operating systems, :c:func:`devpoll` available on
10Solaris and derivatives, :c:func:`epoll` available on Linux 2.5+ and
Georg Brandl60203b42010-10-06 10:11:56 +000011:c:func:`kqueue` available on most BSD.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000012Note that on Windows, it only works for sockets; on other operating systems,
13it also works for other file types (in particular, on Unix, it works on pipes).
14It cannot be used on regular files to determine whether a file has grown since
15it was last read.
Georg Brandl116aa622007-08-15 14:28:22 +000016
17The module defines the following:
18
19
20.. exception:: error
21
Antoine Pitrou9b7fcf82011-10-12 16:23:02 +020022 A deprecated alias of :exc:`OSError`.
23
24 .. versionchanged:: 3.3
25 Following :pep:`3151`, this class was made an alias of :exc:`OSError`.
Georg Brandl116aa622007-08-15 14:28:22 +000026
27
Jesus Cead8b9ae62011-11-14 19:07:41 +010028.. function:: devpoll()
Jesus Ceaf450c1b2011-11-15 05:42:59 +010029
Jesus Cead8b9ae62011-11-14 19:07:41 +010030 (Only supported on Solaris and derivatives.) Returns a ``/dev/poll``
31 polling object; see section :ref:`devpoll-objects` below for the
32 methods supported by devpoll objects.
33
34 :c:func:`devpoll` objects are linked to the number of file
35 descriptors allowed at the time of instantiation. If your program
36 reduces this value, :c:func:`devpoll` will fail. If your program
Jesus Ceaf450c1b2011-11-15 05:42:59 +010037 increases this value, :c:func:`devpoll` may return an
Jesus Cead8b9ae62011-11-14 19:07:41 +010038 incomplete list of active file descriptors.
39
Victor Stinnerdaf45552013-08-28 00:53:59 +020040 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
41
Jesus Cead8b9ae62011-11-14 19:07:41 +010042 .. versionadded:: 3.3
43
Victor Stinnerdaf45552013-08-28 00:53:59 +020044 .. versionchanged:: 3.4
45 The new file descriptor is now non-inheritable.
46
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060047.. function:: epoll(sizehint=-1, flags=0)
Christian Heimes4fbc72b2008-03-22 00:47:35 +000048
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060049 (Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
50 which can be used as Edge or Level Triggered interface for I/O
51 events. *sizehint* is deprecated and completely ignored. *flags* can be set
52 to :const:`EPOLL_CLOEXEC`, which causes the epoll descriptor to be closed
53 automatically when :func:`os.execve` is called. See section
54 :ref:`epoll-objects` below for the methods supported by epolling objects.
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010055 They also support the :keyword:`with` statement.
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060056
Victor Stinnerdaf45552013-08-28 00:53:59 +020057 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
58
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060059 .. versionchanged:: 3.3
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060060 Added the *flags* parameter.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000061
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010062 .. versionchanged:: 3.4
63 Support for the :keyword:`with` statement was added.
Victor Stinnerdaf45552013-08-28 00:53:59 +020064 The new file descriptor is now non-inheritable.
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010065
Christian Heimes4fbc72b2008-03-22 00:47:35 +000066
Georg Brandl116aa622007-08-15 14:28:22 +000067.. function:: poll()
68
69 (Not supported by all operating systems.) Returns a polling object, which
70 supports registering and unregistering file descriptors, and then polling them
71 for I/O events; see section :ref:`poll-objects` below for the methods supported
72 by polling objects.
73
74
Christian Heimesfe337bf2008-03-23 21:54:12 +000075.. function:: kqueue()
Christian Heimes4fbc72b2008-03-22 00:47:35 +000076
Georg Brandle767e042010-07-14 08:00:22 +000077 (Only supported on BSD.) Returns a kernel queue object; see section
Christian Heimesfe337bf2008-03-23 21:54:12 +000078 :ref:`kqueue-objects` below for the methods supported by kqueue objects.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000079
Victor Stinnerdaf45552013-08-28 00:53:59 +020080 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
81
82 .. versionchanged:: 3.4
83 The new file descriptor is now non-inheritable.
84
Christian Heimes4fbc72b2008-03-22 00:47:35 +000085
Benjamin Peterson1baf4652009-12-31 03:11:23 +000086.. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)
Christian Heimes4fbc72b2008-03-22 00:47:35 +000087
Georg Brandle767e042010-07-14 08:00:22 +000088 (Only supported on BSD.) Returns a kernel event object; see section
89 :ref:`kevent-objects` below for the methods supported by kevent objects.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000090
Christian Heimes4fbc72b2008-03-22 00:47:35 +000091
Georg Brandl734e2682008-08-12 08:18:18 +000092.. function:: select(rlist, wlist, xlist[, timeout])
Georg Brandl116aa622007-08-15 14:28:22 +000093
Georg Brandl60203b42010-10-06 10:11:56 +000094 This is a straightforward interface to the Unix :c:func:`select` system call.
Georg Brandl116aa622007-08-15 14:28:22 +000095 The first three arguments are sequences of 'waitable objects': either
96 integers representing file descriptors or objects with a parameterless method
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +030097 named :meth:`~io.IOBase.fileno` returning such an integer:
Georg Brandl734e2682008-08-12 08:18:18 +000098
99 * *rlist*: wait until ready for reading
100 * *wlist*: wait until ready for writing
101 * *xlist*: wait for an "exceptional condition" (see the manual page for what
102 your system considers such a condition)
103
104 Empty sequences are allowed, but acceptance of three empty sequences is
105 platform-dependent. (It is known to work on Unix but not on Windows.) The
106 optional *timeout* argument specifies a time-out as a floating point number
107 in seconds. When the *timeout* argument is omitted the function blocks until
108 at least one file descriptor is ready. A time-out value of zero specifies a
109 poll and never blocks.
Georg Brandl116aa622007-08-15 14:28:22 +0000110
111 The return value is a triple of lists of objects that are ready: subsets of the
112 first three arguments. When the time-out is reached without a file descriptor
113 becoming ready, three empty lists are returned.
114
115 .. index::
116 single: socket() (in module socket)
117 single: popen() (in module os)
118
Antoine Pitrou11cb9612010-09-15 11:11:28 +0000119 Among the acceptable object types in the sequences are Python :term:`file
120 objects <file object>` (e.g. ``sys.stdin``, or objects returned by
121 :func:`open` or :func:`os.popen`), socket objects returned by
122 :func:`socket.socket`. You may also define a :dfn:`wrapper` class yourself,
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300123 as long as it has an appropriate :meth:`~io.IOBase.fileno` method (that
124 really returns a file descriptor, not just a random integer).
Georg Brandl116aa622007-08-15 14:28:22 +0000125
Georg Brandl116aa622007-08-15 14:28:22 +0000126 .. note::
127
128 .. index:: single: WinSock
129
Georg Brandl734e2682008-08-12 08:18:18 +0000130 File objects on Windows are not acceptable, but sockets are. On Windows,
Georg Brandl60203b42010-10-06 10:11:56 +0000131 the underlying :c:func:`select` function is provided by the WinSock
Georg Brandl734e2682008-08-12 08:18:18 +0000132 library, and does not handle file descriptors that don't originate from
133 WinSock.
Georg Brandl116aa622007-08-15 14:28:22 +0000134
Antoine Pitroucfad97b2011-01-25 17:24:57 +0000135.. attribute:: PIPE_BUF
Gregory P. Smithb970b862009-07-04 02:28:47 +0000136
Antoine Pitrouda7be3e2011-01-25 16:28:44 +0000137 The minimum number of bytes which can be written without blocking to a pipe
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300138 when the pipe has been reported as ready for writing by :func:`~select.select`,
Antoine Pitrouda7be3e2011-01-25 16:28:44 +0000139 :func:`poll` or another interface in this module. This doesn't apply
140 to other kind of file-like objects such as sockets.
141
Amaury Forgeot d'Arcace31022009-07-09 22:44:11 +0000142 This value is guaranteed by POSIX to be at least 512. Availability: Unix.
Gregory P. Smithb970b862009-07-04 02:28:47 +0000143
Mark Dickinson574b1d62009-10-01 20:20:09 +0000144 .. versionadded:: 3.2
Gregory P. Smithb970b862009-07-04 02:28:47 +0000145
Georg Brandl116aa622007-08-15 14:28:22 +0000146
Jesus Cead8b9ae62011-11-14 19:07:41 +0100147.. _devpoll-objects:
148
149``/dev/poll`` Polling Objects
150----------------------------------------------
151
152 http://developers.sun.com/solaris/articles/using_devpoll.html
153 http://developers.sun.com/solaris/articles/polling_efficient.html
154
155Solaris and derivatives have ``/dev/poll``. While :c:func:`select` is
156O(highest file descriptor) and :c:func:`poll` is O(number of file
157descriptors), ``/dev/poll`` is O(active file descriptors).
158
159``/dev/poll`` behaviour is very close to the standard :c:func:`poll`
160object.
161
162
Victor Stinner13423c32013-08-22 00:19:50 +0200163.. method:: devpoll.close()
164
165 Close the file descriptor of the polling object.
166
167 .. versionadded:: 3.4
168
169
170.. attribute:: devpoll.closed
171
172 ``True`` if the polling object is closed.
173
174 .. versionadded:: 3.4
175
176
177.. method:: devpoll.fileno()
178
179 Return the file descriptor number of the polling object.
180
181 .. versionadded:: 3.4
182
183
Jesus Cead8b9ae62011-11-14 19:07:41 +0100184.. method:: devpoll.register(fd[, eventmask])
185
186 Register a file descriptor with the polling object. Future calls to the
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300187 :meth:`poll` method will then check whether the file descriptor has any
188 pending I/O events. *fd* can be either an integer, or an object with a
189 :meth:`~io.IOBase.fileno` method that returns an integer. File objects
190 implement :meth:`!fileno`, so they can also be used as the argument.
Jesus Cead8b9ae62011-11-14 19:07:41 +0100191
192 *eventmask* is an optional bitmask describing the type of events you want to
193 check for. The constants are the same that with :c:func:`poll`
194 object. The default value is a combination of the constants :const:`POLLIN`,
195 :const:`POLLPRI`, and :const:`POLLOUT`.
196
197 .. warning::
198
199 Registering a file descriptor that's already registered is not an
200 error, but the result is undefined. The appropiate action is to
201 unregister or modify it first. This is an important difference
202 compared with :c:func:`poll`.
203
204
205.. method:: devpoll.modify(fd[, eventmask])
206
207 This method does an :meth:`unregister` followed by a
208 :meth:`register`. It is (a bit) more efficient that doing the same
209 explicitly.
210
211
212.. method:: devpoll.unregister(fd)
213
214 Remove a file descriptor being tracked by a polling object. Just like the
215 :meth:`register` method, *fd* can be an integer or an object with a
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300216 :meth:`~io.IOBase.fileno` method that returns an integer.
Jesus Cead8b9ae62011-11-14 19:07:41 +0100217
218 Attempting to remove a file descriptor that was never registered is
219 safely ignored.
220
221
222.. method:: devpoll.poll([timeout])
223
224 Polls the set of registered file descriptors, and returns a possibly-empty list
225 containing ``(fd, event)`` 2-tuples for the descriptors that have events or
226 errors to report. *fd* is the file descriptor, and *event* is a bitmask with
227 bits set for the reported events for that descriptor --- :const:`POLLIN` for
228 waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
229 to, and so forth. An empty list indicates that the call timed out and no file
230 descriptors had any events to report. If *timeout* is given, it specifies the
231 length of time in milliseconds which the system will wait for events before
232 returning. If *timeout* is omitted, -1, or :const:`None`, the call will
233 block until there is an event for this poll object.
234
235
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000236.. _epoll-objects:
237
238Edge and Level Trigger Polling (epoll) Objects
239----------------------------------------------
240
241 http://linux.die.net/man/4/epoll
242
243 *eventmask*
244
245 +-----------------------+-----------------------------------------------+
246 | Constant | Meaning |
247 +=======================+===============================================+
248 | :const:`EPOLLIN` | Available for read |
249 +-----------------------+-----------------------------------------------+
250 | :const:`EPOLLOUT` | Available for write |
251 +-----------------------+-----------------------------------------------+
252 | :const:`EPOLLPRI` | Urgent data for read |
253 +-----------------------+-----------------------------------------------+
Christian Heimes5e696852008-04-09 08:37:03 +0000254 | :const:`EPOLLERR` | Error condition happened on the assoc. fd |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000255 +-----------------------+-----------------------------------------------+
Christian Heimes5e696852008-04-09 08:37:03 +0000256 | :const:`EPOLLHUP` | Hang up happened on the assoc. fd |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000257 +-----------------------+-----------------------------------------------+
258 | :const:`EPOLLET` | Set Edge Trigger behavior, the default is |
259 | | Level Trigger behavior |
260 +-----------------------+-----------------------------------------------+
261 | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is |
262 | | pulled out, the fd is internally disabled |
263 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000264 | :const:`EPOLLRDNORM` | Equivalent to :const:`EPOLLIN` |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000265 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000266 | :const:`EPOLLRDBAND` | Priority data band can be read. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000267 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000268 | :const:`EPOLLWRNORM` | Equivalent to :const:`EPOLLOUT` |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000269 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000270 | :const:`EPOLLWRBAND` | Priority data may be written. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000271 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000272 | :const:`EPOLLMSG` | Ignored. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000273 +-----------------------+-----------------------------------------------+
274
275
276.. method:: epoll.close()
277
278 Close the control file descriptor of the epoll object.
279
280
Victor Stinner13423c32013-08-22 00:19:50 +0200281.. attribute:: epoll.closed
282
283 ``True`` if the epoll object is closed.
284
285
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000286.. method:: epoll.fileno()
287
288 Return the file descriptor number of the control fd.
289
290
291.. method:: epoll.fromfd(fd)
292
293 Create an epoll object from a given file descriptor.
294
295
296.. method:: epoll.register(fd[, eventmask])
297
298 Register a fd descriptor with the epoll object.
299
300
301.. method:: epoll.modify(fd, eventmask)
302
303 Modify a register file descriptor.
304
305
306.. method:: epoll.unregister(fd)
307
308 Remove a registered file descriptor from the epoll object.
309
310
Hynek Schlawackdfa46522012-05-21 11:01:54 +0200311.. method:: epoll.poll(timeout=-1, maxevents=-1)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000312
313 Wait for events. timeout in seconds (float)
314
315
Georg Brandl116aa622007-08-15 14:28:22 +0000316.. _poll-objects:
317
318Polling Objects
319---------------
320
Georg Brandl60203b42010-10-06 10:11:56 +0000321The :c:func:`poll` system call, supported on most Unix systems, provides better
Georg Brandl116aa622007-08-15 14:28:22 +0000322scalability for network servers that service many, many clients at the same
Georg Brandl60203b42010-10-06 10:11:56 +0000323time. :c:func:`poll` scales better because the system call only requires listing
324the file descriptors of interest, while :c:func:`select` builds a bitmap, turns
Georg Brandl116aa622007-08-15 14:28:22 +0000325on bits for the fds of interest, and then afterward the whole bitmap has to be
Georg Brandl60203b42010-10-06 10:11:56 +0000326linearly scanned again. :c:func:`select` is O(highest file descriptor), while
327:c:func:`poll` is O(number of file descriptors).
Georg Brandl116aa622007-08-15 14:28:22 +0000328
329
330.. method:: poll.register(fd[, eventmask])
331
332 Register a file descriptor with the polling object. Future calls to the
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300333 :meth:`poll` method will then check whether the file descriptor has any
334 pending I/O events. *fd* can be either an integer, or an object with a
335 :meth:`~io.IOBase.fileno` method that returns an integer. File objects
336 implement :meth:`!fileno`, so they can also be used as the argument.
Georg Brandl116aa622007-08-15 14:28:22 +0000337
338 *eventmask* is an optional bitmask describing the type of events you want to
339 check for, and can be a combination of the constants :const:`POLLIN`,
340 :const:`POLLPRI`, and :const:`POLLOUT`, described in the table below. If not
341 specified, the default value used will check for all 3 types of events.
342
343 +-------------------+------------------------------------------+
344 | Constant | Meaning |
345 +===================+==========================================+
346 | :const:`POLLIN` | There is data to read |
347 +-------------------+------------------------------------------+
348 | :const:`POLLPRI` | There is urgent data to read |
349 +-------------------+------------------------------------------+
350 | :const:`POLLOUT` | Ready for output: writing will not block |
351 +-------------------+------------------------------------------+
352 | :const:`POLLERR` | Error condition of some sort |
353 +-------------------+------------------------------------------+
354 | :const:`POLLHUP` | Hung up |
355 +-------------------+------------------------------------------+
356 | :const:`POLLNVAL` | Invalid request: descriptor not open |
357 +-------------------+------------------------------------------+
358
359 Registering a file descriptor that's already registered is not an error, and has
360 the same effect as registering the descriptor exactly once.
361
362
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000363.. method:: poll.modify(fd, eventmask)
364
365 Modifies an already registered fd. This has the same effect as
Jean-Paul Calderone7f94f392010-07-18 16:13:27 +0000366 ``register(fd, eventmask)``. Attempting to modify a file descriptor
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000367 that was never registered causes an :exc:`IOError` exception with errno
368 :const:`ENOENT` to be raised.
369
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000370
Georg Brandl116aa622007-08-15 14:28:22 +0000371.. method:: poll.unregister(fd)
372
373 Remove a file descriptor being tracked by a polling object. Just like the
374 :meth:`register` method, *fd* can be an integer or an object with a
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300375 :meth:`~io.IOBase.fileno` method that returns an integer.
Georg Brandl116aa622007-08-15 14:28:22 +0000376
377 Attempting to remove a file descriptor that was never registered causes a
378 :exc:`KeyError` exception to be raised.
379
380
381.. method:: poll.poll([timeout])
382
383 Polls the set of registered file descriptors, and returns a possibly-empty list
384 containing ``(fd, event)`` 2-tuples for the descriptors that have events or
385 errors to report. *fd* is the file descriptor, and *event* is a bitmask with
386 bits set for the reported events for that descriptor --- :const:`POLLIN` for
387 waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
388 to, and so forth. An empty list indicates that the call timed out and no file
389 descriptors had any events to report. If *timeout* is given, it specifies the
390 length of time in milliseconds which the system will wait for events before
391 returning. If *timeout* is omitted, negative, or :const:`None`, the call will
392 block until there is an event for this poll object.
393
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000394
395.. _kqueue-objects:
396
397Kqueue Objects
398--------------
399
400.. method:: kqueue.close()
401
402 Close the control file descriptor of the kqueue object.
403
404
Victor Stinner13423c32013-08-22 00:19:50 +0200405.. attribute:: kqueue.closed
406
407 ``True`` if the kqueue object is closed.
408
409
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000410.. method:: kqueue.fileno()
411
412 Return the file descriptor number of the control fd.
413
414
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000415.. method:: kqueue.fromfd(fd)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000416
417 Create a kqueue object from a given file descriptor.
418
419
Hynek Schlawack979f37a2012-05-22 16:12:18 +0200420.. method:: kqueue.control(changelist, max_events[, timeout=None]) -> eventlist
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000421
422 Low level interface to kevent
423
424 - changelist must be an iterable of kevent object or None
425 - max_events must be 0 or a positive integer
426 - timeout in seconds (floats possible)
427
428
429.. _kevent-objects:
430
431Kevent Objects
432--------------
433
Christian Heimesfe337bf2008-03-23 21:54:12 +0000434http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000435
Christian Heimesfe337bf2008-03-23 21:54:12 +0000436.. attribute:: kevent.ident
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000437
438 Value used to identify the event. The interpretation depends on the filter
439 but it's usually the file descriptor. In the constructor ident can either
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300440 be an int or an object with a :meth:`~io.IOBase.fileno` method. kevent
441 stores the integer internally.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000442
Christian Heimesfe337bf2008-03-23 21:54:12 +0000443.. attribute:: kevent.filter
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000444
Georg Brandl1b5ab452009-08-13 07:56:35 +0000445 Name of the kernel filter.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000446
447 +---------------------------+---------------------------------------------+
448 | Constant | Meaning |
449 +===========================+=============================================+
450 | :const:`KQ_FILTER_READ` | Takes a descriptor and returns whenever |
451 | | there is data available to read |
452 +---------------------------+---------------------------------------------+
453 | :const:`KQ_FILTER_WRITE` | Takes a descriptor and returns whenever |
Georg Brandl1b5ab452009-08-13 07:56:35 +0000454 | | there is data available to write |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000455 +---------------------------+---------------------------------------------+
456 | :const:`KQ_FILTER_AIO` | AIO requests |
457 +---------------------------+---------------------------------------------+
458 | :const:`KQ_FILTER_VNODE` | Returns when one or more of the requested |
459 | | events watched in *fflag* occurs |
460 +---------------------------+---------------------------------------------+
461 | :const:`KQ_FILTER_PROC` | Watch for events on a process id |
462 +---------------------------+---------------------------------------------+
463 | :const:`KQ_FILTER_NETDEV` | Watch for events on a network device |
464 | | [not available on Mac OS X] |
465 +---------------------------+---------------------------------------------+
466 | :const:`KQ_FILTER_SIGNAL` | Returns whenever the watched signal is |
467 | | delivered to the process |
468 +---------------------------+---------------------------------------------+
469 | :const:`KQ_FILTER_TIMER` | Establishes an arbitrary timer |
470 +---------------------------+---------------------------------------------+
471
Christian Heimesfe337bf2008-03-23 21:54:12 +0000472.. attribute:: kevent.flags
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000473
Georg Brandl1b5ab452009-08-13 07:56:35 +0000474 Filter action.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000475
476 +---------------------------+---------------------------------------------+
477 | Constant | Meaning |
478 +===========================+=============================================+
479 | :const:`KQ_EV_ADD` | Adds or modifies an event |
480 +---------------------------+---------------------------------------------+
481 | :const:`KQ_EV_DELETE` | Removes an event from the queue |
482 +---------------------------+---------------------------------------------+
483 | :const:`KQ_EV_ENABLE` | Permitscontrol() to returns the event |
484 +---------------------------+---------------------------------------------+
485 | :const:`KQ_EV_DISABLE` | Disablesevent |
486 +---------------------------+---------------------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000487 | :const:`KQ_EV_ONESHOT` | Removes event after first occurrence |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000488 +---------------------------+---------------------------------------------+
489 | :const:`KQ_EV_CLEAR` | Reset the state after an event is retrieved |
490 +---------------------------+---------------------------------------------+
491 | :const:`KQ_EV_SYSFLAGS` | internal event |
492 +---------------------------+---------------------------------------------+
493 | :const:`KQ_EV_FLAG1` | internal event |
494 +---------------------------+---------------------------------------------+
495 | :const:`KQ_EV_EOF` | Filter specific EOF condition |
496 +---------------------------+---------------------------------------------+
497 | :const:`KQ_EV_ERROR` | See return values |
498 +---------------------------+---------------------------------------------+
499
500
Christian Heimesfe337bf2008-03-23 21:54:12 +0000501.. attribute:: kevent.fflags
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000502
Georg Brandl1b5ab452009-08-13 07:56:35 +0000503 Filter specific flags.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000504
Georg Brandl1b5ab452009-08-13 07:56:35 +0000505 :const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000506
507 +----------------------------+--------------------------------------------+
508 | Constant | Meaning |
509 +============================+============================================+
510 | :const:`KQ_NOTE_LOWAT` | low water mark of a socket buffer |
511 +----------------------------+--------------------------------------------+
512
Georg Brandl1b5ab452009-08-13 07:56:35 +0000513 :const:`KQ_FILTER_VNODE` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000514
515 +----------------------------+--------------------------------------------+
516 | Constant | Meaning |
517 +============================+============================================+
518 | :const:`KQ_NOTE_DELETE` | *unlink()* was called |
519 +----------------------------+--------------------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000520 | :const:`KQ_NOTE_WRITE` | a write occurred |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000521 +----------------------------+--------------------------------------------+
522 | :const:`KQ_NOTE_EXTEND` | the file was extended |
523 +----------------------------+--------------------------------------------+
524 | :const:`KQ_NOTE_ATTRIB` | an attribute was changed |
525 +----------------------------+--------------------------------------------+
526 | :const:`KQ_NOTE_LINK` | the link count has changed |
527 +----------------------------+--------------------------------------------+
528 | :const:`KQ_NOTE_RENAME` | the file was renamed |
529 +----------------------------+--------------------------------------------+
530 | :const:`KQ_NOTE_REVOKE` | access to the file was revoked |
531 +----------------------------+--------------------------------------------+
532
Georg Brandl1b5ab452009-08-13 07:56:35 +0000533 :const:`KQ_FILTER_PROC` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000534
535 +----------------------------+--------------------------------------------+
536 | Constant | Meaning |
537 +============================+============================================+
538 | :const:`KQ_NOTE_EXIT` | the process has exited |
539 +----------------------------+--------------------------------------------+
540 | :const:`KQ_NOTE_FORK` | the process has called *fork()* |
541 +----------------------------+--------------------------------------------+
542 | :const:`KQ_NOTE_EXEC` | the process has executed a new process |
543 +----------------------------+--------------------------------------------+
544 | :const:`KQ_NOTE_PCTRLMASK` | internal filter flag |
545 +----------------------------+--------------------------------------------+
546 | :const:`KQ_NOTE_PDATAMASK` | internal filter flag |
547 +----------------------------+--------------------------------------------+
548 | :const:`KQ_NOTE_TRACK` | follow a process across *fork()* |
549 +----------------------------+--------------------------------------------+
550 | :const:`KQ_NOTE_CHILD` | returned on the child process for |
551 | | *NOTE_TRACK* |
552 +----------------------------+--------------------------------------------+
553 | :const:`KQ_NOTE_TRACKERR` | unable to attach to a child |
554 +----------------------------+--------------------------------------------+
555
Georg Brandl1b5ab452009-08-13 07:56:35 +0000556 :const:`KQ_FILTER_NETDEV` filter flags (not available on Mac OS X):
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000557
558 +----------------------------+--------------------------------------------+
559 | Constant | Meaning |
560 +============================+============================================+
561 | :const:`KQ_NOTE_LINKUP` | link is up |
562 +----------------------------+--------------------------------------------+
563 | :const:`KQ_NOTE_LINKDOWN` | link is down |
564 +----------------------------+--------------------------------------------+
565 | :const:`KQ_NOTE_LINKINV` | link state is invalid |
566 +----------------------------+--------------------------------------------+
567
568
Christian Heimesfe337bf2008-03-23 21:54:12 +0000569.. attribute:: kevent.data
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000570
Georg Brandl1b5ab452009-08-13 07:56:35 +0000571 Filter specific data.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000572
573
Christian Heimesfe337bf2008-03-23 21:54:12 +0000574.. attribute:: kevent.udata
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000575
Georg Brandl1b5ab452009-08-13 07:56:35 +0000576 User defined value.