kike: unindent a function by refactoring
This commit is contained in:
parent
c9a02141f9
commit
b3254a589c
27
kike.c
27
kike.c
|
@ -2760,40 +2760,35 @@ client_update_poller (struct client *c, const struct pollfd *pfd)
|
||||||
poller_fd_set (&c->socket_event, new_events);
|
poller_fd_set (&c->socket_event, new_events);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
on_irc_client_available (const struct pollfd *pfd, void *user_data)
|
irc_try_fetch_client (struct server_context *ctx, int listen_fd)
|
||||||
{
|
|
||||||
(void) pfd;
|
|
||||||
struct server_context *ctx = user_data;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
// XXX: `struct sockaddr_storage' is not the most portable thing
|
// XXX: `struct sockaddr_storage' is not the most portable thing
|
||||||
struct sockaddr_storage peer;
|
struct sockaddr_storage peer;
|
||||||
socklen_t peer_len = sizeof peer;
|
socklen_t peer_len = sizeof peer;
|
||||||
|
|
||||||
int fd = accept (pfd->fd, (struct sockaddr *) &peer, &peer_len);
|
int fd = accept (listen_fd, (struct sockaddr *) &peer, &peer_len);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
if (errno == EAGAIN)
|
if (errno == EAGAIN)
|
||||||
break;
|
return false;
|
||||||
if (errno == EINTR
|
if (errno == EINTR
|
||||||
|| errno == ECONNABORTED)
|
|| errno == ECONNABORTED)
|
||||||
continue;
|
return true;
|
||||||
|
|
||||||
// TODO: handle resource exhaustion (EMFILE, ENFILE) specially
|
// TODO: handle resource exhaustion (EMFILE, ENFILE) specially
|
||||||
// (stop accepting new connections and wait until we close some;
|
// (stop accepting new connections and wait until we close some;
|
||||||
// also set a timer in case of ENFILE).
|
// also set a timer in case of ENFILE).
|
||||||
print_fatal ("%s: %s", "accept", strerror (errno));
|
print_fatal ("%s: %s", "accept", strerror (errno));
|
||||||
irc_initiate_quit (ctx);
|
irc_initiate_quit (ctx);
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->max_connections != 0 && ctx->n_clients >= ctx->max_connections)
|
if (ctx->max_connections != 0 && ctx->n_clients >= ctx->max_connections)
|
||||||
{
|
{
|
||||||
print_debug ("connection limit reached, refusing connection");
|
print_debug ("connection limit reached, refusing connection");
|
||||||
close (fd);
|
close (fd);
|
||||||
continue;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[NI_MAXHOST] = "unknown", port[NI_MAXSERV] = "unknown";
|
char host[NI_MAXHOST] = "unknown", port[NI_MAXSERV] = "unknown";
|
||||||
|
@ -2834,7 +2829,15 @@ on_irc_client_available (const struct pollfd *pfd, void *user_data)
|
||||||
set_blocking (fd, false);
|
set_blocking (fd, false);
|
||||||
client_update_poller (c, NULL);
|
client_update_poller (c, NULL);
|
||||||
client_set_kill_timer (c);
|
client_set_kill_timer (c);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_irc_client_available (const struct pollfd *pfd, void *user_data)
|
||||||
|
{
|
||||||
|
struct server_context *ctx = user_data;
|
||||||
|
while (irc_try_fetch_client (ctx, pfd->fd))
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Application setup -------------------------------------------------------
|
// --- Application setup -------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue