diff options
author | Audrius Butkevicius <audrius.butkevicius@elastichosts.com> | 2014-02-12 16:53:18 +0000 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2014-02-12 18:21:16 +0100 |
commit | a277dd92776c5c18d4e08a555e169c46cf75ff94 (patch) | |
tree | 5873ed8615e8b0d52ac83337cd4b14d528276d34 /src/channels.c | |
parent | 370d4b014d22d6ae9229498f75a4f6d28d0d1614 (diff) | |
download | libssh-a277dd92776c5c18d4e08a555e169c46cf75ff94.tar.gz libssh-a277dd92776c5c18d4e08a555e169c46cf75ff94.tar.xz libssh-a277dd92776c5c18d4e08a555e169c46cf75ff94.zip |
Add session/channel byte/packet counters
Signed-off-by: Audrius Butkevicius <audrius.butkevicius@elastichosts.com>
Diffstat (limited to 'src/channels.c')
-rw-r--r-- | src/channels.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/channels.c b/src/channels.c index b6f59f5f..7a72cfe4 100644 --- a/src/channels.c +++ b/src/channels.c @@ -555,6 +555,9 @@ SSH_PACKET_CALLBACK(channel_rcv_data){ is_stderr, channel->callbacks->userdata); if(rest > 0) { + if (channel->counter != NULL) { + channel->counter->in_bytes += rest; + } buffer_pass_bytes(buf, rest); } if (channel->local_window + buffer_get_rest_len(buf) < WINDOWLIMIT) { @@ -1406,6 +1409,9 @@ static int channel_write_common(ssh_channel channel, channel->remote_window -= effectivelen; len -= effectivelen; data = ((uint8_t*)data + effectivelen); + if (channel->counter != NULL) { + channel->counter->out_bytes += effectivelen; + } } /* it's a good idea to flush the socket now */ @@ -2843,6 +2849,9 @@ int ssh_channel_read_timeout(ssh_channel channel, len = (len > count ? count : len); memcpy(dest, buffer_get_rest(stdbuf), len); buffer_pass_bytes(stdbuf,len); + if (channel->counter != NULL) { + channel->counter->in_bytes += len; + } /* Authorize some buffering while userapp is busy */ if (channel->local_window < WINDOWLIMIT) { if (grow_window(session, channel, 0) < 0) { @@ -3269,6 +3278,31 @@ int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, return 0; } +/** + * @brief Set the channel data counter. + * + * @code + * struct ssh_counter_struct counter = { + * .in_bytes = 0, + * .out_bytes = 0, + * .in_packets = 0, + * .out_packets = 0 + * }; + * + * ssh_channel_set_counter(channel, &counter); + * @endcode + * + * @param[in] channel The SSH channel. + * + * @param[in] counter Counter for bytes handled by the channel. + */ +void ssh_channel_set_counter(ssh_channel channel, + ssh_counter counter) { + if (channel != NULL) { + channel->counter = counter; + } +} + #if WITH_SERVER /** * @brief Blocking write on a channel stderr. |