From 9b1156e6735c5212b691069f0d9b3a0434fa7e9e Mon Sep 17 00:00:00 2001 From: cashmere Date: Tue, 30 Jun 2026 13:22:55 +0200 Subject: src/main.c: differentiate between message exit code 0 and -1 --- src/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/main.c') 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) { -- cgit v1.3.1