db: clean up disconnect

This commit is contained in:
Ryan Culpepper 2012-01-17 00:06:31 -07:00
parent f142a1c5f2
commit 766790b9e4
5 changed files with 42 additions and 53 deletions

View File

@ -77,10 +77,24 @@
;; ---------------------------------------- ;; ----------------------------------------
;; Connection base class (locking) (define debugging%
(class object%
(super-new)
(field [DEBUG? #f])
(define/public (debug debug?)
(set! DEBUG? debug?))
(define/public (dprintf fmt . args)
(when DEBUG? (apply fprintf (current-error-port) fmt args)))
))
;; ----------------------------------------
(define locking% (define locking%
(class object% (class debugging%
;; == Communication locking ;; == Communication locking
@ -185,24 +199,33 @@
;; ---------------------------------------- ;; ----------------------------------------
(define debugging% (define disconnect%
(class locking% (class locking%
(inherit dprintf
call-with-lock*
connected?)
(super-new) (super-new)
(field [DEBUG? #f]) ;; disconnect : -> void
(define/public (disconnect)
(when (connected?)
(call-with-lock* 'disconnect
(lambda () (disconnect* #t))
(lambda () (disconnect* #f))
#f)))
(define/public (debug debug?) (define/public (disconnect* politely?)
(set! DEBUG? debug?)) (dprintf " ** disconnecting~a\n" (if politely? " politely" ""))
(void))
(define/public (dprintf fmt . args) (define/override (on-break-within-lock)
(when DEBUG? (apply fprintf (current-error-port) fmt args))) (dprintf " ** break occurred within lock\n")
(disconnect* #f))))
))
;; ---------------------------------------- ;; ----------------------------------------
(define transactions% (define transactions%
(class debugging% (class disconnect%
(inherit dprintf) (inherit dprintf)
(inherit-field DEBUG?) (inherit-field DEBUG?)

View File

@ -143,23 +143,12 @@
(err next)]) (err next)])
next)) next))
(define/override (on-break-within-lock)
(disconnect* #f))
;; ======================================== ;; ========================================
;; Connection management ;; Connection management
;; disconnect : -> void (define/override (disconnect* politely?)
(define/public (disconnect) (super disconnect* politely?)
(when (connected?)
(call-with-lock* 'disconnect
(lambda () (disconnect* #t))
(lambda () (disconnect* #f))
#f)))
(define/private (disconnect* politely?)
(dprintf " ** Disconnecting\n")
(let ([outport* outport] (let ([outport* outport]
[inport* inport]) [inport* inport])
(when outport* (when outport*

View File

@ -51,9 +51,6 @@
check-valid-tx-status check-valid-tx-status
check-statement/tx) check-statement/tx)
(define/override (on-break-within-lock)
(disconnect*))
(define/public (get-db fsym) (define/public (get-db fsym)
(unless db (unless db
(error/not-connected fsym)) (error/not-connected fsym))
@ -479,11 +476,8 @@
(handle-status fsym status stmt) (handle-status fsym status stmt)
(vector name type size digits))))) (vector name type size digits)))))
(define/public (disconnect) (define/override (disconnect* _politely?)
(define (go) (disconnect*)) (super disconnect* _politely?)
(call-with-lock* 'disconnect go go #f))
(define/private (disconnect*)
(start-atomic) (start-atomic)
(let ([db* db] (let ([db* db]
[env* env]) [env* env])

View File

@ -130,9 +130,6 @@
[(and or-eof? (eof-object? r)) (void)] [(and or-eof? (eof-object? r)) (void)]
[else (error/comm fsym "expected ready")]))) [else (error/comm fsym "expected ready")])))
(define/override (on-break-within-lock)
(disconnect* #f))
;; == Asynchronous messages ;; == Asynchronous messages
;; handle-async-message : message -> void ;; handle-async-message : message -> void
@ -157,17 +154,9 @@
;; == Connection management ;; == Connection management
;; disconnect : -> void
(define/public (disconnect)
(when (connected?)
(call-with-lock* 'disconnect
(lambda () (disconnect* #t))
(lambda () (disconnect* #f))
#f)))
;; disconnect* : boolean -> void ;; disconnect* : boolean -> void
(define/private (disconnect* politely?) (define/override (disconnect* politely?)
(dprintf " ** Disconnecting\n") (super disconnect* politely?)
(let ([outport* outport] (let ([outport* outport]
[inport* inport]) [inport* inport])
(when outport* (when outport*

View File

@ -37,9 +37,6 @@
(define/override (call-with-lock fsym proc) (define/override (call-with-lock fsym proc)
(call-with-lock* fsym (lambda () (set! saved-tx-status (get-tx-status)) (proc)) #f #t)) (call-with-lock* fsym (lambda () (set! saved-tx-status (get-tx-status)) (proc)) #f #t))
(define/override (on-break-within-lock)
(disconnect*))
(define/private (get-db fsym) (define/private (get-db fsym)
(or -db (error/not-connected fsym))) (or -db (error/not-connected fsym)))
@ -196,11 +193,8 @@
(hash-set! statement-table pst #t) (hash-set! statement-table pst #t)
pst))) pst)))
(define/public (disconnect) (define/override (disconnect* _politely?)
(define (go) (disconnect*)) (super disconnect* _politely?)
(call-with-lock* 'disconnect go go #f))
(define/private (disconnect*)
(start-atomic) (start-atomic)
(let ([db -db]) (let ([db -db])
(set! -db #f) (set! -db #f)