From: Caleb Clausen Date: 2010-01-04T07:43:32+09:00 Subject: Re: "Dummy" IO object to push and pull data? On 1/3/10, Shay Hawkins wrote: > Caleb Clausen wrote: >> My recollection is that on windows, select only works on sockets. It >> doesn't do anything useful with pipes. You are far from being the >> first programmer to regret that this is the case. > > To make sure that I've been using it right, select is supposed to check > if the IO objects have data ready, and if so, return an array of the > ready objects? It returns an _array_ of arrays of ready file handles. > require("socket") > > server = TCPServer.new("localhost",0) > insock = TCPSocket.new(server.addr[3],server.addr[1]) > outsock = server.accept() > server.close() > > puts("Select starting...") > ready = select([outsock]) > puts("Select is over.") > > I created a quick test program to make sure that select was working how > I thought it did. When this program is run, it outputs "Select > starting...", and then locks up, because it's waiting for outsock to > receive data (which it never will). What I hoped it would do is output > "Select starting..." and then output "Select is over.", because no data > was ready to be read from outsock. Right. Select never returns because nothing ever happens on any of the file handles you asked it about. If you want a nonblocking select, pass 0 for its timeout (final parameter). Even better, make some kind of event for select to read. Either write some data to insock, or close insock so the select there's some event to be read (even if just end of file). (BTW, above snippet has unfortunate variable names; insock and outsock should be swapped.)