Subject: Re: [PATCH] - datacount

Re: [PATCH] - datacount

From: Lubos Uhliarik <uhliarik_at_seznam.cz>
Date: Wed, 13 Aug 2014 16:17:40 +0200

Hi Mikhail,

thank you for your fast answer. I didn't make this patch, so I apologies
for any errors. I removed that garbage, as you advised me. Fixed patch
is below.

Regards,

Lubos

Signed-off-by: Lubos Uhliarik <uhliarik_at_seznam.cz>

---
diff -Naur libssh2-1.4.3/include/libssh2.h
libssh2-1.4.3_datacount/include/libssh2.h
--- libssh2-1.4.3/include/libssh2.h	2012-11-27 22:45:21.000000000 +0100
+++ libssh2-1.4.3_datacount/include/libssh2.h	2014-08-13
16:01:51.571211593 +0200
@@ -241,10 +241,10 @@
 /* I/O callbacks */
 #define LIBSSH2_RECV_FUNC(name)  ssize_t name(libssh2_socket_t socket,
\
                                               void *buffer, size_t
length, \
-                                              int flags, void
**abstract)
+                                              int flags, void
**abstract, LIBSSH2_SESSION *session)
 #define LIBSSH2_SEND_FUNC(name)  ssize_t name(libssh2_socket_t socket,
\
                                               const void *buffer,
size_t length,\
-                                              int flags, void
**abstract)
+                                              int flags, void
**abstract, LIBSSH2_SESSION *session)
 
 /* libssh2_session_callback_set() constants */
 #define LIBSSH2_CALLBACK_IGNORE             0
@@ -1157,6 +1157,12 @@
 LIBSSH2_API int libssh2_keepalive_send (LIBSSH2_SESSION *session,
                                         int *seconds_to_next);
 
+LIBSSH2_API long long 
+libssh2_session_recv_data(LIBSSH2_SESSION *session);
+
+LIBSSH2_API long long
+libssh2_session_send_data(LIBSSH2_SESSION *session);
+
 /* NOTE NOTE NOTE
    libssh2_trace() has no function in builds that aren't built with
debug
    enabled
diff -Naur libssh2-1.4.3/src/libssh2_priv.h
libssh2-1.4.3_datacount/src/libssh2_priv.h
--- libssh2-1.4.3/src/libssh2_priv.h	2012-10-08 14:54:30.000000000 +0200
+++ libssh2-1.4.3_datacount/src/libssh2_priv.h	2014-08-13
16:05:15.232059547 +0200
@@ -184,9 +184,9 @@
                       (channel), &(channel)->abstract)
 
 #define LIBSSH2_SEND_FD(session, fd, buffer, length, flags) \
-    session->send(fd, buffer, length, flags, &session->abstract)
+    session->send(fd, buffer, length, flags, &session->abstract,
session)
 #define LIBSSH2_RECV_FD(session, fd, buffer, length, flags) \
-    session->recv(fd, buffer, length, flags, &session->abstract)
+    session->recv(fd, buffer, length, flags, &session->abstract,
session)
 
 #define LIBSSH2_SEND(session, buffer, length, flags)  \
     LIBSSH2_SEND_FD(session, session->socket_fd, buffer, length, flags)
@@ -809,6 +809,8 @@
     int keepalive_interval;
     int keepalive_want_reply;
     time_t keepalive_last_sent;
+    long long recv_data;
+    long long send_data;
 };
 
 /* session.state bits */
@@ -1000,9 +1002,9 @@
 #define SSH_OPEN_RESOURCE_SHORTAGE           4
 
 ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer,
-                      size_t length, int flags, void **abstract);
+                      size_t length, int flags, void **abstract,
LIBSSH2_SESSION *session);
 ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer,
-                      size_t length, int flags, void **abstract);
+                      size_t length, int flags, void **abstract,
LIBSSH2_SESSION *session);
 
 #define LIBSSH2_READ_TIMEOUT 60 /* generic timeout in seconds used when
                                    waiting for more data to arrive */
diff -Naur libssh2-1.4.3/src/misc.c libssh2-1.4.3_datacount/src/misc.c
--- libssh2-1.4.3/src/misc.c	2011-08-25 19:59:47.000000000 +0200
+++ libssh2-1.4.3_datacount/src/misc.c	2014-08-13 16:01:51.571211593
+0200
@@ -94,7 +94,7 @@
  * Replacement for the standard recv, return -errno on failure.
  */
 ssize_t
-_libssh2_recv(libssh2_socket_t sock, void *buffer, size_t length, int
flags, void **abstract)
+_libssh2_recv(libssh2_socket_t sock, void *buffer, size_t length, int
flags, void **abstract, LIBSSH2_SESSION *session)
 {
     ssize_t rc = recv(sock, buffer, length, flags);
 #ifdef WIN32
@@ -117,6 +117,7 @@
             return -errno;
     }
 #endif
+    session->recv_data += rc;
     return rc;
 }
 
@@ -126,7 +127,7 @@
  */
 ssize_t
 _libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length,
-              int flags, void **abstract)
+              int flags, void **abstract, LIBSSH2_SESSION *session)
 {
     ssize_t rc = send(sock, buffer, length, flags);
 #ifdef WIN32
@@ -143,6 +144,7 @@
     if (rc < 0 )
         return -errno;
 #endif
+    session->send_data += rc;
     return rc;
 }
 
diff -Naur libssh2-1.4.3/src/session.c
libssh2-1.4.3_datacount/src/session.c
--- libssh2-1.4.3/src/session.c	2012-07-25 01:03:27.000000000 +0200
+++ libssh2-1.4.3_datacount/src/session.c	2014-08-13 16:01:51.571211593
+0200
@@ -1749,3 +1749,20 @@
 
     return (const char *) session->remote.banner;
 }
+
+LIBSSH2_API long long 
+libssh2_session_recv_data(LIBSSH2_SESSION *session)
+{
+    long long recv;
+    recv = session->recv_data;
+    session->recv_data = 0;
+    return recv;
+}
+
+LIBSSH2_API long long
+libssh2_session_send_data(LIBSSH2_SESSION *session){
+    long long send;
+    send = session->send_data;
+    session->send_data = 0;
+    return send;
+}
Mikhail Gusarov píše v St 13. 08. 2014 v 15:42 +0200:
> Hi Lubos,
> 
> >  /* Hostkey Types */
> > -#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN          0
> > -#define LIBSSH2_HOSTKEY_TYPE_RSA          1
> > -#define LIBSSH2_HOSTKEY_TYPE_DSS          2
> > +#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN                       0
> > +#define LIBSSH2_HOSTKEY_TYPE_RSA                           1
> > +#define LIBSSH2_HOSTKEY_TYPE_DSS                           2
> 
> Please remove this hunk.
> 
> > +LIBSSH2_API long long
> > +libssh2_session_send_data(LIBSSH2_SESSION *session){
> > +    long long send;
> > +    send = session->send_data;
> > +    session->send_data = 0;
> > +    return send;
> > +}
> > \ No newline at end of file
> 
> And add a missing newline.
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2014-08-13