A Windows issue with Kernel#select

I’m working on a Class that I’d like to be able to use on both Windows and
*nix, but am having problems getting the desired behavior out of Windows.
Currently, I’m using the native win32 version of Ruby which gives this
output from ‘ruby -v’: ruby 1.6.7 (2002-03-01) [i586-mswin32]

I first create a socket:
s = TCPSocket.new(‘localhost’, ‘5222’)

Then I use Kernel#select to monitor the socket for new input:
x = select([s], nil, nil, 30)
puts x.inspect

In *nix (FreeBSD) when there is data waiting on the socket, I get the
results, namely an array with my socket:
[[#TCPSocket:0x2a64738], [], []]

However, on Windows, I’m getting an empty array:
[[], [], []]

As near as I can tell, the select is returnning at the right time… I
tested this by opening the socket, dumping the current time, sending an
event at roughly 5 seconds from the server, then dumping out the time
select returned with the output. select returns with the array at ~5
seconds, which is far below the expiration which is set at 30 seconds, but
the array comes back empty.

Any clues? Since my Class will eventually need to be able to handle
multiple sockets, this behavior just won’t fly. I will need to know which
sockets have data available.

Thanks in advance.

Cheers,

bs.

Hi,

···

At Tue, 17 Sep 2002 20:43:47 +0900, Ben Schumacher wrote:

Then I use Kernel#select to monitor the socket for new input:
x = select([s], nil, nil, 30)
puts x.inspect

In *nix (FreeBSD) when there is data waiting on the socket, I get the
results, namely an array with my socket:
[[#TCPSocket:0x2a64738], , ]

However, on Windows, I’m getting an empty array:
[, , ]

It sounds like the bug reported in [ruby-talk:40009]. If so, it
doesn’t occur in 1.7 but hasn’t been fixed in 1.6 yet.


Nobu Nakada

Hello-

Hi,

Then I use Kernel#select to monitor the socket for new input:
x = select([s], nil, nil, 30)
puts x.inspect

In *nix (FreeBSD) when there is data waiting on the socket, I get the
results, namely an array with my socket:
[[#TCPSocket:0x2a64738], , ]

However, on Windows, I’m getting an empty array:
[, , ]

It sounds like the bug reported in [ruby-talk:40009]. If so, it
doesn’t occur in 1.7 but hasn’t been fixed in 1.6 yet.

Just upgraded to 1.7.2 on my Windows box, and it looks like you’re
correct. Apparently, I left some information out of my previous email…
the problem only manifested itself when the select was in a Thread. I
suppose if this bug has already been reported, there is no reason to
report again.

Thanks for the information.

bs.

···

On Wed, 18 Sep 2002 nobu.nokada@softhome.net wrote:

At Tue, 17 Sep 2002 20:43:47 +0900, > Ben Schumacher wrote: