︙ | | | ︙ | |
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
(avail-cmboxes '()) ;; list of (<cookie> . <mbox>) for re-use
;; threads
(numthreads 10)
(cmd-thread #f)
(work-queue-thread #f)
(num-threads-running 0)
)
;;======================================================================
;; serialization
;; NOTE: I've had problems with read/write and s11n serialize, deserialize
;; thus the inefficient method here
;;======================================================================
|
>
>
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
(avail-cmboxes '()) ;; list of (<cookie> . <mbox>) for re-use
;; threads
(numthreads 10)
(cmd-thread #f)
(work-queue-thread #f)
(num-threads-running 0)
)
(define ulex-printer (make-parameter print))
;;======================================================================
;; serialization
;; NOTE: I've had problems with read/write and s11n serialize, deserialize
;; thus the inefficient method here
;;======================================================================
|
︙ | | | ︙ | |
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
(with-input-from-string
(z3:decode-buffer
(base64:base64-decode
(string-substitute
(regexp "_") "=" msg #t)))
(lambda ()(deserialize)))
(begin
(print "ULEX ERROR: cannot translate received data \""msg"\"")
(print-call-chain (current-error-port))
msg))) ;; crude reply for when things go awry
((write)(with-input-from-string msg (lambda ()(read))))
((s11n)(with-input-from-string msg (lambda ()(deserialize))))
(else msg))) ;; rpc
|
|
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
(with-input-from-string
(z3:decode-buffer
(base64:base64-decode
(string-substitute
(regexp "_") "=" msg #t)))
(lambda ()(deserialize)))
(begin
((ulex-printer) "ULEX ERROR: cannot translate received data \""msg"\"")
(print-call-chain (current-error-port))
msg))) ;; crude reply for when things go awry
((write)(with-input-from-string msg (lambda ()(read))))
((s11n)(with-input-from-string msg (lambda ()(deserialize))))
(else msg))) ;; rpc
|
︙ | | | ︙ | |
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
(dat (list my-host-port 'qrykey cmd params #;(cons (current-seconds)(current-milliseconds)))))
(cond
(isme (do-work udata dat)) ;; no transmission needed
(else
(handle-exceptions ;; TODO - MAKE THIS EXCEPTION CMD SPECIFIC?
exn
(begin
(print "ULEX send-receive: exn="exn)
(message exn))
(begin
;; (mutex-lock! *send-mutex*) ;; DOESN'T SEEM TO HELP
(let-values (((inp oup)(tcp-connect host port)))
(let ((res (if (and inp oup)
(begin
(write (obj->string dat) oup) ;; (write dat oup);; (serialize dat oup)
(close-output-port oup)
(string->obj (read inp))) ;; (deserialize inp))
(begin
(print "ERROR: send called but no receiver has been setup. Please call setup first!")
#f))))
;; (close-output-port oup)
(close-input-port inp)
;; (mutex-unlock! *send-mutex*) ;; DOESN'T SEEM TO HELP
res)))))))) ;; res will always be 'ack unless return-method is direct
;;======================================================================
|
|
|
|
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
(dat (list my-host-port 'qrykey cmd params #;(cons (current-seconds)(current-milliseconds)))))
(cond
(isme (do-work udata dat)) ;; no transmission needed
(else
(handle-exceptions ;; TODO - MAKE THIS EXCEPTION CMD SPECIFIC?
exn
(begin
((ulex-printer) "ULEX send-receive: exn="exn)
(message exn))
(begin
;; (mutex-lock! *send-mutex*) ;; DOESN'T SEEM TO HELP
(let-values (((inp oup)(tcp-connect host port)))
(let ((res (if (and inp oup)
(begin
(write (obj->string dat) oup) ;; (write dat oup);; (serialize dat oup)
(close-output-port oup)
(string->obj (read inp))) ;; (deserialize inp))
(begin
((ulex-printer) "ERROR: send called but no receiver has been setup. Please call setup first!")
#f))))
;; (close-output-port oup)
(close-input-port inp)
;; (mutex-unlock! *send-mutex*) ;; DOESN'T SEEM TO HELP
res)))))))) ;; res will always be 'ack unless return-method is direct
;;======================================================================
|
︙ | | | ︙ | |
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
(let* ((proc (udat-work-proc uconn))
(start-time (current-milliseconds))
(result (proc rem-host-port qrykey cmd params))
(end-time (current-milliseconds))
(run-time (- end-time start-time)))
result))))
(else
(print "ERROR: rdat "rdat", did not match rem-host-port qrykey cmd params")))))
;;======================================================================
;; misc utils
;;======================================================================
(define (pp-uconn uconn)
(pp (udat->alist uconn)))
|
|
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
(let* ((proc (udat-work-proc uconn))
(start-time (current-milliseconds))
(result (proc rem-host-port qrykey cmd params))
(end-time (current-milliseconds))
(run-time (- end-time start-time)))
result))))
(else
((ulex-printer) "ERROR: rdat "rdat", did not match rem-host-port qrykey cmd params")))))
;;======================================================================
;; misc utils
;;======================================================================
(define (pp-uconn uconn)
(pp (udat->alist uconn)))
|
︙ | | | ︙ | |