kike: unindent a function by refactoring
This commit is contained in:
parent
c9a02141f9
commit
b3254a589c
29
kike.c
29
kike.c
|
@ -2760,40 +2760,35 @@ client_update_poller (struct client *c, const struct pollfd *pfd)
|
|||
poller_fd_set (&c->socket_event, new_events);
|
||||
}
|
||||
|
||||
static void
|
||||
on_irc_client_available (const struct pollfd *pfd, void *user_data)
|
||||
static bool
|
||||
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
|
||||
struct sockaddr_storage 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 (errno == EAGAIN)
|
||||
break;
|
||||
return false;
|
||||
if (errno == EINTR
|
||||
|| errno == ECONNABORTED)
|
||||
continue;
|
||||
return true;
|
||||
|
||||
// TODO: handle resource exhaustion (EMFILE, ENFILE) specially
|
||||
// (stop accepting new connections and wait until we close some;
|
||||
// also set a timer in case of ENFILE).
|
||||
print_fatal ("%s: %s", "accept", strerror (errno));
|
||||
irc_initiate_quit (ctx);
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ctx->max_connections != 0 && ctx->n_clients >= ctx->max_connections)
|
||||
{
|
||||
print_debug ("connection limit reached, refusing connection");
|
||||
close (fd);
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
client_update_poller (c, NULL);
|
||||
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 -------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue