Cleaning up timer/conn manager interface

svn: r12331
This commit is contained in:
Jay McCarthy 2008-11-06 17:01:27 +00:00
parent 61b44707cd
commit cbecece203
5 changed files with 35 additions and 38 deletions

View File

@ -3,7 +3,7 @@
web-server/private/connection-manager) web-server/private/connection-manager)
(provide connection-manager-tests) (provide connection-manager-tests)
(start-connection-manager (current-custodian)) (start-connection-manager)
(define connection-manager-tests (define connection-manager-tests
(test-suite (test-suite

View File

@ -13,15 +13,15 @@
[o-port output-port?] [o-port output-port?]
[custodian custodian?] [custodian custodian?]
[close? boolean?])] [close? boolean?])]
[start-connection-manager (custodian? . -> . void)] [start-connection-manager (-> void)]
[new-connection (number? input-port? output-port? custodian? boolean? . -> . connection?)] [new-connection (number? input-port? output-port? custodian? boolean? . -> . connection?)]
[kill-connection! (connection? . -> . void)] [kill-connection! (connection? . -> . void)]
[adjust-connection-timeout! (connection? number? . -> . void)]) [adjust-connection-timeout! (connection? number? . -> . void)])
;; start-connection-manager: custodian -> void ;; start-connection-manager: custodian -> void
;; calls the timer manager ;; calls the timer manager
(define (start-connection-manager custodian) (define (start-connection-manager)
(start-timer-manager custodian)) (start-timer-manager))
;; new-connection: number i-port o-port custodian -> connection ;; new-connection: number i-port o-port custodian -> connection
;; ask the connection manager for a new connection ;; ask the connection manager for a new connection

View File

@ -13,10 +13,10 @@
;; start the server and return a thunk to shut it down ;; start the server and return a thunk to shut it down
(define (serve) (define (serve)
(define the-server-custodian (make-custodian)) (define the-server-custodian (make-custodian))
(start-connection-manager the-server-custodian)
(parameterize ([current-custodian the-server-custodian] (parameterize ([current-custodian the-server-custodian]
[current-server-custodian the-server-custodian] [current-server-custodian the-server-custodian]
#;[current-thread-initial-stack-size 3]) #;[current-thread-initial-stack-size 3])
(start-connection-manager)
(thread (thread
(lambda () (lambda ()
(run-server config:port (run-server config:port
@ -40,10 +40,10 @@
;; NOTE: (GregP) should allow the user to pass in a connection-custodian ;; NOTE: (GregP) should allow the user to pass in a connection-custodian
(define (serve-ports ip op) (define (serve-ports ip op)
(define server-cust (make-custodian)) (define server-cust (make-custodian))
(start-connection-manager server-cust)
(parameterize ([current-custodian server-cust] (parameterize ([current-custodian server-cust]
[current-server-custodian server-cust]) [current-server-custodian server-cust])
(define connection-cust (make-custodian)) (define connection-cust (make-custodian))
(start-connection-manager)
(parameterize ([current-custodian connection-cust]) (parameterize ([current-custodian connection-cust])
(thread (thread
(lambda () (lambda ()

View File

@ -8,10 +8,9 @@
(define timer-ch (make-async-channel)) (define timer-ch (make-async-channel))
; start-timer-manager : custodian -> void ; start-timer-manager : -> void
; The timer manager thread ; The timer manager thread
(define (start-timer-manager server-custodian) (define (start-timer-manager)
(parameterize ([current-custodian server-custodian])
(thread (thread
(lambda () (lambda ()
(let loop ([timers null]) (let loop ([timers null])
@ -33,7 +32,7 @@
;; execute timer ;; execute timer
((timer-action timer)) ((timer-action timer))
(loop (remq timer timers))))) (loop (remq timer timers)))))
timers)))))) timers)))))
(void)) (void))
;; Limitation on this add-timer: thunk cannot make timer ;; Limitation on this add-timer: thunk cannot make timer
@ -93,7 +92,7 @@
[struct timer ([evt evt?] [struct timer ([evt evt?]
[expire-seconds number?] [expire-seconds number?]
[action (-> void)])] [action (-> void)])]
[start-timer-manager (custodian? . -> . void)] [start-timer-manager (-> void)]
[start-timer (number? (-> void) . -> . timer?)] [start-timer (number? (-> void) . -> . timer?)]
[reset-timer! (timer? number? . -> . void)] [reset-timer! (timer? number? . -> . void)]
[increment-timer! (timer? number? . -> . void)] [increment-timer! (timer? number? . -> . void)]

View File

@ -26,10 +26,9 @@ procedures after a given amount of time, that may be extended.
@scheme[action] should be called when this @scheme[evt] is ready. @scheme[action] should be called when this @scheme[evt] is ready.
} }
@defproc[(start-timer-manager [cust custodian?]) @defproc[(start-timer-manager)
void]{ void]{
Handles the execution and management of timers. Resources are charged to Handles the execution and management of timers.
@scheme[cust].
} }
@defproc[(start-timer [s number?] @defproc[(start-timer [s number?]
@ -77,10 +76,9 @@ for doing this.
The connection will last until @scheme[timer] triggers. The connection will last until @scheme[timer] triggers.
} }
@defproc[(start-connection-manager [parent-cust custodian?]) @defproc[(start-connection-manager)
void]{ void]{
Runs the connection manager (now just the timer manager) will @scheme[parent-cust] Runs the connection manager (now just the timer manager).
as the custodian.
} }
@defproc[(new-connection [timeout number?] @defproc[(new-connection [timeout number?]