From: Tim Vaughan Date: Fri, 21 Jun 2019 23:16:02 +0000 (+0200) Subject: Improved connection error handling. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=99049adeaed71d9b6a2c53a79104acbbdc946db9;p=scratchy.git Improved connection error handling. --- diff --git a/scratchy.scm b/scratchy.scm index 0bc9a6a..bdbdee4 100644 --- a/scratchy.scm +++ b/scratchy.scm @@ -20,7 +20,7 @@ ;;; Global constants -(define scratchy-version "1.0.0") +(define scratchy-version "1.0.1") (define scratchy-footer (conc "\n" @@ -58,24 +58,27 @@ (define (server-loop listener config) (let-values (((in-port out-port) (tcp-accept listener))) - (let* ((line (read-line in-port)) - (selector (string-trim-both line))) - (let-values (((local-ip remote-ip) (tcp-addresses in-port))) - (print "Accepted connection from " remote-ip - " on " (seconds->string)) - (condition-case - (begin - (with-output-to-port out-port - (lambda () - (serve-selector (if (= (string-length selector) 0) - "/" - selector) - config))) - (print "... served selector '" selector "'. Closing connection.")) - (o (exn) - (print-error-message o out-port) - (print-error-message o) - (print "Error while attempting to serve selector " selector "."))))) + (let-values (((local-ip remote-ip) (tcp-addresses in-port))) + (print "Accepted connection from " remote-ip + " on " (seconds->string))) + (condition-case + (let* ((line (read-line in-port)) + (selector (string-trim-both line))) + (condition-case + (begin + (with-output-to-port out-port + (lambda () + (serve-selector (if (= (string-length selector) 0) + "/" + selector) + config))) + (print "... served selector '" selector "'. Closing connection.")) + (o (exn) + (print-error-message o out-port) + (print-error-message o) + (print "Error while attempting to serve selector " selector ".")))) + (o (exn) + (print-error-message o))) (close-input-port in-port) (close-output-port out-port)) (server-loop listener config))