From b1117d6871e6b8babfe8792781480162d7bb6048 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 18 Oct 2015 13:41:50 +0200 Subject: [PATCH] Show total bytes sent/received in test program. --- test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test.c b/test.c index d331932..0f7f333 100644 --- a/test.c +++ b/test.c @@ -26,6 +26,9 @@ long dropfrom; long dropto; double dropin; double dropout; +long total_out; +long total_in; + void debug(const char *format, ...) { struct timeval now; @@ -63,6 +66,7 @@ ssize_t do_send(struct utcp *utcp, const void *data, size_t len) { if(outpktno < dropto && outpktno >= dropfrom && drand48() < dropout) return len; + total_out += len; ssize_t result = send(s, data, len, MSG_DONTWAIT); if(result <= 0) debug("Error sending UDP packet: %s\n", strerror(errno)); @@ -140,7 +144,7 @@ int main(int argc, char *argv[]) { if(fds[0].revents) { fds[0].revents = 0; - debug("stdin"); + debug("stdin\n"); ssize_t len = read(0, buf, max); if(len <= 0) { fds[0].fd = -1; @@ -173,8 +177,10 @@ int main(int argc, char *argv[]) { if(!connect(s, (struct sockaddr *)&ss, sl)) connected = true; inpktno++; - if(inpktno >= dropto || inpktno < dropfrom || drand48() >= dropin) + if(inpktno >= dropto || inpktno < dropfrom || drand48() >= dropin) { + total_in += len; utcp_recv(u, buf, len); + } } timeout = utcp_timeout(u); @@ -183,5 +189,7 @@ int main(int argc, char *argv[]) { utcp_close(c); utcp_exit(u); + debug("Total bytes in: %ld, out: %ld\n", total_in, total_out); + return 0; } -- 2.39.5