Index: ulex/ulex.scm ================================================================== --- ulex/ulex.scm +++ ulex/ulex.scm @@ -163,15 +163,16 @@ (if (eq? (send uconn host-port qrykey cmd data) 'ack) (let* ((mbox-timeout-secs 120) ;; timeout) (mbox-timeout-result 'MBOX_TIMEOUT) (res (mailbox-receive! mbox mbox-timeout-secs mbox-timeout-result)) (mbox-receive-time (current-milliseconds))) - (print "In send-receive, got "res" back from mailbox") (if (eq? res 'MBOX_TIMEOUT) #f ;; convert to raising exception? res)) - #f))) ;; #f means failed to communicate + (begin + (print "ERROR: Communication failed?") + #f)))) ;; #f means failed to communicate ;;====================================================================== ;; responder side ;;====================================================================== @@ -178,18 +179,18 @@ ;; take a request, rdata, and if not immediate put it in the work queue ;; ;; Reserved cmds; ack ping goodbye response ;; (define (ulex-handler uconn rdata) - (print "ulex-handler received data: "rdata) (match rdata ;; (string-split controldat) - ((rem-host-port qrykey cmd params) ;; cmdkey host-port pid qrykey params ...) + ((rem-host-port qrykey cmd params) + ;; (print "ulex-handler got: "rem-host-port" qrykey: "qrykey" cmd: "cmd" params: "params) (let ((mbox (hash-table-ref/default (udat-mboxes uconn) qrykey #f))) (case cmd ;; ((ack )(print "Got ack! But why? Should NOT get here.") 'ack) ((ping) - (print "Got Ping!") + ;; (print "Got Ping!") (add-to-work-queue uconn rdata) 'ack) ((goodbye) ;; just clear out references to the caller (add-to-work-queue uconn rdata) @@ -200,13 +201,14 @@ (mailbox-send! mbox params) ;; params here is our result 'ack) (begin (print "ERROR: received result but no associated mbox for cookie "qrykey) #f))) - ((else - (add-to-work-queue uconn rdata) - 'ack))))) + (else + ;; (print "Got generic request: "cmd) + (add-to-work-queue uconn rdata) + 'ack)))) (else (print "BAD DATA? controldat=" rdata) 'ack) ;; send ack anyway? )) @@ -379,32 +381,42 @@ ;; (host-information (current-hostname)))))) ) -(import ulex trace big-chicken srfi-18 test) +(import ulex trace big-chicken srfi-18 test matchable) (trace-call-sites #t) (trace ;; ulex-handler ;; send + ;; add-to-work-queue ) -(define (handler-proc . data) - (print "handler-proc, got: "data) - `(data ,data)) +(define (handler-proc rem-host-port qrykey cmd params) + (print "handler-proc "rem-host-port" "qrykey" "cmd" "params) + (case cmd + ((ping) 'pong) + ((calc) (eval (with-input-from-string params read))) + ((print) + (print "params="params) + params) + ((reflect) `(,rem-host-port ,qrykey ,cmd ,params)) + (else `(data ,data)))) (define uconn (run-listener handler-proc)) (pp-uconn uconn) ;; super basic loop back test (define res #f) (define th1 (make-thread (lambda () - (test #f 'ack (send-receive uconn "zeus:4242" 'ping '()))) - (set! res (send-receive uconn "zeus:4242" 'ping '())))) + (test #f 10 (send-receive uconn "zeus:4242" 'calc "(+ 5 5)")) + (set! res (send-receive uconn "zeus:4242" 'ping '())) + (test #f 'pong (send-receive uconn "zeus:4242" 'ping '())) + ))) + (thread-start! th1) (thread-join! th1) -(thread-sleep! 1) (print "All done") (print "Received "res)