]> git.meshlink.io Git - utcp/commitdiff
Minor changes in the test program.
authorGuus Sliepen <guus@meshlink.io>
Sun, 18 Oct 2015 18:18:49 +0000 (20:18 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 10:03:43 +0000 (12:03 +0200)
- Add one to the timeout in milliseconds, to prevent roundoff errors from
  causing us to busy-loop unnecessarily.
- Log what we are polling for and what the timeout is.

test.c

diff --git a/test.c b/test.c
index 0f7f33368dc1def41192c494b4a29ea918298eac..1df172efa56556443bfa5c6ec913f9e9014b0035 100644 (file)
--- a/test.c
+++ b/test.c
@@ -132,15 +132,17 @@ int main(int argc, char *argv[]) {
        struct timeval timeout = utcp_timeout(u);
 
        while(!connected || utcp_is_active(u)) {
-               debug("\n");
                size_t max = c ? utcp_get_sndbuf_free(c) : 0;
                if(max > sizeof buf)
                        max = sizeof buf;
 
+               int timeout_ms = timeout.tv_sec * 1000 + timeout.tv_usec / 1000 + 1;
+
+               debug("polling, dir = %d, timeout = %d\n", dir, timeout_ms);
                if((dir & DIR_READ) && max)
-                       poll(fds, 2, timeout.tv_sec * 1000 + timeout.tv_usec / 1000);
+                       poll(fds, 2, timeout_ms);
                else
-                       poll(fds + 1, 1, timeout.tv_sec * 1000 + timeout.tv_usec / 1000);
+                       poll(fds + 1, 1, timeout_ms);
 
                if(fds[0].revents) {
                        fds[0].revents = 0;
@@ -165,7 +167,7 @@ int main(int argc, char *argv[]) {
 
                if(fds[1].revents) {
                        fds[1].revents = 0;
-                       debug("netout\n");
+                       debug("netin\n");
                        struct sockaddr_storage ss;
                        socklen_t sl = sizeof ss;
                        int len = recvfrom(s, buf, sizeof buf, MSG_DONTWAIT, (struct sockaddr *)&ss, &sl);