Forum: Ruby TCPSocket select method

Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2007-08-13 21:44
Hmm.  If you create a method thus:
class TCPSocket
 def readableNow?
   r,w,e = select([self],nil,nil,0)
   return r != nil
 end
end

It turns out to use a select OTHER than IO.select. Anyone know, by
chance what the 'internal' select method does?
Thanks.
-Roger
57a778becb5ea951889fa9f0b4e3bd15?d=identicon&s=25 Michael Linfield (macgoober)
on 2007-08-14 05:09
Roger Pack wrote:
> Hmm.  If you create a method thus:
> class TCPSocket
>  def readableNow?
>    r,w,e = select([self],nil,nil,0)
>    return r != nil
>  end
> end
>
> It turns out to use a select OTHER than IO.select. Anyone know, by
> chance what the 'internal' select method does?
> Thanks.
> -Roger

The kernel select method -

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 read_array, for buffers to have
cleared sufficiently to enable writing to any of the devices in
write_array, or for an error to occur on the devices in error_array. 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.

Dunno if thats what u were lookin for
934180817a3765d132193a5428f99051?d=identicon&s=25 Sylvain Joyeux (Guest)
on 2007-08-14 08:56
(Received via mailing list)
On Monday 13 August 2007, Roger Pack wrote:
> Hmm.  If you create a method thus:
> class TCPSocket
>  def readableNow?
>    r,w,e = select([self],nil,nil,0)
>    return r != nil
>  end
> end
>
> It turns out to use a select OTHER than IO.select. Anyone know, by
> chance what the 'internal' select method does?
It cannot use IO.select since IO.select is a singleton method of IO and
a
TCPSocket object is an instance of IO. The only way to explicitely get
IO.select is to call
  r,w,e = IO.select(...)

It calls Kernel#select. And I wouldn't be surprised if Kernel#select and
IO.select were actually the same method ...

Sylvain
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2007-08-14 11:28
(Received via mailing list)
On Aug 13, 2007, at 23:54, Sylvain Joyeux wrote:

>> chance what the 'internal' select method does?
> It cannot use IO.select since IO.select is a singleton method of IO
> and a
> TCPSocket object is an instance of IO. The only way to explicitely get
> IO.select is to call
>   r,w,e = IO.select(...)
>
> It calls Kernel#select. And I wouldn't be surprised if
> Kernel#select and
> IO.select were actually the same method ...

They are.
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2007-08-14 21:23
Eric Hodel wrote:
> On Aug 13, 2007, at 23:54, Sylvain Joyeux wrote:
>
>>> chance what the 'internal' select method does?
>> It cannot use IO.select since IO.select is a singleton method of IO
>> and a
>> TCPSocket object is an instance of IO. The only way to explicitely get
>> IO.select is to call
>>   r,w,e = IO.select(...)
>>
>> It calls Kernel#select. And I wouldn't be surprised if
>> Kernel#select and
>> IO.select were actually the same method ...
>
> They are.

 class TCPSocket
  def readableNow?
    r,w,e = select([self],nil,nil,0)
    return r != nil
  end
 end

So...follow up question:
with the above code, if you try to run it, it says that "select takes 0
arguments, 4 given" (whereas 'normally' select takes four).  If I
replace the call to select (above), with IO.select, then it works with 4
parameters.  So I am thinking it is a different 'internal' select
function of some type.  So...my guess is it is not a call to IO.select
or Kernel.select...hmm...
7877268675d21c33224951b247d518cf?d=identicon&s=25 unknown (Guest)
on 2007-08-14 22:51
(Received via mailing list)
On Aug 14, 3:23 pm, Roger Pack <rogerpack2...@gmail.com> wrote:
> >> It calls Kernel#select. And I wouldn't be surprised if
>  end
>
> So...follow up question:
> with the above code, if you try to run it, it says that "select takes 0
> arguments, 4 given" (whereas 'normally' select takes four).  If I
> replace the call to select (above), with IO.select, then it works with 4
> parameters.  So I am thinking it is a different 'internal' select
> function of some type.  So...my guess is it is not a call to IO.select
> or Kernel.select...hmm...
> --
> Posted viahttp://www.ruby-forum.com/.

Enumerable#select takes no args... perhaps you have an array of IOs
you're calling select on?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.