quark

quark web server
git clone git://git.suckless.org/quark
Log | Files | Refs | LICENSE

commit 9e2662c5e9f461c4f3b80aab9d712b7f72030dad
parent 55912e14bf1194fddc727c4261b531a2969fba5d
Author: FRIGN <dev@frign.de>
Date:   Mon, 11 Aug 2014 16:16:37 +0200

Get rid of getnameinfo and use inet_ntop instead

Compiling quark against musl slowed down request-times considerably.
After further analysis, I found out that the library does a DNS-
request on each address passed to getnameinfo.
Given we chroot into a folder, the /etc/resolv.conf was missing,
which led to the really long response-times (~3-5s).
After hardlinking the /etc/resolv.conf inside the chroot, the
times dropped to ~200ms, as now the library knew which NS to
contact directly.

This obviously isn't fast enough.

Thanks to Hiltjo's useful tips I rewrote the section using
inet_ntop (POSIX 2001).
Now the response-times are back to 1-2ms and we don't need
to copy /etc/resolv.conf everywhere we go.

FYI: This is not a bug in musl, but rather different behaviour.

Diffstat:
Mquark.c | 18++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/quark.c b/quark.c @@ -12,6 +12,7 @@ #include <string.h> #include <time.h> #include <unistd.h> +#include <arpa/inet.h> #include <netinet/in.h> #include <sys/socket.h> #include <sys/stat.h> @@ -448,8 +449,21 @@ serve(int fd) { result = fork(); if (result == 0) { close(fd); - host[0] = 0; - getnameinfo(&sa, salen, host, sizeof host, NULL, 0, NI_NOFQDN); + + /* get host */ + switch(sa.sa_family) { + case AF_INET: + inet_ntop(AF_INET, &(((struct sockaddr_in *)&sa)->sin_addr), + host, sizeof host); + break; + case AF_INET6: + inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)&sa)->sin6_addr), + host, sizeof host); + break; + default: + host[0] = 0; + } + result = request(); shutdown(req.fd, SHUT_RD); status = -1;