diff options
| -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) { |
