]> git.mdlowis.com Git - proto/aos.git/commitdiff
took a first pass at implementing dial
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 10 Dec 2020 21:11:08 +0000 (16:11 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 10 Dec 2020 21:11:08 +0000 (16:11 -0500)
bin/dial.c

index 3429c39b8daf6f62ec46a54d8e7d7b52fc583126..ef5373f1dd88e0143bf16283704fddee1d4a9472 100644 (file)
@@ -1,5 +1,6 @@
 #include <liba.h>
 #include <libnet.h>
+#include <sys/poll.h>
 
 int main(int argc, char** argv)
 {
@@ -9,16 +10,34 @@ int main(int argc, char** argv)
         return 1;
     }
 
-    int fd = netdial(argv[1]);
-    if (argc > 2)
-    {
-        /* execute command with socket as stdio */
-    }
-    else
+    int sockfd = netdial(argv[1]);
+
+    char buf[8192];
+    struct pollfd fds[] = {
+        { .fd = sockfd,       .events = POLLIN },
+        { .fd = STDIN_FILENO, .events = POLLIN },
+    };
+
+    while(1)
     {
-        /* copy data to/from stdio */
+        if (poll(fds, nelem(fds), -1) < 0)
+        {
+            fatal("poll():");
+        }
+
+        if (fds[0].revents & POLLIN)
+        {
+            write(fds[1].fd, buf, read(fds[0].fd, buf, sizeof(buf)));
+            fds[0].revents = 0;
+        }
+
+        if (fds[1].revents & POLLIN)
+        {
+            write(fds[0].fd, buf, read(fds[1].fd, buf, sizeof(buf)));
+            fds[0].revents = 0;
+        }
     }
-    close(fd);
+    close(sockfd);
 
     return 0;
 }
\ No newline at end of file