Hi,
I've got a question on using a select loop. Here is the basic way I
am using select:
if (answer = select(readfds, writefds, nil, 10))
answer[0].each do |r|
# handle reads
end
answer[1].each do |w|
# handle writes
end
else
# timeout
end
The question is: How do I know which file descriptors were returned
in the answer arrays? That is: after I get an answer and I finish
reading from the socket, I want to remove that socket from the readsfs
array, but I'm not sure how to do that. Do I need to do something
like:
answer[0].each do |r|
readfds.each_with_index do |orig,i|
if r == orig
# nuke this one
readfds.slice!(i)
end
end
end
That seems like an awful lot of overhead (cartesian product?) which
I why I think I'm doing it wrong...
Does anyone have some example code using a select loop? I would like
to use it to multiplex connections to web servers. That is, I have
10000 url's that I would like to retrieve the contents from, and would
like to do it using 50 parallel connections using select loop. I know
you can use threads for such an operation, but I would prefer to use
the select loop method.
thanks,
-joe