Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Reducing timeout on SockConnect

2013-08-06
2013-08-08
  • Chuck Tribolet
    Chuck Tribolet
    2013-08-06

    SockConnect seems to have a default timeout of 20 seconds. I'd like to reduce that to two seconds.
    I've tried setting SO_RCVTIMEO and SO_SNDTIMEO to 2, and verified via SockGetSockOpt that the change actually took place, but SockConnect still times out in 20 seconds.

    Am I missing something? Or should the be a bug report or feature request.

     
    • David Ashley
      David Ashley
      2013-08-06

      This timeout is not something you can change. It is compiled into the
      network stack code that sits closer to the hardware than the sockets
      interface. You will just have to live with it.

      David Ashley

      On Tue, 2013-08-06 at 18:17 +0000, Chuck Tribolet wrote:

      SockConnect seems to have a default timeout of 20 seconds. I'd like to reduce that to two seconds.
      I've tried setting SO_RCVTIMEO and SO_SNDTIMEO to 2, and verified via SockGetSockOpt that the change actually took place, but SockConnect still times out in 20 seconds.

      Am I missing something? Or should the be a bug report or feature request.


      Reducing timeout on SockConnect


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/oorexx/discussion/408477/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       
    • Perry Werneck
      Perry Werneck
      2013-08-07

      Hi,

      Never tried on rexx, but, on C code this problem can be avoided putting the
      socket to non blocking mode, doing the connect and, according to the return
      code of the connect you have to wait on a select() with any timeout you
      want. The C code can be packaged in a rexx extension library to simplify
      the usage.

      Maybe the implementation of a SockTimedConnect() method in rxsock could be
      a good idea.

      2013/8/6 Chuck Tribolet triblet@users.sf.net

      SockConnect seems to have a default timeout of 20 seconds. I'd like to
      reduce that to two seconds.
      I've tried setting SO_RCVTIMEO and SO_SNDTIMEO to 2, and verified via
      SockGetSockOpt that the change actually took place, but SockConnect still
      times out in 20 seconds.

      Am I missing something? Or should the be a bug report or feature request.

      Reducing timeout on SockConnecthttps://sourceforge.net/p/oorexx/discussion/408477/thread/43848ac3/?limit=25#3936

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/oorexx/discussion/408477/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

      --
      Perry Werneck
      Brasília/DF

       
  • Chuck Tribolet
    Chuck Tribolet
    2013-08-07

    Thanks. I coded up a quick and dirty SockConnectTimed() that works like SockConnect except for taking an additional third timeout parameter. I'll pass it along below.
    I have some questions:

    It only works if the second parm is "gosaddr." Is there some way to expose the variable
    named in arg(2)? The expose keyword command won't work because it's for methods, and
    (arg(1)) on the Procedure's Expose is a syntax error.

    Should I be doing something to flush out the SockConnect when it times out?

    I tried using SockSockErrno() to get the error code, but it terminates the program if used.

    SockConnectTimed: Procedure Expose gosaddr. Test errno h_errno
      SocketHandle = Arg(1)
      Address = Arg(2)
      Timeout = Arg(3)
      If Test
        Then
          Say "  SockConnectTimed("SocketHandle","Address","Timeout") entered."
      If Test
        Then
          Say "    Calling SockIOctl"                    
      SockIOctlRC = SockIOctl(SocketHandle,"FIONBIO",1)
      If Test
        Then
          Say "      SockIOctlRC="SockIOctlRC
      If SockIOctlRC = -1
        Then
          Do
          If Test 
            Then 
              Say "      ErrNo="ErrNo
          End
      If Test
        Then
          Say "    Calling SockConnect"                
      SockConnectRC = SockConnect(SocketHandle,Address)
      If Test
        Then
          Say "      SockConnectRC="SockConnectRC
      If SockConnectRC = -1
        Then
          Do
          If Test 
            Then 
              Do
              Say "      ErrNo="ErrNo
              End
          End
      w.0 = 1
      w.1 = SocketHandle
      If Test
        Then
          Say "    Calling SockSelect"                     
      SockSelectRC = SockSelect(,"w.",,TimeOut)
      If Test
        Then
          Say "      SockSelectRC="SockSelectRC
      If SockSelectRC = -1
        Then
          Do
          If Test
            Then
              Say "      ErrNo="ErrNo
          End
      If Test
        Then
          Say "    Calling SockIOctl"                    
      SockIOctlRC = SockIOctl(SocketHandle,"FIONBIO",0)
      If Test
        Then
          Say "      SockIOctlRC="SockIOctlRC
      If SockIOctlRC = -1
        Then
          Do
          If Test 
            Then 
              Say "      ErrNo="ErrNo
          End
      Select
        When SockSelectRC = -1
          Then
            Nop
        When SockSelectRC = 0
          Then
            Do
            RC = -1
            ErrNo = "ETIMEDOUT"
            h_errno = 1541
            End
        When SockSelectRC > 0
          Then 
            RC = 0
        End
      Return RC
    
     
    • Perry Werneck
      Perry Werneck
      2013-08-07

      Hi,

      Why not use the procedure as a function and using the return code to check
      for error?

      For example, replacing...

      SockConnectTimed: Procedure Expose gosaddr. Test errno h_errno
      SocketHandle = Arg(1)
      Address = Arg(2)
      Timeout = Arg(3)

      By...

      SockConnectTimed: Procedure Expose gosaddr. Test errno h_errno

      parse arg SocketHandle, Address, Timeout

      And returning -1 if any call fails...

      if SockConnect(SocketHandle,Address) = -1

      then return -1

      (...)

      if SockSelect(,"w.",,TimeOut) = -1

      then return -1

      (...)

      returning 0 if the connect was ok...

      return 0

      2013/8/7 Chuck Tribolet triblet@users.sf.net

      Thanks. I coded up a quick and dirty SockConnectTimed() that works like
      SockConnect except for taking an additional third timeout parameter. I'll
      pass it along below.
      I have some questions:

      It only works if the second parm is "gosaddr." Is there some way to expose
      the variable
      named in arg(2)? The expose keyword command won't work because it's for
      methods, and
      (arg(1)) on the Procedure's Expose is a syntax error.

      Should I be doing something to flush out the SockConnect when it times out?

      I tried using SockSockErrno() to get the error code, but it terminates the
      program if used.

      SockConnectTimed: Procedure Expose gosaddr. Test errno h_errno
      SocketHandle = Arg(1)
      Address = Arg(2)
      Timeout = Arg(3)
      If Test
      Then
      Say " SockConnectTimed("SocketHandle","Address","Timeout") entered."
      If Test
      Then
      Say " Calling SockIOctl"
      SockIOctlRC = SockIOctl(SocketHandle,"FIONBIO",1)
      If Test
      Then
      Say " SockIOctlRC="SockIOctlRC
      If SockIOctlRC = -1
      Then
      Do
      If Test
      Then
      Say " ErrNo="ErrNo
      End
      If Test
      Then
      Say " Calling SockConnect"
      SockConnectRC = SockConnect(SocketHandle,Address)
      If Test
      Then
      Say " SockConnectRC="SockConnectRC
      If SockConnectRC = -1
      Then
      Do
      If Test
      Then
      Do
      Say " ErrNo="ErrNo
      End
      End
      w.0 = 1
      w.1 = SocketHandle
      If Test
      Then
      Say " Calling SockSelect"
      SockSelectRC = SockSelect(,"w.",,TimeOut)
      If Test
      Then
      Say " SockSelectRC="SockSelectRC
      If SockSelectRC = -1
      Then
      Do
      If Test
      Then
      Say " ErrNo="ErrNo
      End
      If Test
      Then
      Say " Calling SockIOctl"
      SockIOctlRC = SockIOctl(SocketHandle,"FIONBIO",0)
      If Test
      Then
      Say " SockIOctlRC="SockIOctlRC
      If SockIOctlRC = -1
      Then
      Do
      If Test
      Then
      Say " ErrNo="ErrNo
      End
      Select
      When SockSelectRC = -1
      Then
      Nop
      When SockSelectRC = 0
      Then
      Do
      RC = -1
      ErrNo = "ETIMEDOUT"
      h_errno = 1541
      End
      When SockSelectRC > 0
      Then
      RC = 0
      End
      Return RC


      Reducing timeout on SockConnecthttps://sourceforge.net/p/oorexx/discussion/408477/thread/43848ac3/?limit=25#a6fb

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/oorexx/discussion/408477/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

      --
      Perry Werneck
      Brasília/DF

       
      • Chuck Tribolet
        Chuck Tribolet
        2013-08-08

        Why not use the procedure as a function and using the return code to check
        for error?

        That's exactly what the code I posted does. It runs just fine as a function, and
        tries to return the same return codes as SockConnect(). This was to make it easy
        to substitute it for SockConnect. Just change the function name and add the third
        parameter for timeout.