Index: apimod.scm ================================================================== --- apimod.scm +++ apimod.scm @@ -374,11 +374,11 @@ ((general-call) (let ((stmtname (car params)) (run-id (cadr params)) (realparams (cddr params))) (db:general-call dbstruct stmtname run-id realparams))) ((sdb-qry) (apply sdb:qry params)) - ((ping) (current-process-id)) + ((ping) `(#t ,(current-process-id) (cadr params))) ;; (current-process-id)) ((get-changed-record-ids) (apply db:get-changed-record-ids dbstruct params)) ((get-run-record-ids) (apply db:get-run-record-ids dbstruct params)) ;; TESTMETA ((testmeta-get-record) (apply db:testmeta-get-record dbstruct params)) Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -159,12 +159,12 @@ ;; set up the api proc, seems like there should be a better place for this? ;; ;; IS THIS NEEDED ANYMORE? TODO - REMOVE IF POSSIBLE ;; -(define api-proc (make-parameter conc)) -(api-proc api:execute-requests) +;; (define api-proc (make-parameter conc)) +;; (api-proc api:execute-requests) ;; do we have a connection to apath dbname and ;; is it not expired? then return it ;; ;; else setup a connection @@ -175,11 +175,12 @@ (let* ((fullname (db:dbname->path apath dbname)) (conn (hash-table-ref/default (servdat-conns remdat) fullname #f))) (if (and conn (< (current-seconds) (conndat-expires conn))) conn - #f))) + #f ;; TODO - convert this to a refresh for the given db? (server could have moved) + ))) (define (rmt:find-main-server uconn apath dbname) (let* ((pktsdir (get-pkts-dir apath)) (all-srvpkts (get-all-server-pkts pktsdir *srvpktspec*)) ;; (dbpath (conc apath "/" dbname)) @@ -231,11 +232,12 @@ (mutex-lock! *connstart-mutex*) (if (> (- (current-seconds) *last-main-start*) 5) ;; at least four seconds since last attempt to start main server (begin (api:run-server-process apath dbname) (set! *last-main-start* (current-seconds)) - (thread-sleep! 1))) + (thread-sleep! 1)) + (thread-sleep! 0.25)) (mutex-unlock! *connstart-mutex*) (rmt:open-main-connection remdat apath) ;; TODO: Add limit to number of tries ))) (if (not the-srv) ;; have server, try connecting to it (start-main-srv) @@ -354,20 +356,21 @@ ;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed ;; sometime in the future ;; (define (rmt:send-receive-real sinfo apath dbname cmd params) - (let* ((conn (rmt:get-conn sinfo apath dbname))) - (assert conn "FATAL: rmt:send-receive-real called without the needed channels opened") + (let* ((cdat (rmt:get-conn sinfo apath dbname))) + (assert cdat "FATAL: rmt:send-receive-real called without the needed channels opened") (let* ((key #f) (payload `((cmd . ,cmd) - (key . ,(conndat-srvkey conn)) + (key . ,(conndat-srvkey cdat)) (params . ,params))) - (res (send-receive conn cmd payload))) + (uconn (servdat-uconn sinfo)) + (res (send-receive uconn (conndat-hostport cdat) cmd payload))) (if (member res '("#")) ;; TODO - fix this in string->sexpr #f - (string->sexpr res))))) + res)))) ;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed ;; sometime in the future. ;; ;; Purpose - call the main.db server and request a server be started @@ -1644,11 +1647,12 @@ (servdat-uconn *db-serv-info*)) (let* ((uconn (servdat-uconn *db-serv-info*))) (wait-and-close uconn)) (let* ((port (portlogger:open-run-close portlogger:find-port)) (handler-proc (lambda (rem-host-port qrykey cmd params) ;; - (api:execute-requests *dbstruct-db* cmd params)))) + (let* ((prms (alist-ref 'params params))) + (api:execute-requests *dbstruct-db* cmd prms #;params))))) ;; (api:process-request *dbstuct-db* (if (not *db-serv-info*) (set! *db-serv-info* (make-servdat host: hostn port: port))) (let* ((uconn (run-listener handler-proc port)) (rport (udat-port uconn))) ;; the real port @@ -1792,11 +1796,11 @@ (let* ((data (sexpr->string `((cmd . ping) (key . ,key) (params . ())))) (res (send-receive uconn host-port 'ping data))) (if res - (string->sexpr res) + (car res) res))) ; from the pkts return servers associated with dbpath ;; NOTE: Only one can be alive - have to check on each ;; in the list of pkts returned Index: tests/unittests/basicserver.scm ================================================================== --- tests/unittests/basicserver.scm +++ tests/unittests/basicserver.scm @@ -25,13 +25,13 @@ (import rmtmod trace http-client apimod dbmod launchmod srfi-69 ulex system-information) (trace-call-sites #t) (trace - get-the-server + ;; get-the-server ;; db:get-dbdat - ;; rmt:find-main-server + rmt:find-main-server ;; rmt:send-receive-real ;; rmt:send-receive ;; sexpr->string server-ready? ;; rmt:register-server @@ -48,13 +48,23 @@ ;; rmt:run ;; rmt:try-start-server ;; ;; ulex ;; - wait-and-close - run-listener + ;; wait-and-close + ;; run-listener ) + +(define-syntax run-in-thread + (syntax-rules () + ((_ body ...) + (let ((th1 (make-thread (lambda () + body ...) + "the thread"))) + (thread-start! th1) + (thread-join! th1))))) + (test #f #t (servdat? (let ((s (make-servdat))) (set! *servdat* s) s))) (test #f #f (rmt:get-conn *servdat* *toppath* ".db/main.db")) @@ -68,11 +78,12 @@ (define *uconn* (servdat-uconn *db-serv-info*)) (print "*uconn*: " *uconn*) (test #f #t (ulex-listener? (servdat-uconn *db-serv-info*))) (test #f #t (string? (udat-host-port *uconn*))) -(test #f #t (server-ready? *db-serv-dat* (udat-host-port *db-serv-dat*))) +(run-in-thread + (test #f #t (server-ready? *uconn* (udat-host-port *uconn*) (servdat-uuid *db-serv-info*)))) (test #f #t (rmt:open-main-connection *db-serv-info* *toppath*)) ;; (pp (hash-table->alist (remotedat-conns *db-serv-info*))) (test #f #t (conndat? (rmt:get-conn *db-serv-info* *toppath* ".db/main.db"))) (exit) Index: ulex/ulex.scm ================================================================== --- ulex/ulex.scm +++ ulex/ulex.scm @@ -25,10 +25,12 @@ ;; ;;====================================================================== (module ulex ( + + ;; NOTE: looking for the handler proc - find the run-listener :) run-listener ;; (run-listener handler-proc [port]) => uconn ;; NOTE: handler-proc params; ;; (handler-proc rem-host-port qrykey cmd params)