]> git.meshlink.io Git - utcp/commitdiff
Show total bytes sent/received in test program.
authorGuus Sliepen <guus@meshlink.io>
Sun, 18 Oct 2015 11:41:50 +0000 (13:41 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 10:01:41 +0000 (12:01 +0200)
test.c

diff --git a/test.c b/test.c
index d3319328c8919dcb3a0429447761be5c18810fa8..0f7f33368dc1def41192c494b4a29ea918298eac 100644 (file)
--- 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;
 }