Squelching port-closed error messages

This commit is contained in:
Jay McCarthy 2012-09-25 10:21:14 -06:00
parent b420e40b0e
commit a5acdb473f

View File

@ -1,14 +1,15 @@
#lang racket/unit #lang racket/unit
(require net/tcp-sig (require net/tcp-sig
racket/async-channel racket/async-channel
racket/port
mzlib/thread) mzlib/thread)
(require "web-server-structs.rkt" (require "web-server-structs.rkt"
"connection-manager.rkt" "connection-manager.rkt"
"dispatch-server-sig.rkt") "dispatch-server-sig.rkt")
;; **************************************** ;; ****************************************
(import tcp^ (prefix config: dispatch-server-config^)) (import tcp^ (prefix config: dispatch-server-config^))
(export dispatch-server^) (export dispatch-server^)
(define (async-channel-put* ac v) (define (async-channel-put* ac v)
(when ac (when ac
@ -24,15 +25,15 @@
(start-connection-manager) (start-connection-manager)
(thread (thread
(lambda () (lambda ()
(run-server 1 ; This is the port argument, but because we specialize listen, it is ignored. (run-server 1 ; This is the port argument, but because we specialize listen, it is ignored.
handle-connection handle-connection
#f #f
(lambda (exn) (lambda (exn)
((error-display-handler) ((error-display-handler)
(format "Connection error: ~a" (exn-message exn)) (format "Connection error: ~a" (exn-message exn))
exn)) exn))
(lambda (_ mw re) (lambda (_ mw re)
(with-handlers ([exn? (with-handlers ([exn?
(λ (x) (λ (x)
(async-channel-put* confirmation-channel x) (async-channel-put* confirmation-channel x)
(raise x))]) (raise x))])
@ -85,12 +86,23 @@
;; connection will be closed. This shouldn't change any other ;; connection will be closed. This shouldn't change any other
;; behavior: read-request is already blocking, peeking doesn't ;; behavior: read-request is already blocking, peeking doesn't
;; consume a byte, etc. ;; consume a byte, etc.
(if (eof-object? (peek-byte ip)) (sync
(kill-connection! conn) (handle-evt
(let-values (port-closed-evt ip)
([(req close?) (config:read-request conn config:port port-addresses)]) (λ (res)
(set-connection-close?! conn close?) (kill-connection! conn)))
(config:dispatch conn req) (handle-evt
(if (connection-close? conn) (peek-bytes-evt 1 0 #f ip)
(kill-connection! conn) (λ (res)
(connection-loop)))))) (cond
[(eof-object? res)
(kill-connection! conn)]
[else
(define-values
(req close?)
(config:read-request conn config:port port-addresses))
(set-connection-close?! conn close?)
(config:dispatch conn req)
(if (connection-close? conn)
(kill-connection! conn)
(connection-loop))]))))))