summaryrefslogtreecommitdiffstats
path: root/Doc/library/select.rst
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-03-21 23:49:44 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-03-21 23:49:44 (GMT)
commit0e9ab5f2f0f907b57c70557e21633ce8c341d1d1 (patch)
treecff563d889c8bca44a7214739706e3674d402d26 /Doc/library/select.rst
parent5f79446af07b8bd7821ca4aacc96895c811f2733 (diff)
downloadcpython-0e9ab5f2f0f907b57c70557e21633ce8c341d1d1.zip
cpython-0e9ab5f2f0f907b57c70557e21633ce8c341d1d1.tar.gz
cpython-0e9ab5f2f0f907b57c70557e21633ce8c341d1d1.tar.bz2
Applied patch #1657 epoll and kqueue wrappers for the select module
The patch adds wrappers for the Linux epoll syscalls and the BSD kqueue syscalls. Thanks to Thomas Herve and the Twisted people for their support and help. TODO: Finish documentation documentation
Diffstat (limited to 'Doc/library/select.rst')
-rw-r--r--Doc/library/select.rst304
1 files changed, 300 insertions, 4 deletions
diff --git a/Doc/library/select.rst b/Doc/library/select.rst
index 4a97179..1368c78 100644
--- a/Doc/library/select.rst
+++ b/Doc/library/select.rst
@@ -7,10 +7,12 @@
This module provides access to the :cfunc:`select` and :cfunc:`poll` functions
-available in most operating systems. Note that on Windows, it only works for
-sockets; on other operating systems, it also works for other file types (in
-particular, on Unix, it works on pipes). It cannot be used on regular files to
-determine whether a file has grown since it was last read.
+available in most operating systems, :cfunc:`epoll` available on Linux 2.5+ and
+:cfunc:`kqueue` available on most BSD.
+Note that on Windows, it only works for sockets; on other operating systems,
+it also works for other file types (in particular, on Unix, it works on pipes).
+It cannot be used on regular files to determine whether a file has grown since
+it was last read.
The module defines the following:
@@ -22,6 +24,16 @@ The module defines the following:
string, as would be printed by the C function :cfunc:`perror`.
+.. type:: epoll([sizehint=-1])
+
+ (Only supported on Linux 2.5.44 and newer.) Returns an edge polling
+ object, which can be used as Edge or Level Triggered interface for I/O
+ events; see section :ref:`epoll-objects` below for the methods supported
+ by epolling objects.
+
+ .. versionadded:: 2.6
+
+
.. function:: poll()
(Not supported by all operating systems.) Returns a polling object, which
@@ -30,6 +42,24 @@ The module defines the following:
by polling objects.
+.. type:: kqueue()
+
+ (Only supported on BSD.) Returns a kernel queue object
+ object; see section :ref:`kqueue-objects` below for the methods supported
+ by kqueue objects.
+
+ .. versionadded:: 2.6
+
+
+.. type:: kqueue(ident, filter=KQ_FILTER_READ, flags=KQ_ADD, fflags=0, data=0, udata=0)
+
+ (Only supported on BSD.) Returns a kernel event object
+ object; see section :ref:`kevent-objects` below for the methods supported
+ by kqueue objects.
+
+ .. versionadded:: 2.6
+
+
.. function:: select(iwtd, owtd, ewtd[, timeout])
This is a straightforward interface to the Unix :cfunc:`select` system call.
@@ -67,6 +97,81 @@ The module defines the following:
not handle file descriptors that don't originate from WinSock.
+.. _epoll-objects:
+
+Edge and Level Trigger Polling (epoll) Objects
+----------------------------------------------
+
+ http://linux.die.net/man/4/epoll
+
+ *eventmask*
+
+ +-----------------------+-----------------------------------------------+
+ | Constant | Meaning |
+ +=======================+===============================================+
+ | :const:`EPOLLIN` | Available for read |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLOUT` | Available for write |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLPRI` | Urgent data for read |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLERR` | Error condition happend on the assoc. fd |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLHUP` | Hang up happend on the assoc. fd |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLET` | Set Edge Trigger behavior, the default is |
+ | | Level Trigger behavior |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is |
+ | | pulled out, the fd is internally disabled |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLRDNORM` | ??? |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLRDBAND` | ??? |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLWRNORM` | ??? |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLWRBAND` | ??? |
+ +-----------------------+-----------------------------------------------+
+ | :const:`EPOLLMSG` | ??? |
+ +-----------------------+-----------------------------------------------+
+
+
+.. method:: epoll.close()
+
+ Close the control file descriptor of the epoll object.
+
+
+.. method:: epoll.fileno()
+
+ Return the file descriptor number of the control fd.
+
+
+.. method:: epoll.fromfd(fd)
+
+ Create an epoll object from a given file descriptor.
+
+
+.. method:: epoll.register(fd[, eventmask])
+
+ Register a fd descriptor with the epoll object.
+
+
+.. method:: epoll.modify(fd, eventmask)
+
+ Modify a register file descriptor.
+
+
+.. method:: epoll.unregister(fd)
+
+ Remove a registered file descriptor from the epoll object.
+
+
+.. method:: epoll.poll([timeout=-1[, maxevents=-1]])
+
+ Wait for events. timeout in seconds (float)
+
+
.. _poll-objects:
Polling Objects
@@ -114,6 +219,16 @@ linearly scanned again. :cfunc:`select` is O(highest file descriptor), while
the same effect as registering the descriptor exactly once.
+.. method:: poll.modify(fd, eventmask)
+
+ Modifies an already registered fd. This has the same effect as
+ :meth:`register(fd, eventmask)`. Attempting to modify a file descriptor
+ that was never registered causes an :exc:`IOError` exception with errno
+ :const:`ENOENT` to be raised.
+
+ .. versionadded:: 2.6
+
+
.. method:: poll.unregister(fd)
Remove a file descriptor being tracked by a polling object. Just like the
@@ -137,3 +252,184 @@ linearly scanned again. :cfunc:`select` is O(highest file descriptor), while
returning. If *timeout* is omitted, negative, or :const:`None`, the call will
block until there is an event for this poll object.
+
+.. _kqueue-objects:
+
+Kqueue Objects
+--------------
+
+.. method:: kqueue.close()
+
+ Close the control file descriptor of the kqueue object.
+
+
+.. method:: kqueue.fileno()
+
+ Return the file descriptor number of the control fd.
+
+
+.. method:: epoll.fromfd(fd)
+
+ Create a kqueue object from a given file descriptor.
+
+
+.. method:: control(changelist, max_events=0[, timeout=None]) -> eventlist
+
+ Low level interface to kevent
+
+ - changelist must be an iterable of kevent object or None
+ - max_events must be 0 or a positive integer
+ - timeout in seconds (floats possible)
+
+
+.. _kevent-objects:
+
+Kevent Objects
+--------------
+
+ http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
+
+ .. attribute:: ident
+
+ Value used to identify the event. The interpretation depends on the filter
+ but it's usually the file descriptor. In the constructor ident can either
+ be an int or an object with a fileno() function. kevent stores the integer
+ internally.
+
+ .. attribute:: filter
+
+ Name of the kernel filter
+
+ +---------------------------+---------------------------------------------+
+ | Constant | Meaning |
+ +===========================+=============================================+
+ | :const:`KQ_FILTER_READ` | Takes a descriptor and returns whenever |
+ | | there is data available to read |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_FILTER_WRITE` | Takes a descriptor and returns whenever |
+ | | there is data available to read |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_FILTER_AIO` | AIO requests |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_FILTER_VNODE` | Returns when one or more of the requested |
+ | | events watched in *fflag* occurs |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_FILTER_PROC` | Watch for events on a process id |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_FILTER_NETDEV` | Watch for events on a network device |
+ | | [not available on Mac OS X] |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_FILTER_SIGNAL` | Returns whenever the watched signal is |
+ | | delivered to the process |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_FILTER_TIMER` | Establishes an arbitrary timer |
+ +---------------------------+---------------------------------------------+
+
+ .. attribute:: flags
+
+ Filter action
+
+ +---------------------------+---------------------------------------------+
+ | Constant | Meaning |
+ +===========================+=============================================+
+ | :const:`KQ_EV_ADD` | Adds or modifies an event |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_DELETE` | Removes an event from the queue |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_ENABLE` | Permitscontrol() to returns the event |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_DISABLE` | Disablesevent |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_ONESHOT` | Removes event after first occurence |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_CLEAR` | Reset the state after an event is retrieved |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_SYSFLAGS` | internal event |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_FLAG1` | internal event |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_EOF` | Filter specific EOF condition |
+ +---------------------------+---------------------------------------------+
+ | :const:`KQ_EV_ERROR` | See return values |
+ +---------------------------+---------------------------------------------+
+
+
+ .. attribute:: fflags
+
+ Filter specific flags
+
+
+ *:const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags
+
+ +----------------------------+--------------------------------------------+
+ | Constant | Meaning |
+ +============================+============================================+
+ | :const:`KQ_NOTE_LOWAT` | low water mark of a socket buffer |
+ +----------------------------+--------------------------------------------+
+
+
+ *:const:`KQ_FILTER_VNODE` filter flags*
+
+ +----------------------------+--------------------------------------------+
+ | Constant | Meaning |
+ +============================+============================================+
+ | :const:`KQ_NOTE_DELETE` | *unlink()* was called |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_WRITE` | a write occured |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_EXTEND` | the file was extended |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_ATTRIB` | an attribute was changed |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_LINK` | the link count has changed |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_RENAME` | the file was renamed |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_REVOKE` | access to the file was revoked |
+ +----------------------------+--------------------------------------------+
+
+
+ *:const:`KQ_FILTER_PROC` filter flags*
+
+ +----------------------------+--------------------------------------------+
+ | Constant | Meaning |
+ +============================+============================================+
+ | :const:`KQ_NOTE_EXIT` | the process has exited |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_FORK` | the process has called *fork()* |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_EXEC` | the process has executed a new process |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_PCTRLMASK` | internal filter flag |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_PDATAMASK` | internal filter flag |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_TRACK` | follow a process across *fork()* |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_CHILD` | returned on the child process for |
+ | | *NOTE_TRACK* |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_TRACKERR` | unable to attach to a child |
+ +----------------------------+--------------------------------------------+
+
+ *:const:`KQ_FILTER_NETDEV` filter flags* [not available on Mac OS X]
+
+ +----------------------------+--------------------------------------------+
+ | Constant | Meaning |
+ +============================+============================================+
+ | :const:`KQ_NOTE_LINKUP` | link is up |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_LINKDOWN` | link is down |
+ +----------------------------+--------------------------------------------+
+ | :const:`KQ_NOTE_LINKINV` | link state is invalid |
+ +----------------------------+--------------------------------------------+
+
+
+ .. attribute:: data
+
+ Filter specific data
+
+
+ .. attribute:: udata
+
+ User defined value