Timeout::timeout and Socket timeout

M

Mark Probert

Hi ..


I would like to suggest that Socket trap ETIMEDOUT and raise Timeout::Error
when a socket timeout occurs. This would allow the following:

begin
Timeout::timeout(to) do
t = TCPSocket.new(host,port)
#
# do socket stuff
#
t.close
end
rescue Timeout::Error => e
p "Timeout --> #{e}"
rescue Exception => e
p "Exception --> #{e}"
end

Rather than having a separate rescue clause.

Any thoughts?
 
B

Brian Candler

Hi ..


I would like to suggest that Socket trap ETIMEDOUT and raise Timeout::Error
when a socket timeout occurs.

I would oppose that.

These are two different error conditions: one is a socket error from the
kernel (the stack has failed to open a TCP connection), and the other is a
user-defined timeout. I'd certainly want to be able to distinguish them.
This would allow the following:

begin
Timeout::timeout(to) do
t = TCPSocket.new(host,port)
#
# do socket stuff
#
t.close
end
rescue Timeout::Error => e
p "Timeout --> #{e}"
rescue Exception => e
p "Exception --> #{e}"
end

Rather than having a separate rescue clause.

Any thoughts?

Assyming you want both types of exception to hit the "Timeout --> #{e}"
line, then all you need to do is

rescue Timeout::Error, Errno::ETIMEDOUT => e
p "Timeout --> #{e}"

Regards,

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top