Skip to content
Snippets Groups Projects
Commit 7e0c65b8 authored by burneykb's avatar burneykb
Browse files

Added remove_client functionality

parent 6ffc61dc
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,8 @@ static int new_client(int fd);
static ssize_t get_client_index(int fd);
/* Returns pointer to client buffer, or -1 */
static char * get_client_buffer(int fd);
/* Returns -1 on error */
static int remove_client(fd);
/* Thread-safe wrappers */
pthread_mutex_t quadSocketMutex;
......@@ -246,6 +248,15 @@ int main(int argc, char **argv)
}
}
}
} else {
for(int i = 0; i < MAX_CLIENTS; ++i) {
if(client_fds[i] != -1) {
char buff;
if(recv(client_fds[i],&buff, 1, MSG_PEEK | MSG_DONTWAIT) < 0) {
remove_client(client_fds[i]);
}
}
}
}
}
......@@ -467,3 +478,15 @@ static char * get_client_buffer(int fd)
return client_buffers[slot];
}
}
static int remove_client(fd) {
ssize_t slot = get_client_index(fd);
if(slot == -1)
return slot;
char *clientBuffer = get_client_buffer(fd);
if(clientBuffer == NULL)
return -1;
clientBuffer = '\0';
client_fds[clientIndex] = -1;
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment