gnu: perl-archive-zip: Remove duplicate package definition.
[jackhill/guix/guix.git] / nix / nix-daemon / nix-daemon.cc
index 3d8e909..deb7003 100644 (file)
@@ -19,6 +19,9 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
 #include <fcntl.h>
 #include <errno.h>
 #include <pwd.h>
@@ -433,7 +436,15 @@ static void performOp(bool trusted, unsigned int clientVersion,
         bool sign = readInt(from) == 1;
         startWork();
         TunnelSink sink(to);
-        store->exportPath(path, sign, sink);
+       try {
+           store->exportPath(path, sign, sink);
+       }
+       catch (Error &e) {
+           /* Flush SINK beforehand or its destructor will rightfully trigger
+              an assertion failure.  */
+           sink.flush();
+           throw e;
+       }
         sink.flush();
         stopWork();
         writeInt(1, to);
@@ -839,6 +850,21 @@ static void acceptConnection(int fdSocket)
 
        closeOnExec(remote);
 
+       {
+         int enabled = 1;
+
+         /* If we're on a TCP connection, disable Nagle's algorithm so that
+            data is sent as soon as possible.  */
+         (void) setsockopt(remote, SOL_TCP, TCP_NODELAY,
+                           &enabled, sizeof enabled);
+
+#if defined(TCP_QUICKACK)
+         /* Enable TCP quick-ack if applicable; this might help a little.  */
+         (void) setsockopt(remote, SOL_TCP, TCP_QUICKACK,
+                           &enabled, sizeof enabled);
+#endif
+       }
+
        pid_t clientPid = -1;
        bool trusted = false;
 
@@ -869,13 +895,11 @@ static void acceptConnection(int fdSocket)
 
            if (remoteAddr.ss_family == AF_INET) {
                struct sockaddr_in *addr = (struct sockaddr_in *) &remoteAddr;
-               struct in_addr inaddr = { addr->sin_addr };
-               result = inet_ntop(AF_INET, &inaddr,
+               result = inet_ntop(AF_INET, &addr->sin_addr,
                                   address_str, sizeof address_str);
            } else if (remoteAddr.ss_family == AF_INET6) {
                struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &remoteAddr;
-               struct in6_addr inaddr = { addr->sin6_addr };
-               result = inet_ntop(AF_INET6, &inaddr,
+               result = inet_ntop(AF_INET6, &addr->sin6_addr,
                                   address_str, sizeof address_str);
            } else {
                result = NULL;