guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 18/23: (web server ethreads) TCP_NODELAY tweak


From: Andy Wingo
Subject: [Guile-commits] 18/23: (web server ethreads) TCP_NODELAY tweak
Date: Thu, 24 Mar 2016 14:26:04 +0000

wingo pushed a commit to branch wip-ethreads
in repository guile.

commit 30bfc2f2703eb16f1c20a5a1b588cace5127f755
Author: Andy Wingo <address@hidden>
Date:   Tue Mar 27 22:24:10 2012 +0200

    (web server ethreads) TCP_NODELAY tweak
    
    * module/web/server/ethreads.scm (client-loop, socket-loop): Instead of
      corking and uncorking the client, just turn on TCP_NODELAY always.
---
 module/web/server/ethreads.scm |   25 ++++++-------------------
 1 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/module/web/server/ethreads.scm b/module/web/server/ethreads.scm
index 7c45661..b803c01 100644
--- a/module/web/server/ethreads.scm
+++ b/module/web/server/ethreads.scm
@@ -137,21 +137,6 @@
               ((0) (memq 'keep-alive (response-connection response)))))
            (else #f)))))
 
-(define cork!
-  (cond
-   ((defined? 'TCP_NODELAY)
-    (lambda (fd cork?)
-      ;; Always disable Nagle's algorithm, as we handle buffering
-      ;; ourselves.  Don't bother disabling if cork? is #f.
-      (when cork?
-        (setsockopt fd IPPROTO_TCP TCP_NODELAY 0))))
-   ((defined? 'TCP_CORK)
-    ;; If we don't have TCP_NODELAY, the Linux-specific TCP_CORK will
-    ;; do.
-    (lambda (fd cork?)
-      (setsockopt fd IPPROTO_TCP TCP_CORK (if cork? 1 0))))
-   (else (lambda (fd cork?) #t))))
-
 (define (client-loop client have-request)
   (with-throw-handler #t
     (lambda ()
@@ -172,7 +157,6 @@
                                           #:headers '((content-length . 0)))
                           #vu8()))))
           (lambda (response body)
-            (cork! (eport-fd client) #t)
             (put-bytevector client
                             (call-with-output-bytevector
                              (lambda (port) (write-response response port))))
@@ -180,9 +164,7 @@
               (put-bytevector client body))
             (drain-output client)
             (if (and (keep-alive? response)
-                     (begin
-                       (cork! (eport-fd client) #f)
-                       (not (eof-object? (lookahead-u8 client)))))
+                     (not (eof-object? (lookahead-u8 client))))
                 (loop)
                 (close-eport client))))))
     (lambda (k . args)
@@ -199,6 +181,11 @@
   (let loop ()
     (let ((client (accept-eport esocket)))
       (setsockopt (eport-fd client) SOL_SOCKET SO_SNDBUF (* 12 1024))
+      ;; Always disable Nagle's algorithm, as we handle buffering
+      ;; ourselves.  Ignore exceptions if it's not a TCP port, or
+      ;; TCP_NODELAY is not defined on this platform.
+      (false-if-exception
+       (setsockopt (eport-fd client) IPPROTO_TCP TCP_NODELAY 0))
       (spawn (lambda () (client-loop client have-request)))
       (loop))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]