Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -82,17 +82,16 @@ (rmt:setup-ulex alldat)))) (ulex:connect ulexdat dbfname dbtype))) ;; setup the remote calls (define (rmt:setup-ulex alldat) - (let* ((new-ulexdat (ulex:setup))) ;; establish connection to ulex - (alldat-ulexdat-set! alldat new-ulexdat) - (let ((udata (alldat-ulexdat alldat))) - ;; register all needed procs - (ulex:register-handler udata 'ping common:get-full-version) - (ulex:register-handler udata 'login common:get-full-version) ;; force setup of the connection - new-ulexdat))) + (let* ((udata (ulex:setup))) ;; establish connection to ulex + (alldat-ulexdat-set! alldat udata) + ;; register all needed procs + (ulex:register-handler udata 'ping common:get-full-version) ;; override ping with get-full-version + (ulex:register-handler udata 'login common:get-full-version) ;; force setup of the connection + udata)) ;; set up a connection to the current owner of the dbfile associated with rid ;; then send the query to that dbfile owner and wait for a response. ;; (define (rmt:send-receive cmd rid params #!key (attemptnum 1)(area-dat #f)) ;; start attemptnum at 1 so the modulo below works as expected Index: ulex/ulex.scm ================================================================== --- ulex/ulex.scm +++ ulex/ulex.scm @@ -67,10 +67,11 @@ (udat-captain-port-set! udata port) (udat-captain-pid-set! udata pid) (if (ping udata (conc ipaddr ":" port)) udata (begin + (print "Found unreachable captain at " ipaddr ":" port ", removing pkt") (remove-captain-pkt udata captn) (setup)))) (begin (setup-as-captain udata) ;; this saves the thread to captain-thread and starts the thread (setup))) @@ -80,12 +81,12 @@ (define (connect udata dbfname dbtype) udata) (define (ping udata host-port) (let* ((cookie (make-cookie udata)) - (res (send-receive udata host-port 'ping "just pinging" (conc (current-seconds))))) - (print "got res=" res) + (res (send-receive udata host-port 'ping "just pinging" (conc (current-seconds)) timeout: 1))) + ;; (print "got res=" res) (equal? res cookie) )) ;;====================================================================== ;; network utilities @@ -310,12 +311,11 @@ (if (start-server-find-port udata) ;; puts the server in udata (if (create-captain-pkt udata) (let* ((th (make-thread (lambda () (ulex-handler udata)) "Captain handler"))) (udat-handler-thread-set! udata th) - (thread-start! th) - udata) + (thread-start! th)) #f) #f)) (define (get-peer-dat udata host-port #!optional (hostname #f)(pid #f)) (let* ((pdat (or (hash-table-ref/default (udat-outgoing-conns udata) host-port #f) @@ -366,22 +366,24 @@ #f))) ;; #f means failed to connect and send ;; send a request to the given host-port and register a mailbox in udata ;; wait for the mailbox data and return it ;; -(define (send-receive udata host-port handler qrykey data #!key (hostname #f)(pid #f)(params '())) +(define (send-receive udata host-port handler qrykey data #!key (hostname #f)(pid #f)(params '())(timeout 20)) (let ((mbox (make-mailbox)) (mbox-time (current-milliseconds)) (mboxes (udat-mboxes udata))) (hash-table-set! mboxes qrykey mbox) (if (send udata host-port handler qrykey data hostname: hostname pid: pid params: params) - (let* ((mbox-timeout-secs 20) + (let* ((mbox-timeout-secs timeout) (mbox-timeout-result 'MBOX_TIMEOUT) (res (mailbox-receive! mbox mbox-timeout-secs mbox-timeout-result)) (mbox-receive-time (current-milliseconds))) (hash-table-delete! mboxes qrykey) - res) + (if (eq? res 'MBOX_TIMEOUT) + #f + res)) #f))) ;; #f means failed to communicate (define (add-to-work-queue udata peer-dat handlerkey qrykey data) (let ((wdat (make-work peer-dat: peer-dat handlerkey: handlerkey qrykey: qrykey data: data))) (if (udat-busy udata)