I want to be able to return quickly from a networking call that times out (having seen that my code can hang forever if the network is down, or similar)
My code looks like:
s = TCPSocket.open(hostname,port)
s.puts msg
ret = s.recv(1024)
s.close
I'm pretty confused at the documentation for TCPSocket, for example, doesn't even MENTION it's open or recv functions:
http://ruby-doc.org/core/classes/TCPSocket.html
Nor does it's parent, Socket:
http://ruby-doc.org/core/classes/Socket.html
I DO see that Socket has a connect and recv_from...and am not sure if that's the same thing. I also see that both can raise an error:
Errno::ETIMEDOUT
in the case of a time out. I'm not sure if open and recv similarly raises this error, and if they do, how long is "long enough" to time out, or if this is configurable.
Is there a better source of TCPSocket documentation?
Can I just surround the code with a:
begin
rescue => err
end
block? Will that take care of the Time out error? Will there even BE a time out error? The lack of doc confuses me...