Commit ed2165ba authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use explicit functions for creating and destroying local sockets.

parent dcd1dba6
......@@ -681,13 +681,11 @@ main(int argc, char **argv)
rc = local_read(&local_sockets[i]);
if(rc <= 0) {
if(rc < 0) {
if(errno == EINTR)
if(errno == EINTR || errno == EAGAIN)
continue;
perror("read(local_socket)");
}
close(local_sockets[i].fd);
local_sockets[i] = local_sockets[--num_local_sockets];
continue;
local_socket_destroy(i);
}
}
i++;
......@@ -881,6 +879,7 @@ static int
accept_local_connections(fd_set *readfds)
{
int rc, s;
struct local_socket *ls;
if(local_server_socket < 0 || !FD_ISSET(local_server_socket, readfds))
return 0;
......@@ -917,8 +916,8 @@ accept_local_connections(fd_set *readfds)
return -1;
}
local_sockets[num_local_sockets++].fd = s;
local_notify_all_1(&local_sockets[num_local_sockets - 1]);
ls = local_socket_create(s);
local_notify_all_1(ls);
return 1;
}
......
......@@ -321,4 +321,28 @@ local_notify_all_1(struct local_socket *s)
return;
}
struct local_socket *
local_socket_create(int fd)
{
if(num_local_sockets >= MAX_LOCAL_SOCKETS)
return NULL;
local_sockets[num_local_sockets].fd = fd;
num_local_sockets++;
return &local_sockets[num_local_sockets - 1];
}
void
local_socket_destroy(int i)
{
if(i < 0 || i >= num_local_sockets) {
fprintf(stderr, "Internal error: closing unknown local socket.\n");
return;
}
close(local_sockets[i].fd);
local_sockets[i] = local_sockets[--num_local_sockets];
}
#endif
......@@ -48,6 +48,8 @@ void local_notify_neighbour(struct neighbour *neigh, int kind);
void local_notify_xroute(struct xroute *xroute, int kind);
void local_notify_route(struct babel_route *route, int kind);
void local_notify_all_1(struct local_socket *s);
struct local_socket *local_socket_create(int fd);
void local_socket_destroy(int i);
#else
......
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