[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6 of 6 V1] Implement channel byte counter
[Thread Prev] | [Thread Next]
- Subject: [PATCH 6 of 6 V1] Implement channel byte counter
- From: Audrius Butkevicius <audrius.butkevicius@xxxxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Wed, 15 Jan 2014 16:43:06 +0000
- To: libssh@xxxxxxxxxx
- Cc: audrius.butkevicius@xxxxxxxxx
include/libssh/channels.h | 3 +++
include/libssh/counters.h | 23 +++++++++++++++++++++++
src/channels.c | 6 ++++++
src/channels1.c | 2 ++
src/counters.c | 9 +++++++++
5 files changed, 43 insertions(+), 0 deletions(-)
# HG changeset patch
# User Audrius Butkevicius <audrius.butkevicius@xxxxxxxxxxxxxxxx>
# Date 1389804180 0
# Wed Jan 15 16:43:00 2014 +0000
# Node ID 27f2708c0d3c3fa8c0d16809819dc5ed81eefbf6
# Parent 3b842c373559f9d51b3e3485a59a6456545e74b5
Implement channel byte counter
diff --git a/include/libssh/channels.h b/include/libssh/channels.h
--- a/include/libssh/channels.h
+++ b/include/libssh/channels.h
@@ -21,6 +21,7 @@
#ifndef CHANNELS_H_
#define CHANNELS_H_
#include "libssh/priv.h"
+#include "libssh/counters.h"
/** @internal
* Describes the different possible states in a
@@ -75,6 +76,8 @@
int exit_status;
enum ssh_channel_request_state_e request_state;
ssh_channel_callbacks callbacks;
+ /* counters */
+ ssh_bytes_counter bytes_counter;
};
SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf);
diff --git a/include/libssh/counters.h b/include/libssh/counters.h
--- a/include/libssh/counters.h
+++ b/include/libssh/counters.h
@@ -95,6 +95,29 @@
ssh_bytes_counter rcounter,
ssh_packet_counter pcounter);
+/**
+ * @brief Set the channel data counters.
+ *
+ * This functions sets the counter structures to be used to calculate data
+ * which come in and go out through the channel at various points in time.
+ *
+ * @code
+ * struct ssh_byte_counter_struct bcounter = {
+ * .in_bytes = 0,
+ * .out_bytes = 0
+ * };
+ *
+ * ssh_set_channel_counters(channel, &bcounter);
+ * @endcode
+ *
+ * @param channel The channel to set the counter structures.
+ *
+ * @param bcounter The byte counter structure for raw data passed to the
+ * channel.
+ */
+LIBSSH_API void ssh_set_channel_counters(ssh_channel channel,
+ ssh_bytes_counter bcounter);
+
/** @} */
#ifdef __cplusplus
diff --git a/src/channels.c b/src/channels.c
--- a/src/channels.c
+++ b/src/channels.c
@@ -555,6 +555,8 @@
is_stderr,
channel->callbacks->userdata);
if(rest > 0) {
+ if (channel->bytes_counter)
+ channel->bytes_counter->in_bytes += rest;
buffer_pass_bytes(buf, rest);
}
if (channel->local_window + buffer_get_rest_len(buf) < WINDOWLIMIT) {
@@ -1390,6 +1392,8 @@
channel->remote_window -= effectivelen;
len -= effectivelen;
data = ((uint8_t*)data + effectivelen);
+ if (channel->bytes_counter)
+ channel->bytes_counter->out_bytes += effectivelen;
}
/* it's a good idea to flush the socket now */
@@ -2799,6 +2803,8 @@
len = (len > count ? count : len);
memcpy(dest, buffer_get_rest(stdbuf), len);
buffer_pass_bytes(stdbuf,len);
+ if (channel->bytes_counter)
+ channel->bytes_counter->in_bytes += len;
/* Authorize some buffering while userapp is busy */
if (channel->local_window < WINDOWLIMIT) {
if (grow_window(session, channel, 0) < 0) {
diff --git a/src/channels1.c b/src/channels1.c
--- a/src/channels1.c
+++ b/src/channels1.c
@@ -367,6 +367,8 @@
return -1;
}
ssh_handle_packets(session, SSH_TIMEOUT_NONBLOCKING);
+ if (channel->bytes_counter)
+ channel->bytes_counter->out_bytes += effectivelen;
}
if (ssh_blocking_flush(session,SSH_TIMEOUT_USER) == SSH_ERROR)
return -1;
diff --git a/src/counters.c b/src/counters.c
--- a/src/counters.c
+++ b/src/counters.c
@@ -23,6 +23,7 @@
#include "libssh/counters.h"
#include "libssh/session.h"
+#include "libssh/channels.h"
void ssh_set_session_counters(ssh_session session, ssh_bytes_counter scounter,
ssh_bytes_counter rcounter,
@@ -34,3 +35,11 @@
session->raw_byte_counter = rcounter;
session->packet_counter = pcounter;
}
+
+void ssh_set_channel_counters(ssh_channel channel,
+ ssh_bytes_counter bcounter) {
+ if (channel == NULL)
+ return;
+
+ channel->bytes_counter = bcounter;
+}
| [PATCH 0 of 6 V1] Counters | Audrius Butkevicius <audrius.butkevicius@xxxxxxxxxxxxxxxx> |