[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4 of 6 V1] Implement session packet counter
[Thread Prev] | [Thread Next]
- Subject: [PATCH 4 of 6 V1] Implement session packet counter
- From: Audrius Butkevicius <audrius.butkevicius@xxxxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Wed, 15 Jan 2014 16:43:04 +0000
- To: libssh@xxxxxxxxxx
- Cc: audrius.butkevicius@xxxxxxxxx
include/libssh/counters.h | 13 +++++++++++-- include/libssh/session.h | 1 + src/counters.c | 4 +++- src/packet.c | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) # HG changeset patch # User Audrius Butkevicius <audrius.butkevicius@xxxxxxxxxxxxxxxx> # Date 1389803772 0 # Wed Jan 15 16:36:12 2014 +0000 # Node ID 9e462bb4ad281e6b8f8f278726ec601596c35c21 # Parent 754710d2feba31833ecdd111b0a9948549bcbb5a Implement session packet counter diff --git a/include/libssh/counters.h b/include/libssh/counters.h --- a/include/libssh/counters.h +++ b/include/libssh/counters.h @@ -67,15 +67,24 @@ * .out_bytes = 0 * }; * - * ssh_set_session_counters(session, &scounter); + * struct ssh_packet_counter_struct pcounter = { + * .in_packets = 0, + * .out_packets = 0 + * }; + * + * ssh_set_session_counters(session, &scounter, &pcounter); * @endcode * * @param session The session to set the counter structures. * * @param scounter The byte counter structure for data passed to sockets. + * + * @param pcounter The packet counter structure for SSH packets handled by + * the session. */ LIBSSH_API void ssh_set_session_counters(ssh_session session, - ssh_bytes_counter scounter); + ssh_bytes_counter scounter, + ssh_packet_counter pcounter); /** @} */ diff --git a/include/libssh/session.h b/include/libssh/session.h --- a/include/libssh/session.h +++ b/include/libssh/session.h @@ -191,6 +191,7 @@ /* counters */ ssh_bytes_counter socket_byte_counter; + ssh_packet_counter packet_counter; }; /** @internal diff --git a/src/counters.c b/src/counters.c --- a/src/counters.c +++ b/src/counters.c @@ -24,9 +24,11 @@ #include "libssh/counters.h" #include "libssh/session.h" -void ssh_set_session_counters(ssh_session session, ssh_bytes_counter scounter) { +void ssh_set_session_counters(ssh_session session, ssh_bytes_counter scounter, + ssh_packet_counter pcounter) { if (session == NULL) return; session->socket_byte_counter = scounter; + session->packet_counter = pcounter; } diff --git a/src/packet.c b/src/packet.c --- a/src/packet.c +++ b/src/packet.c @@ -305,6 +305,8 @@ #endif /* WITH_ZLIB */ payloadsize = buffer_get_rest_len(session->in_buffer); session->recv_seq++; + if (session->packet_counter) + session->packet_counter->in_packets++; /* * We don't want to rewrite a new packet while still executing the @@ -554,6 +556,8 @@ rc = ssh_packet_write(session); session->send_seq++; + if (session->packet_counter) + session->packet_counter->out_packets++; SSH_LOG(SSH_LOG_PACKET, "packet: wrote [len=%d,padding=%hhd,comp=%d,payload=%d]",
[PATCH 0 of 6 V1] Counters | Audrius Butkevicius <audrius.butkevicius@xxxxxxxxxxxxxxxx> |