blob: 524e411f2cc36c026acafa3b924adcc6b1c88f4e [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
Victor Stinner73821c42013-09-04 20:40:13 +020017.. note::
18
19 The :mod:`selectors` module allows high-level and efficient I/O
20 multiplexing, built upon the :mod:`select` module primitives. Users are
21 encouraged to use the :mod:`selectors` module instead, unless they want
22 precise control over the OS-level primitives used.
23
24
Georg Brandl116aa622007-08-15 14:28:22 +000025The module defines the following:
26
27
28.. exception:: error
29
Antoine Pitrou9b7fcf82011-10-12 16:23:02 +020030 A deprecated alias of :exc:`OSError`.
31
32 .. versionchanged:: 3.3
33 Following :pep:`3151`, this class was made an alias of :exc:`OSError`.
Georg Brandl116aa622007-08-15 14:28:22 +000034
35
Jesus Cead8b9ae62011-11-14 19:07:41 +010036.. function:: devpoll()
Jesus Ceaf450c1b2011-11-15 05:42:59 +010037
Jesus Cead8b9ae62011-11-14 19:07:41 +010038 (Only supported on Solaris and derivatives.) Returns a ``/dev/poll``
39 polling object; see section :ref:`devpoll-objects` below for the
40 methods supported by devpoll objects.
41
42 :c:func:`devpoll` objects are linked to the number of file
43 descriptors allowed at the time of instantiation. If your program
44 reduces this value, :c:func:`devpoll` will fail. If your program
Jesus Ceaf450c1b2011-11-15 05:42:59 +010045 increases this value, :c:func:`devpoll` may return an
Jesus Cead8b9ae62011-11-14 19:07:41 +010046 incomplete list of active file descriptors.
47
Victor Stinnerdaf45552013-08-28 00:53:59 +020048 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
49
Jesus Cead8b9ae62011-11-14 19:07:41 +010050 .. versionadded:: 3.3
51
Victor Stinnerdaf45552013-08-28 00:53:59 +020052 .. versionchanged:: 3.4
53 The new file descriptor is now non-inheritable.
54
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060055.. function:: epoll(sizehint=-1, flags=0)
Christian Heimes4fbc72b2008-03-22 00:47:35 +000056
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060057 (Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
58 which can be used as Edge or Level Triggered interface for I/O
59 events. *sizehint* is deprecated and completely ignored. *flags* can be set
60 to :const:`EPOLL_CLOEXEC`, which causes the epoll descriptor to be closed
61 automatically when :func:`os.execve` is called. See section
62 :ref:`epoll-objects` below for the methods supported by epolling objects.
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010063 They also support the :keyword:`with` statement.
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060064
Victor Stinnerdaf45552013-08-28 00:53:59 +020065 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
66
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060067 .. versionchanged:: 3.3
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060068 Added the *flags* parameter.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000069
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010070 .. versionchanged:: 3.4
71 Support for the :keyword:`with` statement was added.
Victor Stinnerdaf45552013-08-28 00:53:59 +020072 The new file descriptor is now non-inheritable.
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010073
Christian Heimes4fbc72b2008-03-22 00:47:35 +000074
Georg Brandl116aa622007-08-15 14:28:22 +000075.. function:: poll()
76
77 (Not supported by all operating systems.) Returns a polling object, which
78 supports registering and unregistering file descriptors, and then polling them
79 for I/O events; see section :ref:`poll-objects` below for the methods supported
80 by polling objects.
81
82
Christian Heimesfe337bf2008-03-23 21:54:12 +000083.. function:: kqueue()
Christian Heimes4fbc72b2008-03-22 00:47:35 +000084
Georg Brandle767e042010-07-14 08:00:22 +000085 (Only supported on BSD.) Returns a kernel queue object; see section
Christian Heimesfe337bf2008-03-23 21:54:12 +000086 :ref:`kqueue-objects` below for the methods supported by kqueue objects.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000087
Victor Stinnerdaf45552013-08-28 00:53:59 +020088 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
89
90 .. versionchanged:: 3.4
91 The new file descriptor is now non-inheritable.
92
Christian Heimes4fbc72b2008-03-22 00:47:35 +000093
Benjamin Peterson1baf4652009-12-31 03:11:23 +000094.. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)
Christian Heimes4fbc72b2008-03-22 00:47:35 +000095
Georg Brandle767e042010-07-14 08:00:22 +000096 (Only supported on BSD.) Returns a kernel event object; see section
97 :ref:`kevent-objects` below for the methods supported by kevent objects.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000098
Christian Heimes4fbc72b2008-03-22 00:47:35 +000099
Georg Brandl734e2682008-08-12 08:18:18 +0000100.. function:: select(rlist, wlist, xlist[, timeout])
Georg Brandl116aa622007-08-15 14:28:22 +0000101
Georg Brandl60203b42010-10-06 10:11:56 +0000102 This is a straightforward interface to the Unix :c:func:`select` system call.
Georg Brandl116aa622007-08-15 14:28:22 +0000103 The first three arguments are sequences of 'waitable objects': either
104 integers representing file descriptors or objects with a parameterless method
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300105 named :meth:`~io.IOBase.fileno` returning such an integer:
Georg Brandl734e2682008-08-12 08:18:18 +0000106
107 * *rlist*: wait until ready for reading
108 * *wlist*: wait until ready for writing
109 * *xlist*: wait for an "exceptional condition" (see the manual page for what
110 your system considers such a condition)
111
112 Empty sequences are allowed, but acceptance of three empty sequences is
113 platform-dependent. (It is known to work on Unix but not on Windows.) The
114 optional *timeout* argument specifies a time-out as a floating point number
115 in seconds. When the *timeout* argument is omitted the function blocks until
116 at least one file descriptor is ready. A time-out value of zero specifies a
117 poll and never blocks.
Georg Brandl116aa622007-08-15 14:28:22 +0000118
119 The return value is a triple of lists of objects that are ready: subsets of the
120 first three arguments. When the time-out is reached without a file descriptor
121 becoming ready, three empty lists are returned.
122
123 .. index::
124 single: socket() (in module socket)
125 single: popen() (in module os)
126
Antoine Pitrou11cb9612010-09-15 11:11:28 +0000127 Among the acceptable object types in the sequences are Python :term:`file
128 objects <file object>` (e.g. ``sys.stdin``, or objects returned by
129 :func:`open` or :func:`os.popen`), socket objects returned by
130 :func:`socket.socket`. You may also define a :dfn:`wrapper` class yourself,
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300131 as long as it has an appropriate :meth:`~io.IOBase.fileno` method (that
132 really returns a file descriptor, not just a random integer).
Georg Brandl116aa622007-08-15 14:28:22 +0000133
Georg Brandl116aa622007-08-15 14:28:22 +0000134 .. note::
135
136 .. index:: single: WinSock
137
Georg Brandl734e2682008-08-12 08:18:18 +0000138 File objects on Windows are not acceptable, but sockets are. On Windows,
Georg Brandl60203b42010-10-06 10:11:56 +0000139 the underlying :c:func:`select` function is provided by the WinSock
Georg Brandl734e2682008-08-12 08:18:18 +0000140 library, and does not handle file descriptors that don't originate from
141 WinSock.
Georg Brandl116aa622007-08-15 14:28:22 +0000142
Antoine Pitroucfad97b2011-01-25 17:24:57 +0000143.. attribute:: PIPE_BUF
Gregory P. Smithb970b862009-07-04 02:28:47 +0000144
Antoine Pitrouda7be3e2011-01-25 16:28:44 +0000145 The minimum number of bytes which can be written without blocking to a pipe
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300146 when the pipe has been reported as ready for writing by :func:`~select.select`,
Antoine Pitrouda7be3e2011-01-25 16:28:44 +0000147 :func:`poll` or another interface in this module. This doesn't apply
148 to other kind of file-like objects such as sockets.
149
Amaury Forgeot d'Arcace31022009-07-09 22:44:11 +0000150 This value is guaranteed by POSIX to be at least 512. Availability: Unix.
Gregory P. Smithb970b862009-07-04 02:28:47 +0000151
Mark Dickinson574b1d62009-10-01 20:20:09 +0000152 .. versionadded:: 3.2
Gregory P. Smithb970b862009-07-04 02:28:47 +0000153
Georg Brandl116aa622007-08-15 14:28:22 +0000154
Jesus Cead8b9ae62011-11-14 19:07:41 +0100155.. _devpoll-objects:
156
157``/dev/poll`` Polling Objects
158----------------------------------------------
159
160 http://developers.sun.com/solaris/articles/using_devpoll.html
161 http://developers.sun.com/solaris/articles/polling_efficient.html
162
163Solaris and derivatives have ``/dev/poll``. While :c:func:`select` is
164O(highest file descriptor) and :c:func:`poll` is O(number of file
165descriptors), ``/dev/poll`` is O(active file descriptors).
166
167``/dev/poll`` behaviour is very close to the standard :c:func:`poll`
168object.
169
170
Victor Stinner13423c32013-08-22 00:19:50 +0200171.. method:: devpoll.close()
172
173 Close the file descriptor of the polling object.
174
175 .. versionadded:: 3.4
176
177
178.. attribute:: devpoll.closed
179
180 ``True`` if the polling object is closed.
181
182 .. versionadded:: 3.4
183
184
185.. method:: devpoll.fileno()
186
187 Return the file descriptor number of the polling object.
188
189 .. versionadded:: 3.4
190
191
Jesus Cead8b9ae62011-11-14 19:07:41 +0100192.. method:: devpoll.register(fd[, eventmask])
193
194 Register a file descriptor with the polling object. Future calls to the
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300195 :meth:`poll` method will then check whether the file descriptor has any
196 pending I/O events. *fd* can be either an integer, or an object with a
197 :meth:`~io.IOBase.fileno` method that returns an integer. File objects
198 implement :meth:`!fileno`, so they can also be used as the argument.
Jesus Cead8b9ae62011-11-14 19:07:41 +0100199
200 *eventmask* is an optional bitmask describing the type of events you want to
201 check for. The constants are the same that with :c:func:`poll`
202 object. The default value is a combination of the constants :const:`POLLIN`,
203 :const:`POLLPRI`, and :const:`POLLOUT`.
204
205 .. warning::
206
207 Registering a file descriptor that's already registered is not an
208 error, but the result is undefined. The appropiate action is to
209 unregister or modify it first. This is an important difference
210 compared with :c:func:`poll`.
211
212
213.. method:: devpoll.modify(fd[, eventmask])
214
215 This method does an :meth:`unregister` followed by a
216 :meth:`register`. It is (a bit) more efficient that doing the same
217 explicitly.
218
219
220.. method:: devpoll.unregister(fd)
221
222 Remove a file descriptor being tracked by a polling object. Just like the
223 :meth:`register` method, *fd* can be an integer or an object with a
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300224 :meth:`~io.IOBase.fileno` method that returns an integer.
Jesus Cead8b9ae62011-11-14 19:07:41 +0100225
226 Attempting to remove a file descriptor that was never registered is
227 safely ignored.
228
229
230.. method:: devpoll.poll([timeout])
231
232 Polls the set of registered file descriptors, and returns a possibly-empty list
233 containing ``(fd, event)`` 2-tuples for the descriptors that have events or
234 errors to report. *fd* is the file descriptor, and *event* is a bitmask with
235 bits set for the reported events for that descriptor --- :const:`POLLIN` for
236 waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
237 to, and so forth. An empty list indicates that the call timed out and no file
238 descriptors had any events to report. If *timeout* is given, it specifies the
239 length of time in milliseconds which the system will wait for events before
240 returning. If *timeout* is omitted, -1, or :const:`None`, the call will
241 block until there is an event for this poll object.
242
243
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000244.. _epoll-objects:
245
246Edge and Level Trigger Polling (epoll) Objects
247----------------------------------------------
248
249 http://linux.die.net/man/4/epoll
250
251 *eventmask*
252
253 +-----------------------+-----------------------------------------------+
254 | Constant | Meaning |
255 +=======================+===============================================+
256 | :const:`EPOLLIN` | Available for read |
257 +-----------------------+-----------------------------------------------+
258 | :const:`EPOLLOUT` | Available for write |
259 +-----------------------+-----------------------------------------------+
260 | :const:`EPOLLPRI` | Urgent data for read |
261 +-----------------------+-----------------------------------------------+
Christian Heimes5e696852008-04-09 08:37:03 +0000262 | :const:`EPOLLERR` | Error condition happened on the assoc. fd |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000263 +-----------------------+-----------------------------------------------+
Christian Heimes5e696852008-04-09 08:37:03 +0000264 | :const:`EPOLLHUP` | Hang up happened on the assoc. fd |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000265 +-----------------------+-----------------------------------------------+
266 | :const:`EPOLLET` | Set Edge Trigger behavior, the default is |
267 | | Level Trigger behavior |
268 +-----------------------+-----------------------------------------------+
269 | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is |
270 | | pulled out, the fd is internally disabled |
271 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000272 | :const:`EPOLLRDNORM` | Equivalent to :const:`EPOLLIN` |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000273 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000274 | :const:`EPOLLRDBAND` | Priority data band can be read. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000275 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000276 | :const:`EPOLLWRNORM` | Equivalent to :const:`EPOLLOUT` |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000277 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000278 | :const:`EPOLLWRBAND` | Priority data may be written. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000279 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000280 | :const:`EPOLLMSG` | Ignored. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000281 +-----------------------+-----------------------------------------------+
282
283
284.. method:: epoll.close()
285
286 Close the control file descriptor of the epoll object.
287
288
Victor Stinner13423c32013-08-22 00:19:50 +0200289.. attribute:: epoll.closed
290
291 ``True`` if the epoll object is closed.
292
293
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000294.. method:: epoll.fileno()
295
296 Return the file descriptor number of the control fd.
297
298
299.. method:: epoll.fromfd(fd)
300
301 Create an epoll object from a given file descriptor.
302
303
304.. method:: epoll.register(fd[, eventmask])
305
306 Register a fd descriptor with the epoll object.
307
308
309.. method:: epoll.modify(fd, eventmask)
310
311 Modify a register file descriptor.
312
313
314.. method:: epoll.unregister(fd)
315
316 Remove a registered file descriptor from the epoll object.
317
318
Hynek Schlawackdfa46522012-05-21 11:01:54 +0200319.. method:: epoll.poll(timeout=-1, maxevents=-1)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000320
321 Wait for events. timeout in seconds (float)
322
323
Georg Brandl116aa622007-08-15 14:28:22 +0000324.. _poll-objects:
325
326Polling Objects
327---------------
328
Georg Brandl60203b42010-10-06 10:11:56 +0000329The :c:func:`poll` system call, supported on most Unix systems, provides better
Georg Brandl116aa622007-08-15 14:28:22 +0000330scalability for network servers that service many, many clients at the same
Georg Brandl60203b42010-10-06 10:11:56 +0000331time. :c:func:`poll` scales better because the system call only requires listing
332the file descriptors of interest, while :c:func:`select` builds a bitmap, turns
Georg Brandl116aa622007-08-15 14:28:22 +0000333on bits for the fds of interest, and then afterward the whole bitmap has to be
Georg Brandl60203b42010-10-06 10:11:56 +0000334linearly scanned again. :c:func:`select` is O(highest file descriptor), while
335:c:func:`poll` is O(number of file descriptors).
Georg Brandl116aa622007-08-15 14:28:22 +0000336
337
338.. method:: poll.register(fd[, eventmask])
339
340 Register a file descriptor with the polling object. Future calls to the
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300341 :meth:`poll` method will then check whether the file descriptor has any
342 pending I/O events. *fd* can be either an integer, or an object with a
343 :meth:`~io.IOBase.fileno` method that returns an integer. File objects
344 implement :meth:`!fileno`, so they can also be used as the argument.
Georg Brandl116aa622007-08-15 14:28:22 +0000345
346 *eventmask* is an optional bitmask describing the type of events you want to
347 check for, and can be a combination of the constants :const:`POLLIN`,
348 :const:`POLLPRI`, and :const:`POLLOUT`, described in the table below. If not
349 specified, the default value used will check for all 3 types of events.
350
351 +-------------------+------------------------------------------+
352 | Constant | Meaning |
353 +===================+==========================================+
354 | :const:`POLLIN` | There is data to read |
355 +-------------------+------------------------------------------+
356 | :const:`POLLPRI` | There is urgent data to read |
357 +-------------------+------------------------------------------+
358 | :const:`POLLOUT` | Ready for output: writing will not block |
359 +-------------------+------------------------------------------+
360 | :const:`POLLERR` | Error condition of some sort |
361 +-------------------+------------------------------------------+
362 | :const:`POLLHUP` | Hung up |
363 +-------------------+------------------------------------------+
364 | :const:`POLLNVAL` | Invalid request: descriptor not open |
365 +-------------------+------------------------------------------+
366
367 Registering a file descriptor that's already registered is not an error, and has
368 the same effect as registering the descriptor exactly once.
369
370
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000371.. method:: poll.modify(fd, eventmask)
372
373 Modifies an already registered fd. This has the same effect as
Jean-Paul Calderone7f94f392010-07-18 16:13:27 +0000374 ``register(fd, eventmask)``. Attempting to modify a file descriptor
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000375 that was never registered causes an :exc:`IOError` exception with errno
376 :const:`ENOENT` to be raised.
377
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000378
Georg Brandl116aa622007-08-15 14:28:22 +0000379.. method:: poll.unregister(fd)
380
381 Remove a file descriptor being tracked by a polling object. Just like the
382 :meth:`register` method, *fd* can be an integer or an object with a
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300383 :meth:`~io.IOBase.fileno` method that returns an integer.
Georg Brandl116aa622007-08-15 14:28:22 +0000384
385 Attempting to remove a file descriptor that was never registered causes a
386 :exc:`KeyError` exception to be raised.
387
388
389.. method:: poll.poll([timeout])
390
391 Polls the set of registered file descriptors, and returns a possibly-empty list
392 containing ``(fd, event)`` 2-tuples for the descriptors that have events or
393 errors to report. *fd* is the file descriptor, and *event* is a bitmask with
394 bits set for the reported events for that descriptor --- :const:`POLLIN` for
395 waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
396 to, and so forth. An empty list indicates that the call timed out and no file
397 descriptors had any events to report. If *timeout* is given, it specifies the
398 length of time in milliseconds which the system will wait for events before
399 returning. If *timeout* is omitted, negative, or :const:`None`, the call will
400 block until there is an event for this poll object.
401
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000402
403.. _kqueue-objects:
404
405Kqueue Objects
406--------------
407
408.. method:: kqueue.close()
409
410 Close the control file descriptor of the kqueue object.
411
412
Victor Stinner13423c32013-08-22 00:19:50 +0200413.. attribute:: kqueue.closed
414
415 ``True`` if the kqueue object is closed.
416
417
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000418.. method:: kqueue.fileno()
419
420 Return the file descriptor number of the control fd.
421
422
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000423.. method:: kqueue.fromfd(fd)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000424
425 Create a kqueue object from a given file descriptor.
426
427
Hynek Schlawack979f37a2012-05-22 16:12:18 +0200428.. method:: kqueue.control(changelist, max_events[, timeout=None]) -> eventlist
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000429
430 Low level interface to kevent
431
432 - changelist must be an iterable of kevent object or None
433 - max_events must be 0 or a positive integer
434 - timeout in seconds (floats possible)
435
436
437.. _kevent-objects:
438
439Kevent Objects
440--------------
441
Christian Heimesfe337bf2008-03-23 21:54:12 +0000442http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000443
Christian Heimesfe337bf2008-03-23 21:54:12 +0000444.. attribute:: kevent.ident
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000445
446 Value used to identify the event. The interpretation depends on the filter
447 but it's usually the file descriptor. In the constructor ident can either
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300448 be an int or an object with a :meth:`~io.IOBase.fileno` method. kevent
449 stores the integer internally.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000450
Christian Heimesfe337bf2008-03-23 21:54:12 +0000451.. attribute:: kevent.filter
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000452
Georg Brandl1b5ab452009-08-13 07:56:35 +0000453 Name of the kernel filter.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000454
455 +---------------------------+---------------------------------------------+
456 | Constant | Meaning |
457 +===========================+=============================================+
458 | :const:`KQ_FILTER_READ` | Takes a descriptor and returns whenever |
459 | | there is data available to read |
460 +---------------------------+---------------------------------------------+
461 | :const:`KQ_FILTER_WRITE` | Takes a descriptor and returns whenever |
Georg Brandl1b5ab452009-08-13 07:56:35 +0000462 | | there is data available to write |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000463 +---------------------------+---------------------------------------------+
464 | :const:`KQ_FILTER_AIO` | AIO requests |
465 +---------------------------+---------------------------------------------+
466 | :const:`KQ_FILTER_VNODE` | Returns when one or more of the requested |
467 | | events watched in *fflag* occurs |
468 +---------------------------+---------------------------------------------+
469 | :const:`KQ_FILTER_PROC` | Watch for events on a process id |
470 +---------------------------+---------------------------------------------+
471 | :const:`KQ_FILTER_NETDEV` | Watch for events on a network device |
472 | | [not available on Mac OS X] |
473 +---------------------------+---------------------------------------------+
474 | :const:`KQ_FILTER_SIGNAL` | Returns whenever the watched signal is |
475 | | delivered to the process |
476 +---------------------------+---------------------------------------------+
477 | :const:`KQ_FILTER_TIMER` | Establishes an arbitrary timer |
478 +---------------------------+---------------------------------------------+
479
Christian Heimesfe337bf2008-03-23 21:54:12 +0000480.. attribute:: kevent.flags
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000481
Georg Brandl1b5ab452009-08-13 07:56:35 +0000482 Filter action.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000483
484 +---------------------------+---------------------------------------------+
485 | Constant | Meaning |
486 +===========================+=============================================+
487 | :const:`KQ_EV_ADD` | Adds or modifies an event |
488 +---------------------------+---------------------------------------------+
489 | :const:`KQ_EV_DELETE` | Removes an event from the queue |
490 +---------------------------+---------------------------------------------+
491 | :const:`KQ_EV_ENABLE` | Permitscontrol() to returns the event |
492 +---------------------------+---------------------------------------------+
493 | :const:`KQ_EV_DISABLE` | Disablesevent |
494 +---------------------------+---------------------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000495 | :const:`KQ_EV_ONESHOT` | Removes event after first occurrence |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000496 +---------------------------+---------------------------------------------+
497 | :const:`KQ_EV_CLEAR` | Reset the state after an event is retrieved |
498 +---------------------------+---------------------------------------------+
499 | :const:`KQ_EV_SYSFLAGS` | internal event |
500 +---------------------------+---------------------------------------------+
501 | :const:`KQ_EV_FLAG1` | internal event |
502 +---------------------------+---------------------------------------------+
503 | :const:`KQ_EV_EOF` | Filter specific EOF condition |
504 +---------------------------+---------------------------------------------+
505 | :const:`KQ_EV_ERROR` | See return values |
506 +---------------------------+---------------------------------------------+
507
508
Christian Heimesfe337bf2008-03-23 21:54:12 +0000509.. attribute:: kevent.fflags
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000510
Georg Brandl1b5ab452009-08-13 07:56:35 +0000511 Filter specific flags.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000512
Georg Brandl1b5ab452009-08-13 07:56:35 +0000513 :const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000514
515 +----------------------------+--------------------------------------------+
516 | Constant | Meaning |
517 +============================+============================================+
518 | :const:`KQ_NOTE_LOWAT` | low water mark of a socket buffer |
519 +----------------------------+--------------------------------------------+
520
Georg Brandl1b5ab452009-08-13 07:56:35 +0000521 :const:`KQ_FILTER_VNODE` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000522
523 +----------------------------+--------------------------------------------+
524 | Constant | Meaning |
525 +============================+============================================+
526 | :const:`KQ_NOTE_DELETE` | *unlink()* was called |
527 +----------------------------+--------------------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000528 | :const:`KQ_NOTE_WRITE` | a write occurred |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000529 +----------------------------+--------------------------------------------+
530 | :const:`KQ_NOTE_EXTEND` | the file was extended |
531 +----------------------------+--------------------------------------------+
532 | :const:`KQ_NOTE_ATTRIB` | an attribute was changed |
533 +----------------------------+--------------------------------------------+
534 | :const:`KQ_NOTE_LINK` | the link count has changed |
535 +----------------------------+--------------------------------------------+
536 | :const:`KQ_NOTE_RENAME` | the file was renamed |
537 +----------------------------+--------------------------------------------+
538 | :const:`KQ_NOTE_REVOKE` | access to the file was revoked |
539 +----------------------------+--------------------------------------------+
540
Georg Brandl1b5ab452009-08-13 07:56:35 +0000541 :const:`KQ_FILTER_PROC` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000542
543 +----------------------------+--------------------------------------------+
544 | Constant | Meaning |
545 +============================+============================================+
546 | :const:`KQ_NOTE_EXIT` | the process has exited |
547 +----------------------------+--------------------------------------------+
548 | :const:`KQ_NOTE_FORK` | the process has called *fork()* |
549 +----------------------------+--------------------------------------------+
550 | :const:`KQ_NOTE_EXEC` | the process has executed a new process |
551 +----------------------------+--------------------------------------------+
552 | :const:`KQ_NOTE_PCTRLMASK` | internal filter flag |
553 +----------------------------+--------------------------------------------+
554 | :const:`KQ_NOTE_PDATAMASK` | internal filter flag |
555 +----------------------------+--------------------------------------------+
556 | :const:`KQ_NOTE_TRACK` | follow a process across *fork()* |
557 +----------------------------+--------------------------------------------+
558 | :const:`KQ_NOTE_CHILD` | returned on the child process for |
559 | | *NOTE_TRACK* |
560 +----------------------------+--------------------------------------------+
561 | :const:`KQ_NOTE_TRACKERR` | unable to attach to a child |
562 +----------------------------+--------------------------------------------+
563
Georg Brandl1b5ab452009-08-13 07:56:35 +0000564 :const:`KQ_FILTER_NETDEV` filter flags (not available on Mac OS X):
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000565
566 +----------------------------+--------------------------------------------+
567 | Constant | Meaning |
568 +============================+============================================+
569 | :const:`KQ_NOTE_LINKUP` | link is up |
570 +----------------------------+--------------------------------------------+
571 | :const:`KQ_NOTE_LINKDOWN` | link is down |
572 +----------------------------+--------------------------------------------+
573 | :const:`KQ_NOTE_LINKINV` | link state is invalid |
574 +----------------------------+--------------------------------------------+
575
576
Christian Heimesfe337bf2008-03-23 21:54:12 +0000577.. attribute:: kevent.data
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000578
Georg Brandl1b5ab452009-08-13 07:56:35 +0000579 Filter specific data.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000580
581
Christian Heimesfe337bf2008-03-23 21:54:12 +0000582.. attribute:: kevent.udata
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000583
Georg Brandl1b5ab452009-08-13 07:56:35 +0000584 User defined value.