Subject: [libssh2] #183: Check if keepalive reply came in if want_reply == 1, set error if not

[libssh2] #183: Check if keepalive reply came in if want_reply == 1, set error if not

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Thu, 12 Aug 2010 00:10:32 -0000

#183: Check if keepalive reply came in if want_reply == 1, set error if not
----------------------------------+-----------------------------------------
 Reporter: dringdahl | Owner:
     Type: enhancement | Status: new
 Priority: normal | Milestone: 1.2.6
Component: misc | Version: 1.2.6
 Keywords: keepalive want_reply | Blocks:
Blocked By: |
----------------------------------+-----------------------------------------
 This is the patch against v1.2.6 that I am using. I'm sure it could use
 some improvement, such as using a better error code (perhaps creating a
 new error code).

 Use this as you wish.

 {{{
 diff -urwb libssh2-1.2.6/src/keepalive.c
 libssh2-1.2.6-luminex/src/keepalive.c
 --- libssh2-1.2.6/src/keepalive.c Thu Jun 3 04:52:02 2010
 +++ libssh2-1.2.6-luminex/src/keepalive.c Tue Aug 3 13:26:46 2010
 @@ -51,6 +51,7 @@
      else
          session->keepalive_interval = interval;
      session->keepalive_want_reply = want_reply ? 1 : 0;
 + session->keepalive_got_reply = want_reply ? 1 : 0;
  }

  LIBSSH2_API int
 @@ -68,6 +69,12 @@
      now = time (NULL);

      if (session->keepalive_last_sent + session->keepalive_interval <=
 now) {
 + if (session->keepalive_got_reply == 0) {
 + _libssh2_error(session, LIBSSH2_ERROR_TIMEOUT,
 + "Did not receive keepalive reply");
 + return LIBSSH2_ERROR_TIMEOUT;
 + }
 + session->keepalive_got_reply = 0;
  /* Format is "SSH_MSG_GLOBAL_REQUEST || 4-byte len || str || want-reply".
 */
          unsigned char keepalive_data[]
              = "\x50\x00\x00\x00\x15keepalive_at_libssh2.orgW";
 diff -urwb libssh2-1.2.6/src/libssh2_priv.h
 libssh2-1.2.6-luminex/src/libssh2_priv.h
 --- libssh2-1.2.6/src/libssh2_priv.h Thu Jun 3 04:52:02 2010
 +++ libssh2-1.2.6-luminex/src/libssh2_priv.h Tue Aug 3 12:53:21 2010
 @@ -923,6 +923,7 @@
      /* Keepalive variables used by keepalive.c. */
      int keepalive_interval;
      int keepalive_want_reply;
 + int keepalive_got_reply;
      time_t keepalive_last_sent;
  };

 diff -urwb libssh2-1.2.6/src/packet.c libssh2-1.2.6-luminex/src/packet.c
 --- libssh2-1.2.6/src/packet.c Fri May 21 05:09:41 2010
 +++ libssh2-1.2.6-luminex/src/packet.c Tue Aug 3 13:06:39 2010
 @@ -599,6 +599,16 @@
          }
          break;

 + case SSH_MSG_REQUEST_FAILURE:
 + {
 + _libssh2_debug(session,
 + LIBSSH2_TRACE_CONN,
 + "Received keepalive reply");
 +
 + session->keepalive_got_reply = 1;
 + }
 + break;
 +
          case SSH_MSG_CHANNEL_EXTENDED_DATA:
              /* streamid(4) */
              session->packAdd_data_head += 4;

 }}}

-- 
Ticket URL: <http://trac.libssh2.org/ticket/183>
libssh2 <http://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-08-12