Switch to more consistently setting sockets non-blocking.

This commit is contained in:
Ian Gulliver
2016-02-17 22:22:14 -08:00
parent 4398deb2d4
commit 820d5d6192
2 changed files with 3 additions and 7 deletions

View File

@@ -1,3 +1,5 @@
#define _GNU_SOURCE
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -26,7 +28,7 @@ static void incoming_handler(struct peer *peer) {
struct sockaddr peer_addr, local_addr; struct sockaddr peer_addr, local_addr;
socklen_t peer_addrlen = sizeof(peer_addr), local_addrlen = sizeof(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) { 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)); fprintf(stderr, "I %s: Failed to accept new connection on %s/%s: %s\n", incoming->id, incoming->node, incoming->service, strerror(errno));
return; return;

6
send.c
View File

@@ -4,7 +4,6 @@
#include <strings.h> #include <strings.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <signal.h> #include <signal.h>
#include "common.h" #include "common.h"
@@ -98,11 +97,6 @@ struct serializer *send_get_serializer(char *name) {
} }
void send_add(int fd, struct serializer *serializer) { 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)) { if (!send_hello(fd, serializer)) {
fprintf(stderr, "S xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx: Failed to write hello\n"); fprintf(stderr, "S xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx: Failed to write hello\n");
return; return;