# TCPSocket select method

**URL:** <https://www.ruby-forum.com/t/tcpsocket-select-method/111961>\
**Category:** Ruby\
**Created:** [August 13, 2007, 9:44pm UTC](https://www.ruby-forum.com/t/tcpsocket-select-method/111961 "2007-08-13T21:44:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [August 13, 2007, 9:44pm UTC](https://www.ruby-forum.com/t/tcpsocket-select-method/111961/1 "2007-08-13T21:44:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [August 14, 2007, 5:09am UTC](https://www.ruby-forum.com/t/tcpsocket-select-method/111961/2 "2007-08-14T05:09:43Z")

</div>

Roger P. 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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [August 14, 2007, 8:56am UTC](https://www.ruby-forum.com/t/tcpsocket-select-method/111961/3 "2007-08-14T08:56:03Z")

</div>

On Monday 13 August 2007, Roger P. 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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [August 14, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/tcpsocket-select-method/111961/4 "2007-08-14T21:23:31Z")

</div>

Eric H. wrote:

> On Aug 13, 2007, at 23:54, Sylvain J. 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…

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [August 14, 2007, 11:28am UTC](https://www.ruby-forum.com/t/tcpsocket-select-method/111961/5 "2007-08-14T11:28:18Z")

</div>

On Aug 13, 2007, at 23:54, Sylvain J. 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.

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [August 14, 2007, 10:51pm UTC](https://www.ruby-forum.com/t/tcpsocket-select-method/111961/6 "2007-08-14T22:51:07Z")

</div>

On Aug 14, 3:23 pm, Roger P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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?
