commit 9e2662c5e9f461c4f3b80aab9d712b7f72030dad
Author: FRIGN <[email protected]>
Date:   Mon Aug 11 16:16:37 2014 +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.

diff --git a/quark.c b/quark.c
index 8a9fc8d..9002424 100644
--- 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;


Reply via email to