Class Poll
In: poll.c
lib/poll.rb
Parent: Object

An object-oriented poll() implementation for Ruby

Methods
add    addMask    args    callback    clear    events    handles    hasCallback?    has_callback?    inspect    mask    new    poll    register    registered?    remove    removeMask    setCallback    setMask    unregister   
Classes and Modules
Class Poll::EventMask
Public Class methods
new()

Create and return new poll object.

Public Instance methods
register( io, eventMask, callback=nil, *arguments, &block )

Register the specified IO object with the specified eventMask. If the optional callback parameter (a Method or Proc object) or a block is given, it will be called with io and the mask of the event/s whenever poll generates any events for io. If the callback parameter non-nil, any block specified is discarded. Any arguments specified are passed to the callback as the third and succeeding arguments. The following event masks can be set in the eventMask:

Poll::IN
Data other than high-priority data may be read without blocking.
Poll::PRI
High-priority data may be received without blocking.
Poll::OUT
Normal data (priority band equals 0) may be written without blocking.

The following masks are ignored in the eventMask, as they are always implicitly set, but they may be specified in the handler callback or block to trap the conditions they represent:

Poll::ERR
An error has occurred on the device.
Poll::HUP
The device has been disconnected. This event and Poll::OUT are mutually exclusive; a device can never be writable once a hangup has occurred. However, this event and Poll::IN, Poll::RDNORM, Poll::RDBAND, or Poll::PRI are not mutually exclusive.
Poll::NVAL
The io object specified is invalid — it has been closed, has a bad file descriptor, etc.

If your operating system defines them, these masks are also available:

Poll::RDNORM
Normal data (priority band equals 0) may be read without blocking.
Poll::RDBAND
Data from a non-zero priority band may be read without blocking.
Poll::WRNORM
Same as Poll::OUT.
Poll::WRBAND
Priority data (priority band greater than 0) may be written.
This method is also aliased as add
add( io, eventMask, callback=nil, *arguments, &block )

Alias for register

unregister( io )

Remove the specified io from the receiver’s list of registered handles, if present. Returns the handle if it was registered, or nil if it was not.

This method is also aliased as remove
remove( io )

Alias for unregister

registered?( io )

Returns true if the specified io is registered with the poll object.

clear()

Clear all registered handles from the poll object. Returns the handles that were cleared.

mask( io )

Get the EventMask for the specified io.

setMask( io, eventMask )

Set the EventMask for the specified io to the given eventMask.

addMask( io, eventMask )

Add (bitwise OR) the specified eventMask to the mask for the specified io. Returns the new mask.

removeMask( io, eventMask )

Remove (bitwise XOR) the specified eventMask from the mask for the specified io. Returns the new mask.

hasCallback?( io )

Returns true if the specified io has a callback associated with it.

This method is also aliased as has_callback?
has_callback?( io )

Alias for hasCallback?

callback( io )

Returns the per-handle callback associated with the specified io. If no callback exists for the given io, nil is returned.

args( io )

Returns the per-handle callback arguments associated with the specified io as an Array. If no callback exists for the given io, nil is returned.

setCallback( io, callback=nil, *args, &block )

Reset the per-handle callback associated with the specified io to the specified callback (a Proc or Method object) or block, if given, or to nil if not specified. Any arguments specified past the second will be passed to the callback as its arguments. Returns the old callback.

poll( timeout=-1 ) {|io, eventMask| ...}

Call the system-level poll function with the handles registered to the receiver. Any callbacks specified when the handles were registered are run for those handles with events. If a block is given, it will be invoked once for each handle which doesn’t have an explicit handler. The timeout argument is the number of floating-point seconds to wait for an event before returning; negative timeout values will cause poll to block until there is at least one event to report. This method returns the number of handles on which one or more events occurred.

events( eventMask=nil )

Fetch an Array of handles which had the events specified by eventMask happen to them in the last call to poll. If eventMask is nil, an Array of all handles with pending events is returned.

handles( eventMask=nil )

Fetch an Array of handles that are masked to receive the specified eventMask. If eventMask is nil, an Array of all registered handles is returned.

inspect()

Return a human-readable string describing the poll object.