From: Guus Sliepen Date: Sun, 18 Oct 2015 11:41:50 +0000 (+0200) Subject: Show total bytes sent/received in test program. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=b1117d6871e6b8babfe8792781480162d7bb6048;p=utcp Show total bytes sent/received in test program. --- 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; }