EOT works out of the box apparently

This commit is contained in:
flyingscorpio@clevo 2022-10-18 22:43:04 +02:00
parent c8b2e5ee0f
commit 039182fef1

View file

@ -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 */