#include <liba.h>
#include <libnet.h>
+#include <sys/poll.h>
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