From: Aredridel Date: 2004-07-24T13:13:46+09:00 Subject: Re: [Q] Is there any way to do a non-blocking TCPSocket#recv? On Sat, 2004-07-24 at 08:14 +0900, 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? Use select anyway: i,o,e = select([@insock, @outsock]) or similar. Or use threads -- Ruby's threads use a select() call internally anyway.