Commit 186a40f3 authored by Baptiste Jonglez's avatar Baptiste Jonglez Committed by Juliusz Chroboczek

Refactor acceptance of new local connections

The various cases of success or failure are quite intricate.  Since we
plan to intricate it further in an upcoming commit, it's better to
refactor it now.
parent 5a41d3a4
......@@ -89,6 +89,7 @@ struct timeval check_neighbours_timeout, check_interfaces_timeout;
static volatile sig_atomic_t exiting = 0, dumping = 0, reopening = 0;
static int accept_local_connections(fd_set *readfds);
static int kernel_routes_callback(int changed, void *closure);
static void init_signals(void);
static void dump_tables(FILE *out);
......@@ -621,23 +622,7 @@ main(int argc, char **argv)
}
#ifndef NO_LOCAL_INTERFACE
if(local_server_socket >= 0 &&
FD_ISSET(local_server_socket, &readfds)) {
int s;
s = accept(local_server_socket, NULL, NULL);
if(s < 0) {
if(errno != EINTR && errno != EAGAIN)
perror("accept(local_server_socket)");
} else if(num_local_sockets >= MAX_LOCAL_SOCKETS) {
/* This should never happen, since we don't select for
the server socket in this case. But I'm paranoid. */
fprintf(stderr, "Internal error: too many local sockets.\n");
close(s);
} else {
local_sockets[num_local_sockets++] = s;
local_notify_all_1(s);
}
}
accept_local_connections(&readfds);
i = 0;
while(i < num_local_sockets) {
......@@ -839,6 +824,36 @@ main(int argc, char **argv)
exit(1);
}
static int
accept_local_connections(fd_set *readfds)
{
if(local_server_socket < 0 || !FD_ISSET(local_server_socket, readfds))
return 0;
int s;
s = accept(local_server_socket, NULL, NULL);
if(s < 0) {
if(errno != EINTR && errno != EAGAIN) {
perror("accept(local_server_socket)");
return -1;
}
return 0;
}
if(num_local_sockets >= MAX_LOCAL_SOCKETS) {
/* This should never happen, since we don't select for
the server socket in this case. But I'm paranoid. */
fprintf(stderr, "Internal error: too many local sockets.\n");
close(s);
return -1;
}
local_sockets[num_local_sockets++] = s;
local_notify_all_1(s);
return 1;
}
void
schedule_neighbours_check(int msecs, int override)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment