From: Kem Mason Date: 2008-11-15T01:22:39+09:00 Subject: Re: How to set socket option SO_RCVTIMEO The problem with using timeout is that it is unsafe: (see http://tinyurl.com/5fngha ) I have actually encountered a problem using timeout where my thread hung forever (10 times in production over the last couple months) -- so this is why I am starting to do something else. You're right that gets silently ignores the exception -- turns out that was the main problem -- if I use sock.recvfrom, I get the exception as I want -- then I just have to handle the case where I get only part of the response (and still have time left). All is working now when using the code at: http://pastie.org/314914 thanks much for your help all Brian Candler wrote: > Kem Mason wrote: >> hehe yeh I just realized I could use a regular Socket instead of a TCP >> Socket -- it doesn't appear to be the only problem though. here's my >> latest code (which still doesn't timeout properly) > > Well, probably you shouldn't be using setsockopt for this at all. Note > that setting SO_RCVTIMEO just raises an EAGAIN on timeout; I'd expect > that gets would trap that and retry. > > Why not simply: > > require 'timeout' > result = nil > timeout(1.5) { > result = sock.gets > } -- Posted via http://www.ruby-forum.com/.