From: Joel VanderWerf Date: 2004-07-24T08:19:02+09:00 Subject: Re: [Q] Is there any way to do a non-blocking TCPSocket#recv? Warren Brown wrote: > I am trying to create a simple socket monitor program in Ruby. The idea > is to listen for an "inbound" connection, then open an "outbound" socket > and forward all of the traffic both ways while logging the traffic. In > order to do this, I need to be able to tell if there is data available > to receive before doing the TCPSocket#recv, since #recv blocks if there > isn't any (instead of simply returning 0 bytes or nil). There is no > #select method in any of the classes to test for data availability, so > I'm stuck. I would think this is a common thing to want to do, but > there doesn't seem to be any way to do it using the socket library. > What am I missing? What about putting each socket handler in a thread and using two queues to pass data between threads? (I'm ignorant, but I think internally ruby will use select() to schedule these threads to run when data is coming in.)