Cleaning up timer/conn manager interface
svn: r12331
This commit is contained in:
parent
61b44707cd
commit
cbecece203
|
@ -3,7 +3,7 @@
|
|||
web-server/private/connection-manager)
|
||||
(provide connection-manager-tests)
|
||||
|
||||
(start-connection-manager (current-custodian))
|
||||
(start-connection-manager)
|
||||
|
||||
(define connection-manager-tests
|
||||
(test-suite
|
||||
|
|
|
@ -13,15 +13,15 @@
|
|||
[o-port output-port?]
|
||||
[custodian custodian?]
|
||||
[close? boolean?])]
|
||||
[start-connection-manager (custodian? . -> . void)]
|
||||
[start-connection-manager (-> void)]
|
||||
[new-connection (number? input-port? output-port? custodian? boolean? . -> . connection?)]
|
||||
[kill-connection! (connection? . -> . void)]
|
||||
[adjust-connection-timeout! (connection? number? . -> . void)])
|
||||
|
||||
;; start-connection-manager: custodian -> void
|
||||
;; calls the timer manager
|
||||
(define (start-connection-manager custodian)
|
||||
(start-timer-manager custodian))
|
||||
(define (start-connection-manager)
|
||||
(start-timer-manager))
|
||||
|
||||
;; new-connection: number i-port o-port custodian -> connection
|
||||
;; ask the connection manager for a new connection
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
;; start the server and return a thunk to shut it down
|
||||
(define (serve)
|
||||
(define the-server-custodian (make-custodian))
|
||||
(start-connection-manager the-server-custodian)
|
||||
(parameterize ([current-custodian the-server-custodian]
|
||||
[current-server-custodian the-server-custodian]
|
||||
#;[current-thread-initial-stack-size 3])
|
||||
(start-connection-manager)
|
||||
(thread
|
||||
(lambda ()
|
||||
(run-server config:port
|
||||
|
@ -40,10 +40,10 @@
|
|||
;; NOTE: (GregP) should allow the user to pass in a connection-custodian
|
||||
(define (serve-ports ip op)
|
||||
(define server-cust (make-custodian))
|
||||
(start-connection-manager server-cust)
|
||||
(parameterize ([current-custodian server-cust]
|
||||
[current-server-custodian server-cust])
|
||||
(define connection-cust (make-custodian))
|
||||
(start-connection-manager)
|
||||
(parameterize ([current-custodian connection-cust])
|
||||
(thread
|
||||
(lambda ()
|
||||
|
|
|
@ -8,32 +8,31 @@
|
|||
|
||||
(define timer-ch (make-async-channel))
|
||||
|
||||
; start-timer-manager : custodian -> void
|
||||
; start-timer-manager : -> void
|
||||
; The timer manager thread
|
||||
(define (start-timer-manager server-custodian)
|
||||
(parameterize ([current-custodian server-custodian])
|
||||
(thread
|
||||
(lambda ()
|
||||
(let loop ([timers null])
|
||||
#;(printf "Timers: ~a~n" (length timers))
|
||||
;; Wait for either...
|
||||
(apply sync
|
||||
;; ... a timer-request message ...
|
||||
(handle-evt
|
||||
timer-ch
|
||||
(lambda (req)
|
||||
;; represent a req as a (timer-list -> timer-list) function:
|
||||
;; add/remove/change timer evet:
|
||||
(loop (req timers))))
|
||||
;; ... or a timer
|
||||
(map (lambda (timer)
|
||||
(handle-evt
|
||||
(timer-evt timer)
|
||||
(lambda (_)
|
||||
;; execute timer
|
||||
((timer-action timer))
|
||||
(loop (remq timer timers)))))
|
||||
timers))))))
|
||||
(define (start-timer-manager)
|
||||
(thread
|
||||
(lambda ()
|
||||
(let loop ([timers null])
|
||||
#;(printf "Timers: ~a~n" (length timers))
|
||||
;; Wait for either...
|
||||
(apply sync
|
||||
;; ... a timer-request message ...
|
||||
(handle-evt
|
||||
timer-ch
|
||||
(lambda (req)
|
||||
;; represent a req as a (timer-list -> timer-list) function:
|
||||
;; add/remove/change timer evet:
|
||||
(loop (req timers))))
|
||||
;; ... or a timer
|
||||
(map (lambda (timer)
|
||||
(handle-evt
|
||||
(timer-evt timer)
|
||||
(lambda (_)
|
||||
;; execute timer
|
||||
((timer-action timer))
|
||||
(loop (remq timer timers)))))
|
||||
timers)))))
|
||||
(void))
|
||||
|
||||
;; Limitation on this add-timer: thunk cannot make timer
|
||||
|
@ -93,7 +92,7 @@
|
|||
[struct timer ([evt evt?]
|
||||
[expire-seconds number?]
|
||||
[action (-> void)])]
|
||||
[start-timer-manager (custodian? . -> . void)]
|
||||
[start-timer-manager (-> void)]
|
||||
[start-timer (number? (-> void) . -> . timer?)]
|
||||
[reset-timer! (timer? number? . -> . void)]
|
||||
[increment-timer! (timer? number? . -> . void)]
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
|
||||
@defproc[(start-timer-manager [cust custodian?])
|
||||
@defproc[(start-timer-manager)
|
||||
void]{
|
||||
Handles the execution and management of timers. Resources are charged to
|
||||
@scheme[cust].
|
||||
Handles the execution and management of timers.
|
||||
}
|
||||
|
||||
@defproc[(start-timer [s number?]
|
||||
|
@ -77,10 +76,9 @@ for doing this.
|
|||
The connection will last until @scheme[timer] triggers.
|
||||
}
|
||||
|
||||
@defproc[(start-connection-manager [parent-cust custodian?])
|
||||
@defproc[(start-connection-manager)
|
||||
void]{
|
||||
Runs the connection manager (now just the timer manager) will @scheme[parent-cust]
|
||||
as the custodian.
|
||||
Runs the connection manager (now just the timer manager).
|
||||
}
|
||||
|
||||
@defproc[(new-connection [timeout number?]
|
||||
|
|
Loading…
Reference in New Issue
Block a user