summary refs log tree commit diff
path: root/view.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--view.c41
1 files changed, 14 insertions, 27 deletions
diff --git a/view.c b/view.c
index 47c6c5b..b8f8793 100644
--- a/view.c
+++ b/view.c
@@ -19,6 +19,7 @@
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <sys/event.h>
 #include <sys/ioctl.h>
@@ -26,14 +27,13 @@
 #include <termios.h>
 #include <unistd.h>
 
-extern int winch(void);
+static void nop() { }
 
 static struct {
-    int winch;
     int remote;
     int local;
     int input;
-} fd = { -1, -1, STDOUT_FILENO, STDIN_FILENO };
+} fd = { -1, STDOUT_FILENO, STDIN_FILENO };
 
 static struct termios saveTerm;
 static void restoreTerm(void) {
@@ -59,26 +59,26 @@ int main(int argc, char *argv[]) {
     error = tcsetattr(fd.input, TCSADRAIN, &term);
     if (error) err(EX_IOERR, "tcsetattr");
 
-    struct winsize localWindow;
-    error = ioctl(fd.local, TIOCGWINSZ, &localWindow);
-    if (error) err(EX_IOERR, "TIOCGWINSZ");
-    fd.winch = winch();
+    signal(SIGWINCH, nop);
 
     int kq = kqueue();
     if (kq < 0) err(EX_OSERR, "kqueue");
 
-    struct kevent events[3] = {
+    struct kevent events[2] = {
         { .ident = fd.input, .filter = EVFILT_READ, .flags = EV_ADD },
         { .ident = fd.remote, .filter = EVFILT_READ, .flags = EV_ADD },
-        { .ident = fd.winch, .filter = EVFILT_READ, .flags = EV_ADD },
     };
-    int nevents = kevent(kq, events, 3, NULL, 0, NULL);
+    int nevents = kevent(kq, events, 2, NULL, 0, NULL);
     if (nevents < 0) err(EX_OSERR, "kevent");
 
     for (;;) {
         off_t off = lseek(fd.remote, 0, SEEK_SET);
         if (off < 0) err(EX_IOERR, "%s", path);
 
+        struct winsize localWindow;
+        error = ioctl(fd.local, TIOCGWINSZ, &localWindow);
+        if (error) err(EX_IOERR, "TIOCGWINSZ");
+
         // FIXME: Hack spin waiting for remote window.
         struct winsize remoteWindow;
         ssize_t size;
@@ -100,12 +100,9 @@ int main(int argc, char *argv[]) {
                 localWindow.ws_col, localWindow.ws_row,
                 remoteWindow.ws_col, remoteWindow.ws_row
             );
-
-            ssize_t size = read(fd.winch, &localWindow, sizeof(localWindow));
-            if (size < 0) err(EX_IOERR, "read(%d)", fd.winch);
-            if ((size_t)size < sizeof(localWindow)) {
-                errx(EX_IOERR, "short read(%d)", fd.winch);
-            }
+            sigset_t mask;
+            sigemptyset(&mask);
+            sigsuspend(&mask);
             continue;
         }
 
@@ -114,10 +111,9 @@ int main(int argc, char *argv[]) {
             struct kevent event;
             int nevents = kevent(kq, NULL, 0, &event, 1, NULL);
             if (nevents < 0) {
-                if (errno == EINTR) continue;
+                if (errno == EINTR) break;
                 err(EX_OSERR, "kevent");
             }
-            if (!nevents) continue;
 
             if (event.ident == (uintptr_t)fd.input) {
                 ssize_t size = read(fd.input, buf, sizeof(buf));
@@ -135,15 +131,6 @@ int main(int argc, char *argv[]) {
                 if (writeSize < 0) err(EX_IOERR, "write(%d)", fd.local);
                 if (writeSize < readSize) errx(EX_IOERR, "short write(%d)", fd.local);
             }
-
-            if (event.ident == (uintptr_t)fd.winch) {
-                ssize_t size = read(fd.winch, &localWindow, sizeof(localWindow));
-                if (size < 0) err(EX_IOERR, "read(%d)", fd.winch);
-                if ((size_t)size < sizeof(localWindow)) {
-                    errx(EX_IOERR, "short read(%d)", fd.winch);
-                }
-                break;
-            }
         }
     }
 }