summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-05-13 15:05:42 -0400
committerJune McEnroe <june@causal.agency>2018-05-13 15:05:42 -0400
commitd67d19fe7f899dd8bd48ea68cbe8dff926f31956 (patch)
treef36925106a48fed0f644d4113468e5534e8c4b15 /bin
parentAdd modem (diff)
downloadsrc-d67d19fe7f899dd8bd48ea68cbe8dff926f31956.tar.gz
src-d67d19fe7f899dd8bd48ea68cbe8dff926f31956.zip
Clean up modem loop
Diffstat (limited to 'bin')
-rw-r--r--bin/modem.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/bin/modem.c b/bin/modem.c
index 47a4ddaf..4b5e8eb2 100644
--- a/bin/modem.c
+++ b/bin/modem.c
@@ -65,30 +65,22 @@ int main(int argc, char *argv[]) {
 		err(EX_NOINPUT, "%s", argv[1]);
 	}
 
-	for (;;) {
-		usleep(8 * 1000000 / BAUD_RATE);
-
-		struct pollfd fds[2] = {
-			{ .events = POLLIN, .fd = STDIN_FILENO },
-			{ .events = POLLIN, .fd = pty },
-		};
-		int n = poll(fds, 2, -1);
-		if (n < 0) err(EX_IOERR, "poll");
-
+	char c;
+	struct pollfd fds[2] = {
+		{ .events = POLLIN, .fd = STDIN_FILENO },
+		{ .events = POLLIN, .fd = pty },
+	};
+	while (usleep(8 * 1000000 / BAUD_RATE), 0 < poll(fds, 2, -1)) {
 		if (fds[0].revents) {
-			char c;
 			ssize_t size = read(STDIN_FILENO, &c, 1);
 			if (size < 0) err(EX_IOERR, "read(%d)", STDIN_FILENO);
-
 			size = write(pty, &c, 1);
 			if (size < 0) err(EX_IOERR, "write(%d)", pty);
 		}
 
 		if (fds[1].revents) {
-			char c;
 			ssize_t size = read(pty, &c, 1);
 			if (size < 0) err(EX_IOERR, "read(%d)", pty);
-
 			size = write(STDOUT_FILENO, &c, 1);
 			if (size < 0) err(EX_IOERR, "write(%d)", STDOUT_FILENO);
 		}
@@ -98,4 +90,5 @@ int main(int argc, char *argv[]) {
 		if (dead < 0) err(EX_OSERR, "waitpid");
 		if (dead) return WIFEXITED(status) ? WEXITSTATUS(status) : EX_SOFTWARE;
 	}
+	err(EX_IOERR, "poll");
 }
ut.c?id=5c4ecb5a0f8a8a532192d066f792c1f2bfbc414c&follow=1'>Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe 2022-02-18Implement new line editing "library"June McEnroe 2022-02-18Simplify cursor positioning in inputJune McEnroe 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe