From: Joel VanderWerf Date: 2006-03-29T05:43:12+09:00 Subject: Re: timeout when listening with TCPServer Joel VanderWerf wrote: > Bill Kelly wrote: >> From: "Eric Hodel" >>> On Mar 28, 2006, at 9:48 AM, Shea Martin wrote: >>> >>>> I want to listen for connections for 2 seconds, then timeout. Do I >>>> have to use the Timeout module? >>> That will be the easiest way. >>> >>> Timeout.timeout 2 do >>> Thread.start server.accept do |s| new_connection s end >>> end >> Oh, hey, cool. Using the thread there looks like it >> ought to avoid the issue with Timeout firing in the >> middle of ensure blocks and circumventing them? >> >> I've been avoiding Timeout like "the plague" since >> running into that behavior. > > But the timeout won't stop the thread. Ignore my last post. Not stopping the thread is probably exactly the behavior that you want. The timeout affects only the server.accept call (and the Thread.start). So this code is allowing 2 sec for a connection, but no placing a limit on what happens after that. I think it might be clearer to write it as session = Timeout.timeout 2 do server.accept end Thread.start(session) do |s| new_connection s end but that is only my unconsidered opinion. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407