The Epoll
class provides high-level access to epoll(7) functionality in the Linux 2.6 and later kernels. It provides fork and GC-safety for Ruby objects stored within the IO
object and may be passed as an argument to IO.select.
specifies whether close-on-exec flag is set for Epoll.new
registers a target IO
object via epoll_ctl
unregisters a target IO
object via epoll_ctl
modifies the registration of a target IO
object via epoll_ctl
watch for errors, there is no need to specify this, it is always monitored when an IO
is watched
notifications are only Edge Triggered, see epoll(7)
Sets an exclusive wakeup mode for the epoll object that is being attached to the target IO
. This avoids thundering herd scenarios when the same target IO
is shared among multiple epoll objects. Available since Linux 4.5
watch for hangups, there is no need to specify this, it is always monitored when an IO
is watched
watch for read/recv operations
unwatch the descriptor once any event has fired
watch for write/send operations
watch for urgent read(2) data
Watch a specified io for shutdown(SHUT_WR) on the remote-end. Available since Linux 2.6.17.
This prevents system suspend while event is ready. This requires the caller to have the CAP_BLOCK_SUSPEND capability Available since Linux 3.5
SleepyPenguin::Epoll.new([flags]) -> Epoll object source
Creates a new Epoll
object with an optional flags
argument. flags
may currently be :CLOEXEC
or 0
(or nil
).
add (io, events) source
Starts watching a given io
object with events
which may be an Integer bitmask or Array representing arrays to watch for.
ep.close -> nil source
Closes an existing Epoll
object and returns memory back to the kernel. Raises IOError if object is already closed.
ep.closed? -> true or false source
Returns whether or not an Epoll
object is closed.
ep.del(io) -> 0 source
Disables an IO
object from being watched.
ep.delete(io) -> io or nil source
This method is deprecated and will be removed in sleepy_penguin 4.x
Stops an io
object from being monitored. This is like Epoll#del
but returns nil
on ENOENT instead of raising an error. This is useful for apps that do not care to track the status of an epoll object itself.
This method is deprecated and will be removed in sleepy_penguin 4.x
epoll.events_for(io) -> Integer source
Returns the events currently watched for in current Epoll
object. Mostly used for debugging.
flags_for (io)
backwards compatibility, to be removed in 4.x
epoll.include?(io) -> true or false source
Returns whether or not a given IO
is watched and prevented from being garbage-collected by the current Epoll
object. This may include closed IO
objects.
ep.io_for(io) -> object source
Returns the given IO
object currently being watched for. Different IO
objects may internally refer to the same process file descriptor. Mostly used for debugging.
epoll.mod(io, flags) -> 0 source
Changes the watch for an existing IO
object based on events
. Returns zero on success, will raise SystemError on failure.
ep.set(io, flags) -> 0 source
This method is deprecated and will be removed in sleepy_penguin 4.x
Used to avoid exceptions when your app is too lazy to check what state a descriptor is in, this sets the epoll descriptor to watch an io
with the given events
events
may be an array of symbols or an unsigned Integer bit mask:
events = [ :IN, :ET ]
events = SleepyPenguin::Epoll::IN
| SleepyPenguin::Epoll::ET
See constants in Epoll
for more information.
This method is deprecated and will be removed in sleepy_penguin 4.x
to_io () source
Epoll
objects may be watched by IO.select and similar methods
wait (maxevents = 64, timeout = nil) { |events, io| ... } source
Calls epoll_wait(2) and yields Integer events
and IO
objects watched for. maxevents
is the maximum number of events to process at once, lower numbers may prevent starvation when used by epoll_wait in multiple threads. Larger maxevents
reduces syscall overhead for single-threaded applications. maxevents
defaults to 64 events. timeout
is specified in milliseconds, nil
(the default) meaning it will block and wait indefinitely.
As of sleepy_penguin 3.5.0+, it is possible to nest wait
calls within the same thread.
mail archives: https://yhbt.net/sleepy-penguin/ public: sleepy-penguin@yhbt.net source code: git clone https://yhbt.net/sleepy_penguin.git