stop crashing server when client disconnects
This commit is contained in:
parent
98333194db
commit
199d2cb6c2
3 changed files with 19 additions and 2 deletions
5
server.c
5
server.c
|
@ -85,6 +85,11 @@ int server_accept(struct server_t *server, struct client_t *accepted_client) {
|
|||
fprintf(stderr, "[%s:%d] error %d: %s\n", __func__, __LINE__, errno, strerror(errno));
|
||||
return -errno;
|
||||
}
|
||||
/* make client socket non-blocking */
|
||||
if (fcntl(accepted_client->socket, F_SETFL, O_NONBLOCK) == -1) {
|
||||
fprintf(stderr, "[%s:%d] error %d: %s\n", __func__, __LINE__, errno, strerror(errno));
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* get client IP address as human readable string */
|
||||
inet_ntop(accepted_client->address.sin_family, &accepted_client->address.sin_addr.s_addr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue