summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-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) {