]> git.meshlink.io Git - utcp/commitdiff
Clarify read/write direction in test program.
authorGuus Sliepen <guus@meshlink.io>
Sun, 11 Oct 2015 14:21:22 +0000 (16:21 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 09:53:27 +0000 (11:53 +0200)
test.c

diff --git a/test.c b/test.c
index 75fce79dfd16d8697f32544a5e0a64c98e448aed..8ad46c63f49eada35109e303582ed121e8444953 100644 (file)
--- a/test.c
+++ b/test.c
 
 #include "utcp.h"
 
+#define DIR_READ 1
+#define DIR_WRITE 2
+
 struct utcp_connection *c;
-int dir = 3;
+int dir = DIR_READ | DIR_WRITE;
 bool running = true;
 double dropin;
 double dropout;
@@ -25,7 +28,7 @@ ssize_t do_recv(struct utcp_connection *c, const void *data, size_t len) {
                        fprintf(stderr, "Error: %s\n", strerror(errno));
                        dir = 0;
                } else {
-                       dir &= ~2;
+                       dir &= ~DIR_WRITE;
                        fprintf(stderr, "Connection closed by peer\n");
                }
                return -1;
@@ -110,7 +113,7 @@ int main(int argc, char *argv[]) {
                if(max > sizeof buf)
                        max = sizeof buf;
 
-               if((dir & 1) && max)
+               if((dir & DIR_READ) && max)
                        poll(fds, 2, timeout.tv_sec * 1000 + timeout.tv_usec / 1000);
                else
                        poll(fds + 1, 1, timeout.tv_sec * 1000 + timeout.tv_usec / 1000);
@@ -121,7 +124,7 @@ int main(int argc, char *argv[]) {
                        ssize_t len = read(0, buf, max);
                        if(len <= 0) {
                                fds[0].fd = -1;
-                               dir &= ~1;
+                               dir &= ~DIR_READ;
                                if(c)
                                        utcp_shutdown(c, SHUT_WR);
                                if(len == -1)