summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-06-30 13:22:55 +0200
committercashmere <cashmere@autistici.org>2026-06-30 13:22:55 +0200
commit9b1156e6735c5212b691069f0d9b3a0434fa7e9e (patch)
treeba3ed039e21cb19446891b727dac1cf459a56499 /src
parentf54df76327cdadee5b1450fd731897f6a5d2d368 (diff)
downloadtelnet-9b1156e6735c5212b691069f0d9b3a0434fa7e9e.tar.gz
src/main.c: differentiate between message exit code 0 and -1
Diffstat (limited to 'src')
-rw-r--r--src/main.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 4c3298b..bbf26e1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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) {