From 34fc018520ff7f2054ddf814c2b7a48393fb000f Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 4 May 2014 16:20:21 -0400 Subject: [PATCH] Make the statistician perform the shutdown after a final round of reporting. --- echo-server.rkt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/echo-server.rkt b/echo-server.rkt index 3ad4ea5..a8be1b6 100644 --- a/echo-server.rkt +++ b/echo-server.rkt @@ -22,6 +22,7 @@ (define Tconn (logbook-table E "server-connections" #:column-spec '(time-seconds connection-count))) (define connection-count 0) +(define first-connection-seen? #f) (define statistics-poll-interval 2000) @@ -34,6 +35,8 @@ ;; (collect-garbage) (write-logbook-datum! Tmem (list (/ now 1000.0) (current-memory-use))) (write-logbook-datum! Tconn (list (/ now 1000.0) connection-count)) + (when (and first-connection-seen? (zero? connection-count)) + (exit 0)) (transition s (send (set-timer 'statistician statistics-poll-interval 'relative)))] [_ #f])) @@ -53,14 +56,13 @@ (define (connection in out) (set! connection-count (+ connection-count 1)) + (set! first-connection-seen? #t) (spawn (lambda (e s) (match e [(message (event _ (list (? eof-object?))) _ _) (close-input-port in) (close-output-port out) (set! connection-count (- connection-count 1)) - (when (zero? connection-count) - (exit 0)) (transition s (quit))] [(message (event _ (list line)) _ _) (fprintf out "~a\n" line)