From 039182fef153128aed9461c189489495d2ec357b Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Tue, 18 Oct 2022 22:43:04 +0200 Subject: [PATCH] EOT works out of the box apparently --- src/client.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client.c b/src/client.c index 9661be0..16ec68f 100644 --- a/src/client.c +++ b/src/client.c @@ -101,9 +101,12 @@ void Listener(int sockid) { while (1) { /* Read n bytes at a time, because we don't know how long the message will be */ while ((n = read(sockid, buf, BUF_LEN)) > 0) { - if (n > 0) write(STDOUT_FILENO, buf, n); + write(STDOUT_FILENO, buf, n); + } + if (n < 0) { + fprintf(stderr, "ERROR: read\n"); + break; } - if (n < 0) break; } } @@ -118,7 +121,6 @@ void Sender(int sockid) { /* Read a full line ending with '\n' */ if (fgets(buf, BUF_LEN, stdin) != NULL) { if (strcmp(buf, "exit\n") == 0) break; // break if read 'exit' - if (buf[strlen(buf) - 1] == EOT) break; // break if EOT (^D on Linux), TODO: test this if (strlen(buf) == 1) continue; // user only hit ENTER /* Send the buffer to the server */