stop crashing server when client disconnects

This commit is contained in:
socec 2014-03-09 18:48:04 +01:00
parent 98333194db
commit 199d2cb6c2
3 changed files with 19 additions and 2 deletions

View file

@ -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,