summaryrefslogtreecommitdiff
path: root/xD.c
diff options
context:
space:
mode:
Diffstat (limited to 'xD.c')
-rw-r--r--xD.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/xD.c b/xD.c
index 45cd659..65ebe7e 100644
--- a/xD.c
+++ b/xD.c
@@ -853,8 +853,6 @@ client_send_str (struct client *c, const struct str *s)
str_append_data (&c->write_buffer, s->str,
MIN (s->len, IRC_MAX_MESSAGE_LENGTH));
str_append (&c->write_buffer, "\r\n");
- // XXX: we might want to move this elsewhere, so that it doesn't get called
- // as often; it's going to cause a lot of syscalls with epoll.
client_update_poller (c, NULL);
// Technically we haven't sent it yet but that's a minor detail
@@ -3095,6 +3093,7 @@ irc_try_read (struct client *c)
{
buf->str[buf->len += n_read] = '\0';
// TODO: discard characters above the 512 character limit
+ // FIXME: we should probably discard the data if closing_link
irc_process_buffer (buf, irc_process_message, c);
continue;
}
@@ -3136,6 +3135,7 @@ irc_try_read_tls (struct client *c)
case SSL_ERROR_NONE:
buf->str[buf->len += n_read] = '\0';
// TODO: discard characters above the 512 character limit
+ // FIXME: we should probably discard the data if closing_link
irc_process_buffer (buf, irc_process_message, c);
continue;
case SSL_ERROR_ZERO_RETURN:
@@ -3421,16 +3421,10 @@ irc_try_fetch_client (struct server_context *ctx, int listen_fd)
if (errno == EINTR)
return true;
- if (errno == EBADF
- || errno == EINVAL
- || errno == ENOTSOCK
- || errno == EOPNOTSUPP)
+ if (accept_error_is_transient (errno))
+ print_warning ("%s: %s", "accept", strerror (errno));
+ else
print_fatal ("%s: %s", "accept", strerror (errno));
-
- // OS kernels may return a wide range of unforeseeable errors.
- // Assuming that they're either transient or caused by
- // a connection that we've just extracted from the queue.
- print_warning ("%s: %s", "accept", strerror (errno));
return true;
}
@@ -3814,10 +3808,9 @@ irc_lock_pid_file (struct server_context *ctx, struct error **e)
}
static int
-irc_listen (struct addrinfo *gai_iter)
+irc_listen (struct addrinfo *ai)
{
- int fd = socket (gai_iter->ai_family,
- gai_iter->ai_socktype, gai_iter->ai_protocol);
+ int fd = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (fd == -1)
return -1;
set_cloexec (fd);
@@ -3831,21 +3824,13 @@ irc_listen (struct addrinfo *gai_iter)
#if defined SOL_IPV6 && defined IPV6_V6ONLY
// Make NULL always bind to both IPv4 and IPv6, irrespectively of the order
// of results; only INADDR6_ANY seems to be affected by this
- if (gai_iter->ai_family == AF_INET6)
+ if (ai->ai_family == AF_INET6)
soft_assert (setsockopt (fd, SOL_IPV6, IPV6_V6ONLY,
&yes, sizeof yes) != -1);
#endif
- char host[NI_MAXHOST], port[NI_MAXSERV];
- host[0] = port[0] = '\0';
- int err = getnameinfo (gai_iter->ai_addr, gai_iter->ai_addrlen,
- host, sizeof host, port, sizeof port,
- NI_NUMERICHOST | NI_NUMERICSERV);
- if (err)
- print_debug ("%s: %s", "getnameinfo", gai_strerror (err));
-
- char *address = format_host_port_pair (host, port);
- if (bind (fd, gai_iter->ai_addr, gai_iter->ai_addrlen))
+ char *address = gai_reconstruct_address (ai);
+ if (bind (fd, ai->ai_addr, ai->ai_addrlen))
print_error ("bind to %s failed: %s", address, strerror (errno));
else if (listen (fd, 16 /* arbitrary number */))
print_error ("listen on %s failed: %s", address, strerror (errno));
@@ -3865,12 +3850,12 @@ static void
irc_listen_resolve (struct server_context *ctx,
const char *host, const char *port, struct addrinfo *gai_hints)
{
- struct addrinfo *gai_result, *gai_iter;
+ struct addrinfo *gai_result = NULL, *gai_iter = NULL;
int err = getaddrinfo (host, port, gai_hints, &gai_result);
if (err)
{
char *address = format_host_port_pair (host, port);
- print_error ("bind to %s failed: %s: %s",
+ print_error ("binding to %s failed: %s: %s",
address, "getaddrinfo", gai_strerror (err));
free (address);
return;