Timeout::timeout and Socket timeout

Discussion in 'Ruby' started by Mark Probert, Oct 6, 2004.

  1. Mark Probert

    Mark Probert Guest

    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?

    --
    -mark. (probertm @ acm dot org)
    Mark Probert, Oct 6, 2004
    #1
    1. Advertising

  2. On Wed, Oct 06, 2004 at 02:04:49PM +0900, Mark Probert wrote:
    >
    > 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.
    Brian Candler, Oct 6, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laszlo Nagy
    Replies:
    1
    Views:
    4,822
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    966
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    545
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    662
    Steve Holden
    Feb 1, 2009
  5. Steve Holden
    Replies:
    1
    Views:
    715
Loading...

Share This Page