34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
fail_count INTEGER DEFAULT 0,
update_time TIMESTAMP DEFAULT (strftime('%s','now')) );"))
db))
(define (portlogger:open-run-close proc . params)
(handle-exceptions
exn
(print "ERROR: portlogger:open-run-close failed. " proc " " params)
(let* ((db (portlogger:open-db (conc "/tmp/." (current-user-name) "-portlogger.db")))
(res (apply proc db params)))
(sqlite3:finalize! db)
res)))
;; (fold-row PROC INIT DATABASE SQL . PARAMETERS)
(define (portlogger:take-port db portnum)
|
>
|
>
>
>
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
fail_count INTEGER DEFAULT 0,
update_time TIMESTAMP DEFAULT (strftime('%s','now')) );"))
db))
(define (portlogger:open-run-close proc . params)
(handle-exceptions
exn
(begin
(debug:print 0 "ERROR: portlogger:open-run-close failed. " proc " " params)
(debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn))
(debug:print 0 "exn=" (condition->list exn))
(print-call-chain))
(let* ((db (portlogger:open-db (conc "/tmp/." (current-user-name) "-portlogger.db")))
(res (apply proc db params)))
(sqlite3:finalize! db)
res)))
;; (fold-row PROC INIT DATABASE SQL . PARAMETERS)
(define (portlogger:take-port db portnum)
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
(define (portlogger:get-prev-used-port db)
(sqlite3:fold-row
(lambda (var curr)
(or curr var curr))
#f
db
"SELECT (port) FROM ports WHERE state='released' LIMIT 1;"))
;; set port to "released", "failed" etc.
;;
(define (portlogger:set-port db portnum value)
(sqlite3:execute db "UPDATE ports SET state=?,update_time=strftime('%s','now') WHERE port=?;" value portnum))
;; set port to failed (attempted to take but got error)
|
>
>
>
>
>
>
>
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
(define (portlogger:get-prev-used-port db)
(sqlite3:fold-row
(lambda (var curr)
(or curr var curr))
#f
db
"SELECT (port) FROM ports WHERE state='released' LIMIT 1;"))
(define (portlogger:find-port db)
(let ((portnum (or (portlogger:get-prev-used-port db)
(+ 50000 ;; top of registered ports
(random (- 60000 50000))))))
(portlogger:take-port db portnum)
portnum))
;; set port to "released", "failed" etc.
;;
(define (portlogger:set-port db portnum value)
(sqlite3:execute db "UPDATE ports SET state=?,update_time=strftime('%s','now') WHERE port=?;" value portnum))
;; set port to failed (attempted to take but got error)
|