summaryrefslogtreecommitdiffstats
path: root/src/send.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-09-03 21:53:45 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-09-03 21:53:45 +0200
commit02c1cb4ce21dca6cc63545cd5bd7ed621ed61529 (patch)
tree7c953fbb9c062936b66f63a8d95b5702da7ece8e /src/send.c
parentf0fa4e0c9085e0b4476b144185040ce9fbdc11e3 (diff)
downloadfastd-02c1cb4ce21dca6cc63545cd5bd7ed621ed61529.tar
fastd-02c1cb4ce21dca6cc63545cd5bd7ed621ed61529.zip
Add packet/byte statistics
Diffstat (limited to 'src/send.c')
-rw-r--r--src/send.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/send.c b/src/send.c
index c624405..b1a6107 100644
--- a/src/send.c
+++ b/src/send.c
@@ -64,7 +64,14 @@ static inline void add_pktinfo(struct msghdr *msg, const fastd_peer_address_t *l
}
}
-static void send_type(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, uint8_t packet_type, fastd_buffer_t buffer) {
+static inline void count_stat(fastd_stats_t *stats, size_t stat_size) {
+ if (stat_size) {
+ stats->packets++;
+ stats->bytes += stat_size;
+ }
+}
+
+static void send_type(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, uint8_t packet_type, fastd_buffer_t buffer, size_t stat_size) {
if (!sock)
exit_bug(ctx, "send: sock == NULL");
@@ -122,28 +129,34 @@ static void send_type(fastd_context_t *ctx, const fastd_socket_t *sock, const fa
case EWOULDBLOCK:
#endif
pr_debug2_errno(ctx, "sendmsg");
+ count_stat(&ctx->tx_dropped, stat_size);
break;
case ENETDOWN:
case ENETUNREACH:
case EHOSTUNREACH:
pr_debug_errno(ctx, "sendmsg");
+ count_stat(&ctx->tx_error, stat_size);
break;
default:
pr_warn_errno(ctx, "sendmsg");
+ count_stat(&ctx->tx_error, stat_size);
}
}
+ else {
+ count_stat(&ctx->tx, stat_size);
+ }
fastd_buffer_free(buffer);
}
-void fastd_send(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_buffer_t buffer) {
- send_type(ctx, sock, local_addr, remote_addr, PACKET_DATA, buffer);
+void fastd_send(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_buffer_t buffer, size_t stat_size) {
+ send_type(ctx, sock, local_addr, remote_addr, PACKET_DATA, buffer, stat_size);
}
void fastd_send_handshake(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_buffer_t buffer) {
- send_type(ctx, sock, local_addr, remote_addr, PACKET_HANDSHAKE, buffer);
+ send_type(ctx, sock, local_addr, remote_addr, PACKET_HANDSHAKE, buffer, 0);
}
void fastd_send_all(fastd_context_t *ctx, fastd_peer_t *source_peer, fastd_buffer_t buffer) {