blob: b73f11e227604c7c3217d51eeef1f2ca6df44c57 [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
40 .. versionadded:: 3.3
41
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060042.. function:: epoll(sizehint=-1, flags=0)
Christian Heimes4fbc72b2008-03-22 00:47:35 +000043
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060044 (Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
45 which can be used as Edge or Level Triggered interface for I/O
46 events. *sizehint* is deprecated and completely ignored. *flags* can be set
47 to :const:`EPOLL_CLOEXEC`, which causes the epoll descriptor to be closed
48 automatically when :func:`os.execve` is called. See section
49 :ref:`epoll-objects` below for the methods supported by epolling objects.
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010050 They also support the :keyword:`with` statement.
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060051
52 .. versionchanged:: 3.3
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060053 Added the *flags* parameter.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000054
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010055 .. versionchanged:: 3.4
56 Support for the :keyword:`with` statement was added.
57
Christian Heimes4fbc72b2008-03-22 00:47:35 +000058
Georg Brandl116aa622007-08-15 14:28:22 +000059.. function:: poll()
60
61 (Not supported by all operating systems.) Returns a polling object, which
62 supports registering and unregistering file descriptors, and then polling them
63 for I/O events; see section :ref:`poll-objects` below for the methods supported
64 by polling objects.
65
66
Christian Heimesfe337bf2008-03-23 21:54:12 +000067.. function:: kqueue()
Christian Heimes4fbc72b2008-03-22 00:47:35 +000068
Georg Brandle767e042010-07-14 08:00:22 +000069 (Only supported on BSD.) Returns a kernel queue object; see section
Christian Heimesfe337bf2008-03-23 21:54:12 +000070 :ref:`kqueue-objects` below for the methods supported by kqueue objects.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000071
Christian Heimes4fbc72b2008-03-22 00:47:35 +000072
Benjamin Peterson1baf4652009-12-31 03:11:23 +000073.. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)
Christian Heimes4fbc72b2008-03-22 00:47:35 +000074
Georg Brandle767e042010-07-14 08:00:22 +000075 (Only supported on BSD.) Returns a kernel event object; see section
76 :ref:`kevent-objects` below for the methods supported by kevent objects.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000077
Christian Heimes4fbc72b2008-03-22 00:47:35 +000078
Georg Brandl734e2682008-08-12 08:18:18 +000079.. function:: select(rlist, wlist, xlist[, timeout])
Georg Brandl116aa622007-08-15 14:28:22 +000080
Georg Brandl60203b42010-10-06 10:11:56 +000081 This is a straightforward interface to the Unix :c:func:`select` system call.
Georg Brandl116aa622007-08-15 14:28:22 +000082 The first three arguments are sequences of 'waitable objects': either
83 integers representing file descriptors or objects with a parameterless method
Georg Brandl734e2682008-08-12 08:18:18 +000084 named :meth:`fileno` returning such an integer:
85
86 * *rlist*: wait until ready for reading
87 * *wlist*: wait until ready for writing
88 * *xlist*: wait for an "exceptional condition" (see the manual page for what
89 your system considers such a condition)
90
91 Empty sequences are allowed, but acceptance of three empty sequences is
92 platform-dependent. (It is known to work on Unix but not on Windows.) The
93 optional *timeout* argument specifies a time-out as a floating point number
94 in seconds. When the *timeout* argument is omitted the function blocks until
95 at least one file descriptor is ready. A time-out value of zero specifies a
96 poll and never blocks.
Georg Brandl116aa622007-08-15 14:28:22 +000097
98 The return value is a triple of lists of objects that are ready: subsets of the
99 first three arguments. When the time-out is reached without a file descriptor
100 becoming ready, three empty lists are returned.
101
102 .. index::
103 single: socket() (in module socket)
104 single: popen() (in module os)
105
Antoine Pitrou11cb9612010-09-15 11:11:28 +0000106 Among the acceptable object types in the sequences are Python :term:`file
107 objects <file object>` (e.g. ``sys.stdin``, or objects returned by
108 :func:`open` or :func:`os.popen`), socket objects returned by
109 :func:`socket.socket`. You may also define a :dfn:`wrapper` class yourself,
110 as long as it has an appropriate :meth:`fileno` method (that really returns
111 a file descriptor, not just a random integer).
Georg Brandl116aa622007-08-15 14:28:22 +0000112
Georg Brandl116aa622007-08-15 14:28:22 +0000113 .. note::
114
115 .. index:: single: WinSock
116
Georg Brandl734e2682008-08-12 08:18:18 +0000117 File objects on Windows are not acceptable, but sockets are. On Windows,
Georg Brandl60203b42010-10-06 10:11:56 +0000118 the underlying :c:func:`select` function is provided by the WinSock
Georg Brandl734e2682008-08-12 08:18:18 +0000119 library, and does not handle file descriptors that don't originate from
120 WinSock.
Georg Brandl116aa622007-08-15 14:28:22 +0000121
Antoine Pitroucfad97b2011-01-25 17:24:57 +0000122.. attribute:: PIPE_BUF
Gregory P. Smithb970b862009-07-04 02:28:47 +0000123
Antoine Pitrouda7be3e2011-01-25 16:28:44 +0000124 The minimum number of bytes which can be written without blocking to a pipe
125 when the pipe has been reported as ready for writing by :func:`select`,
126 :func:`poll` or another interface in this module. This doesn't apply
127 to other kind of file-like objects such as sockets.
128
Amaury Forgeot d'Arcace31022009-07-09 22:44:11 +0000129 This value is guaranteed by POSIX to be at least 512. Availability: Unix.
Gregory P. Smithb970b862009-07-04 02:28:47 +0000130
Mark Dickinson574b1d62009-10-01 20:20:09 +0000131 .. versionadded:: 3.2
Gregory P. Smithb970b862009-07-04 02:28:47 +0000132
Georg Brandl116aa622007-08-15 14:28:22 +0000133
Jesus Cead8b9ae62011-11-14 19:07:41 +0100134.. _devpoll-objects:
135
136``/dev/poll`` Polling Objects
137----------------------------------------------
138
139 http://developers.sun.com/solaris/articles/using_devpoll.html
140 http://developers.sun.com/solaris/articles/polling_efficient.html
141
142Solaris and derivatives have ``/dev/poll``. While :c:func:`select` is
143O(highest file descriptor) and :c:func:`poll` is O(number of file
144descriptors), ``/dev/poll`` is O(active file descriptors).
145
146``/dev/poll`` behaviour is very close to the standard :c:func:`poll`
147object.
148
149
150.. method:: devpoll.register(fd[, eventmask])
151
152 Register a file descriptor with the polling object. Future calls to the
153 :meth:`poll` method will then check whether the file descriptor has any pending
154 I/O events. *fd* can be either an integer, or an object with a :meth:`fileno`
155 method that returns an integer. File objects implement :meth:`fileno`, so they
156 can also be used as the argument.
157
158 *eventmask* is an optional bitmask describing the type of events you want to
159 check for. The constants are the same that with :c:func:`poll`
160 object. The default value is a combination of the constants :const:`POLLIN`,
161 :const:`POLLPRI`, and :const:`POLLOUT`.
162
163 .. warning::
164
165 Registering a file descriptor that's already registered is not an
166 error, but the result is undefined. The appropiate action is to
167 unregister or modify it first. This is an important difference
168 compared with :c:func:`poll`.
169
170
171.. method:: devpoll.modify(fd[, eventmask])
172
173 This method does an :meth:`unregister` followed by a
174 :meth:`register`. It is (a bit) more efficient that doing the same
175 explicitly.
176
177
178.. method:: devpoll.unregister(fd)
179
180 Remove a file descriptor being tracked by a polling object. Just like the
181 :meth:`register` method, *fd* can be an integer or an object with a
182 :meth:`fileno` method that returns an integer.
183
184 Attempting to remove a file descriptor that was never registered is
185 safely ignored.
186
187
188.. method:: devpoll.poll([timeout])
189
190 Polls the set of registered file descriptors, and returns a possibly-empty list
191 containing ``(fd, event)`` 2-tuples for the descriptors that have events or
192 errors to report. *fd* is the file descriptor, and *event* is a bitmask with
193 bits set for the reported events for that descriptor --- :const:`POLLIN` for
194 waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
195 to, and so forth. An empty list indicates that the call timed out and no file
196 descriptors had any events to report. If *timeout* is given, it specifies the
197 length of time in milliseconds which the system will wait for events before
198 returning. If *timeout* is omitted, -1, or :const:`None`, the call will
199 block until there is an event for this poll object.
200
201
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000202.. _epoll-objects:
203
204Edge and Level Trigger Polling (epoll) Objects
205----------------------------------------------
206
207 http://linux.die.net/man/4/epoll
208
209 *eventmask*
210
211 +-----------------------+-----------------------------------------------+
212 | Constant | Meaning |
213 +=======================+===============================================+
214 | :const:`EPOLLIN` | Available for read |
215 +-----------------------+-----------------------------------------------+
216 | :const:`EPOLLOUT` | Available for write |
217 +-----------------------+-----------------------------------------------+
218 | :const:`EPOLLPRI` | Urgent data for read |
219 +-----------------------+-----------------------------------------------+
Christian Heimes5e696852008-04-09 08:37:03 +0000220 | :const:`EPOLLERR` | Error condition happened on the assoc. fd |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000221 +-----------------------+-----------------------------------------------+
Christian Heimes5e696852008-04-09 08:37:03 +0000222 | :const:`EPOLLHUP` | Hang up happened on the assoc. fd |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000223 +-----------------------+-----------------------------------------------+
224 | :const:`EPOLLET` | Set Edge Trigger behavior, the default is |
225 | | Level Trigger behavior |
226 +-----------------------+-----------------------------------------------+
227 | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is |
228 | | pulled out, the fd is internally disabled |
229 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000230 | :const:`EPOLLRDNORM` | Equivalent to :const:`EPOLLIN` |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000231 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000232 | :const:`EPOLLRDBAND` | Priority data band can be read. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000233 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000234 | :const:`EPOLLWRNORM` | Equivalent to :const:`EPOLLOUT` |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000235 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000236 | :const:`EPOLLWRBAND` | Priority data may be written. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000237 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000238 | :const:`EPOLLMSG` | Ignored. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000239 +-----------------------+-----------------------------------------------+
240
241
242.. method:: epoll.close()
243
244 Close the control file descriptor of the epoll object.
245
246
247.. method:: epoll.fileno()
248
249 Return the file descriptor number of the control fd.
250
251
252.. method:: epoll.fromfd(fd)
253
254 Create an epoll object from a given file descriptor.
255
256
257.. method:: epoll.register(fd[, eventmask])
258
259 Register a fd descriptor with the epoll object.
260
261
262.. method:: epoll.modify(fd, eventmask)
263
264 Modify a register file descriptor.
265
266
267.. method:: epoll.unregister(fd)
268
269 Remove a registered file descriptor from the epoll object.
270
271
Hynek Schlawackdfa46522012-05-21 11:01:54 +0200272.. method:: epoll.poll(timeout=-1, maxevents=-1)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000273
274 Wait for events. timeout in seconds (float)
275
276
Georg Brandl116aa622007-08-15 14:28:22 +0000277.. _poll-objects:
278
279Polling Objects
280---------------
281
Georg Brandl60203b42010-10-06 10:11:56 +0000282The :c:func:`poll` system call, supported on most Unix systems, provides better
Georg Brandl116aa622007-08-15 14:28:22 +0000283scalability for network servers that service many, many clients at the same
Georg Brandl60203b42010-10-06 10:11:56 +0000284time. :c:func:`poll` scales better because the system call only requires listing
285the file descriptors of interest, while :c:func:`select` builds a bitmap, turns
Georg Brandl116aa622007-08-15 14:28:22 +0000286on bits for the fds of interest, and then afterward the whole bitmap has to be
Georg Brandl60203b42010-10-06 10:11:56 +0000287linearly scanned again. :c:func:`select` is O(highest file descriptor), while
288:c:func:`poll` is O(number of file descriptors).
Georg Brandl116aa622007-08-15 14:28:22 +0000289
290
291.. method:: poll.register(fd[, eventmask])
292
293 Register a file descriptor with the polling object. Future calls to the
294 :meth:`poll` method will then check whether the file descriptor has any pending
295 I/O events. *fd* can be either an integer, or an object with a :meth:`fileno`
296 method that returns an integer. File objects implement :meth:`fileno`, so they
297 can also be used as the argument.
298
299 *eventmask* is an optional bitmask describing the type of events you want to
300 check for, and can be a combination of the constants :const:`POLLIN`,
301 :const:`POLLPRI`, and :const:`POLLOUT`, described in the table below. If not
302 specified, the default value used will check for all 3 types of events.
303
304 +-------------------+------------------------------------------+
305 | Constant | Meaning |
306 +===================+==========================================+
307 | :const:`POLLIN` | There is data to read |
308 +-------------------+------------------------------------------+
309 | :const:`POLLPRI` | There is urgent data to read |
310 +-------------------+------------------------------------------+
311 | :const:`POLLOUT` | Ready for output: writing will not block |
312 +-------------------+------------------------------------------+
313 | :const:`POLLERR` | Error condition of some sort |
314 +-------------------+------------------------------------------+
315 | :const:`POLLHUP` | Hung up |
316 +-------------------+------------------------------------------+
317 | :const:`POLLNVAL` | Invalid request: descriptor not open |
318 +-------------------+------------------------------------------+
319
320 Registering a file descriptor that's already registered is not an error, and has
321 the same effect as registering the descriptor exactly once.
322
323
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000324.. method:: poll.modify(fd, eventmask)
325
326 Modifies an already registered fd. This has the same effect as
Jean-Paul Calderone7f94f392010-07-18 16:13:27 +0000327 ``register(fd, eventmask)``. Attempting to modify a file descriptor
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000328 that was never registered causes an :exc:`IOError` exception with errno
329 :const:`ENOENT` to be raised.
330
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000331
Georg Brandl116aa622007-08-15 14:28:22 +0000332.. method:: poll.unregister(fd)
333
334 Remove a file descriptor being tracked by a polling object. Just like the
335 :meth:`register` method, *fd* can be an integer or an object with a
336 :meth:`fileno` method that returns an integer.
337
338 Attempting to remove a file descriptor that was never registered causes a
339 :exc:`KeyError` exception to be raised.
340
341
342.. method:: poll.poll([timeout])
343
344 Polls the set of registered file descriptors, and returns a possibly-empty list
345 containing ``(fd, event)`` 2-tuples for the descriptors that have events or
346 errors to report. *fd* is the file descriptor, and *event* is a bitmask with
347 bits set for the reported events for that descriptor --- :const:`POLLIN` for
348 waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
349 to, and so forth. An empty list indicates that the call timed out and no file
350 descriptors had any events to report. If *timeout* is given, it specifies the
351 length of time in milliseconds which the system will wait for events before
352 returning. If *timeout* is omitted, negative, or :const:`None`, the call will
353 block until there is an event for this poll object.
354
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000355
356.. _kqueue-objects:
357
358Kqueue Objects
359--------------
360
361.. method:: kqueue.close()
362
363 Close the control file descriptor of the kqueue object.
364
365
366.. method:: kqueue.fileno()
367
368 Return the file descriptor number of the control fd.
369
370
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000371.. method:: kqueue.fromfd(fd)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000372
373 Create a kqueue object from a given file descriptor.
374
375
Hynek Schlawack979f37a2012-05-22 16:12:18 +0200376.. method:: kqueue.control(changelist, max_events[, timeout=None]) -> eventlist
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000377
378 Low level interface to kevent
379
380 - changelist must be an iterable of kevent object or None
381 - max_events must be 0 or a positive integer
382 - timeout in seconds (floats possible)
383
384
385.. _kevent-objects:
386
387Kevent Objects
388--------------
389
Christian Heimesfe337bf2008-03-23 21:54:12 +0000390http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000391
Christian Heimesfe337bf2008-03-23 21:54:12 +0000392.. attribute:: kevent.ident
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000393
394 Value used to identify the event. The interpretation depends on the filter
395 but it's usually the file descriptor. In the constructor ident can either
396 be an int or an object with a fileno() function. kevent stores the integer
397 internally.
398
Christian Heimesfe337bf2008-03-23 21:54:12 +0000399.. attribute:: kevent.filter
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000400
Georg Brandl1b5ab452009-08-13 07:56:35 +0000401 Name of the kernel filter.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000402
403 +---------------------------+---------------------------------------------+
404 | Constant | Meaning |
405 +===========================+=============================================+
406 | :const:`KQ_FILTER_READ` | Takes a descriptor and returns whenever |
407 | | there is data available to read |
408 +---------------------------+---------------------------------------------+
409 | :const:`KQ_FILTER_WRITE` | Takes a descriptor and returns whenever |
Georg Brandl1b5ab452009-08-13 07:56:35 +0000410 | | there is data available to write |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000411 +---------------------------+---------------------------------------------+
412 | :const:`KQ_FILTER_AIO` | AIO requests |
413 +---------------------------+---------------------------------------------+
414 | :const:`KQ_FILTER_VNODE` | Returns when one or more of the requested |
415 | | events watched in *fflag* occurs |
416 +---------------------------+---------------------------------------------+
417 | :const:`KQ_FILTER_PROC` | Watch for events on a process id |
418 +---------------------------+---------------------------------------------+
419 | :const:`KQ_FILTER_NETDEV` | Watch for events on a network device |
420 | | [not available on Mac OS X] |
421 +---------------------------+---------------------------------------------+
422 | :const:`KQ_FILTER_SIGNAL` | Returns whenever the watched signal is |
423 | | delivered to the process |
424 +---------------------------+---------------------------------------------+
425 | :const:`KQ_FILTER_TIMER` | Establishes an arbitrary timer |
426 +---------------------------+---------------------------------------------+
427
Christian Heimesfe337bf2008-03-23 21:54:12 +0000428.. attribute:: kevent.flags
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000429
Georg Brandl1b5ab452009-08-13 07:56:35 +0000430 Filter action.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000431
432 +---------------------------+---------------------------------------------+
433 | Constant | Meaning |
434 +===========================+=============================================+
435 | :const:`KQ_EV_ADD` | Adds or modifies an event |
436 +---------------------------+---------------------------------------------+
437 | :const:`KQ_EV_DELETE` | Removes an event from the queue |
438 +---------------------------+---------------------------------------------+
439 | :const:`KQ_EV_ENABLE` | Permitscontrol() to returns the event |
440 +---------------------------+---------------------------------------------+
441 | :const:`KQ_EV_DISABLE` | Disablesevent |
442 +---------------------------+---------------------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000443 | :const:`KQ_EV_ONESHOT` | Removes event after first occurrence |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000444 +---------------------------+---------------------------------------------+
445 | :const:`KQ_EV_CLEAR` | Reset the state after an event is retrieved |
446 +---------------------------+---------------------------------------------+
447 | :const:`KQ_EV_SYSFLAGS` | internal event |
448 +---------------------------+---------------------------------------------+
449 | :const:`KQ_EV_FLAG1` | internal event |
450 +---------------------------+---------------------------------------------+
451 | :const:`KQ_EV_EOF` | Filter specific EOF condition |
452 +---------------------------+---------------------------------------------+
453 | :const:`KQ_EV_ERROR` | See return values |
454 +---------------------------+---------------------------------------------+
455
456
Christian Heimesfe337bf2008-03-23 21:54:12 +0000457.. attribute:: kevent.fflags
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000458
Georg Brandl1b5ab452009-08-13 07:56:35 +0000459 Filter specific flags.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000460
Georg Brandl1b5ab452009-08-13 07:56:35 +0000461 :const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000462
463 +----------------------------+--------------------------------------------+
464 | Constant | Meaning |
465 +============================+============================================+
466 | :const:`KQ_NOTE_LOWAT` | low water mark of a socket buffer |
467 +----------------------------+--------------------------------------------+
468
Georg Brandl1b5ab452009-08-13 07:56:35 +0000469 :const:`KQ_FILTER_VNODE` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000470
471 +----------------------------+--------------------------------------------+
472 | Constant | Meaning |
473 +============================+============================================+
474 | :const:`KQ_NOTE_DELETE` | *unlink()* was called |
475 +----------------------------+--------------------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000476 | :const:`KQ_NOTE_WRITE` | a write occurred |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000477 +----------------------------+--------------------------------------------+
478 | :const:`KQ_NOTE_EXTEND` | the file was extended |
479 +----------------------------+--------------------------------------------+
480 | :const:`KQ_NOTE_ATTRIB` | an attribute was changed |
481 +----------------------------+--------------------------------------------+
482 | :const:`KQ_NOTE_LINK` | the link count has changed |
483 +----------------------------+--------------------------------------------+
484 | :const:`KQ_NOTE_RENAME` | the file was renamed |
485 +----------------------------+--------------------------------------------+
486 | :const:`KQ_NOTE_REVOKE` | access to the file was revoked |
487 +----------------------------+--------------------------------------------+
488
Georg Brandl1b5ab452009-08-13 07:56:35 +0000489 :const:`KQ_FILTER_PROC` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000490
491 +----------------------------+--------------------------------------------+
492 | Constant | Meaning |
493 +============================+============================================+
494 | :const:`KQ_NOTE_EXIT` | the process has exited |
495 +----------------------------+--------------------------------------------+
496 | :const:`KQ_NOTE_FORK` | the process has called *fork()* |
497 +----------------------------+--------------------------------------------+
498 | :const:`KQ_NOTE_EXEC` | the process has executed a new process |
499 +----------------------------+--------------------------------------------+
500 | :const:`KQ_NOTE_PCTRLMASK` | internal filter flag |
501 +----------------------------+--------------------------------------------+
502 | :const:`KQ_NOTE_PDATAMASK` | internal filter flag |
503 +----------------------------+--------------------------------------------+
504 | :const:`KQ_NOTE_TRACK` | follow a process across *fork()* |
505 +----------------------------+--------------------------------------------+
506 | :const:`KQ_NOTE_CHILD` | returned on the child process for |
507 | | *NOTE_TRACK* |
508 +----------------------------+--------------------------------------------+
509 | :const:`KQ_NOTE_TRACKERR` | unable to attach to a child |
510 +----------------------------+--------------------------------------------+
511
Georg Brandl1b5ab452009-08-13 07:56:35 +0000512 :const:`KQ_FILTER_NETDEV` filter flags (not available on Mac OS X):
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000513
514 +----------------------------+--------------------------------------------+
515 | Constant | Meaning |
516 +============================+============================================+
517 | :const:`KQ_NOTE_LINKUP` | link is up |
518 +----------------------------+--------------------------------------------+
519 | :const:`KQ_NOTE_LINKDOWN` | link is down |
520 +----------------------------+--------------------------------------------+
521 | :const:`KQ_NOTE_LINKINV` | link state is invalid |
522 +----------------------------+--------------------------------------------+
523
524
Christian Heimesfe337bf2008-03-23 21:54:12 +0000525.. attribute:: kevent.data
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000526
Georg Brandl1b5ab452009-08-13 07:56:35 +0000527 Filter specific data.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000528
529
Christian Heimesfe337bf2008-03-23 21:54:12 +0000530.. attribute:: kevent.udata
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000531
Georg Brandl1b5ab452009-08-13 07:56:35 +0000532 User defined value.