Select?

Is there a way in ruby to do the equivalent of the select(2) unix
system call? I couldn’t find anything in the documentation I checked
but I may simply have been looking in the wrong places.

···


Perry E. Metzger perry@piermont.com

“Ask not what your country can force other people to do for you…”

Is there a way in ruby to do the equivalent of the select(2) unix
system call? I couldn't find anything in the documentation I checked
but I may simply have been looking in the wrong places.

Kernel::select

pigeon% ri Kernel::select
--------------------------------------------------------- Kernel::select
     select( readArray [, writeArray [errorArray [timeout]]] ) ->
     anArray or nil

···

------------------------------------------------------------------------
     Performs a low-level select call, which waits for data to become
     available from input/output devices. The first three parameters are
     arrays of IO objects or nil. The last is a timeout in seconds,
     which should be an Integer or a Float. The call waits for data to
     become available for any of the IO objects in readArray, for
     buffers to have cleared sufficiently to enable writing to any of
     the devices in writeArray, or for an error to occur on the devices
     in errorArray. If one or more of these conditions are met, the call
     returns a three-element array containing arrays of the IO objects
     that were ready. Otherwise, if there is no change in status for
     timeout seconds, the call returns nil. If all parameters are nil,
     the current thread sleeps forever.
        select( [$stdin], nil, nil, 1.5 ) #=> [[#<IO:0x4019202c>], , ]

pigeon%

Guy Decoux

“Perry E. Metzger” perry@piermont.com writes:

Is there a way in ruby to do the equivalent of the select(2) unix
system call? I couldn’t find anything in the documentation I checked
but I may simply have been looking in the wrong places.

Never mind – I seem to have found it.

ri IO#select

------------------------------------------------------------- IO::select
IO.select( readArray [, writeArray [errorArray [timeout]]] ) →
anArray
or nil

···

On 2002.08.22, Perry E. Metzger perry@piermont.com wrote:

Is there a way in ruby to do the equivalent of the select(2) unix
system call? I couldn’t find anything in the documentation I checked
but I may simply have been looking in the wrong places.


 See Kernel#select on page 426.

– Dossy


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)