Switch to more consistently setting sockets non-blocking.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -26,7 +28,7 @@ static void incoming_handler(struct peer *peer) {
|
||||
struct sockaddr peer_addr, local_addr;
|
||||
socklen_t peer_addrlen = sizeof(peer_addr), local_addrlen = sizeof(local_addr);
|
||||
|
||||
int fd = accept(incoming->peer.fd, &peer_addr, &peer_addrlen);
|
||||
int fd = accept4(incoming->peer.fd, &peer_addr, &peer_addrlen, SOCK_NONBLOCK);
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "I %s: Failed to accept new connection on %s/%s: %s\n", incoming->id, incoming->node, incoming->service, strerror(errno));
|
||||
return;
|
||||
|
||||
6
send.c
6
send.c
@@ -4,7 +4,6 @@
|
||||
#include <strings.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "common.h"
|
||||
@@ -98,11 +97,6 @@ struct serializer *send_get_serializer(char *name) {
|
||||
}
|
||||
|
||||
void send_add(int fd, struct serializer *serializer) {
|
||||
int flags = fcntl(fd, F_GETFL, 0);
|
||||
assert(flags >= 0);
|
||||
flags |= O_NONBLOCK;
|
||||
assert(fcntl(fd, F_SETFL, flags) == 0);
|
||||
|
||||
if (!send_hello(fd, serializer)) {
|
||||
fprintf(stderr, "S xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx: Failed to write hello\n");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user