From: Michael D. Lowis Date: Thu, 10 Dec 2020 21:11:08 +0000 (-0500) Subject: took a first pass at implementing dial X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=68737770318f2ca4ec26c0623933e7c01f552fba;p=proto%2Faos.git took a first pass at implementing dial --- diff --git a/bin/dial.c b/bin/dial.c index 3429c39..ef5373f 100644 --- a/bin/dial.c +++ b/bin/dial.c @@ -1,5 +1,6 @@ #include #include +#include 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