diff options
| author | cashmere <cashmere@autistici.org> | 2026-06-30 13:22:55 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-06-30 13:22:55 +0200 |
| commit | 9b1156e6735c5212b691069f0d9b3a0434fa7e9e (patch) | |
| tree | ba3ed039e21cb19446891b727dac1cf459a56499 | |
| parent | f54df76327cdadee5b1450fd731897f6a5d2d368 (diff) | |
| download | telnet-9b1156e6735c5212b691069f0d9b3a0434fa7e9e.tar.gz | |
src/main.c: differentiate between message exit code 0 and -1
| -rw-r--r-- | src/main.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -48,15 +48,21 @@ int process_message(struct pollfd *fds, nfds_t *nfds) { ssize_t message = read(fds[i].fd, buffer, sizeof(buffer)); /* read the message which the client sent */ - /* if message of the client returns an error */ - if (message < 0) { + if (message == 0) { /* close the connection if client disappeared or disconnected */ close(fds[i].fd); fds[i] = fds[*nfds - 1]; /* move back last slot */ (*nfds)--; /* size down the current array */ i--; + } else if (message == -1) { + /* if message of the client returns an error */ + close(fds[i].fd); + fds[i] = fds[*nfds - 1]; /* move back last slot */ + (*nfds)--; /* size down the current array */ + i--; return -1; - } else { + } + else { /* send every message bytes to the other clients */ for (nfds_t j = 1; j < *nfds; j++) { if (j != i) { |
