Index: http-transportmod.scm ================================================================== --- http-transportmod.scm +++ http-transportmod.scm @@ -175,10 +175,14 @@ ((equal? (uri-path (request-uri (current-request))) '(/ "ping")) (send-response body: (conc *toppath*"/"(args:get-arg "-db")) headers: '((content-type text/plain)))) ((equal? (uri-path (request-uri (current-request))) + '(/ "loop-test")) + (send-response body: (alist-ref 'data ($)) + headers: '((content-type text/plain)))) + ((equal? (uri-path (request-uri (current-request))) '(/ "")) (send-response body: ((http-get-function 'http-transport:main-page)))) ((equal? (uri-path (request-uri (current-request))) '(/ "json_api")) (send-response body: ((http-get-function 'http-transport:main-page)))) @@ -298,10 +302,18 @@ (mutex-unlock! *http-mutex*)) (define (http-transport:inc-requests-and-prep-to-close-all-connections) (mutex-lock! *http-mutex*) (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*))) + +(define (sexpr->string data) + (with-output-to-string + (lambda ()(write data)))) + +(define (string->sexpr instr) + (with-input-from-string instr + (lambda ()(read)))) ;; serverdat contains uuid to be used for connection validation ;; ;; NOTE: serverdat must be initialized or created by servdat-init ;; @@ -483,11 +495,23 @@ #t (begin (debug:print-info 0 *default-log-port* "server-ready? key="key", received="res) #f)))) -;; from the pkts return servers associated with dbpath +(define (loop-test host port data) ;; server-address is host:port + ;; ping the server and ask it + ;; if it ready + ;; (let* ((sdat (servdat-init #f host port #f))) + ;; (http-transport:send-receive sdat "abc" 'ping '()))) + (let* ((payload (sexpr->string data)) + (res (with-input-from-request + (conc "http://"host":"port"/loop-test") ;; returns *toppath*/dbname + `((data . ,payload)) + read-string))) + (string->sexpr 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 ;; (define (get-viable-servers serv-pkts dbpath) (let loop ((tail serv-pkts) Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -157,10 +157,13 @@ (defstruct rmt:conn (apath #f) (dbname #f) (fullname #f) (hostport #f) + (ipaddr #f) + (port #f) + (srvpkt #f) (lastmsg 0) (expires 0)) ;; replaces *runremote* (define *rmt:remote* (make-rmt:remote)) @@ -174,14 +177,14 @@ ;; else setup a connection ;; ;; if that fails, return '(#f "some reason") ;; NB// convert to raising an exception ;; (define (rmt:get-connection remote apath dbname) - (let* ((fullname (db:dbname->path apath dbname)) - (conn (hash-table-ref/default (rmt:remote-conns remote) fullname #f))) + (let* ((fullname (db:dbname->path apath dbname)) ;; we'll switch to full name later + (conn (hash-table-ref/default (rmt:remote-conns remote) dbname #f))) (if (and conn - (> (current-seconds) (rmt:conn-expires conn))) + (< (current-seconds) (rmt:conn-expires conn))) conn #f))) (define (rmt:find-main-server apath dbname) (let* ((pktsdir (get-pkts-dir apath)) @@ -198,11 +201,11 @@ (the-srv (rmt:find-main-server apath dbname)) (start-main-srv (lambda () ;; srv not ready, delay a little and try again (system (conc "nbfake megatest -server - -area "apath " -db "dbname)) - (thread-sleep! 1.5) + (thread-sleep! 2) (rmt:open-main-connection remote apath) ;; TODO: Add limit to number of tries ))) (if the-srv ;; yes, we have a server, now try connecting to it (let* ((srv-addr (server-address the-srv)) (ipaddr (alist-ref 'ipaddr the-srv)) @@ -210,16 +213,19 @@ (fullpath (db:dbname->path apath dbname)) (srvready (server-ready? ipaddr port fullpath))) (if srvready (begin (hash-table-set! (rmt:remote-conns remote) - fullpath + dbname ;; fullpath ;; yes, I'd prefer it to be fullpath - FIXME later (make-rmt:conn apath: apath dbname: dbname fullname: fullpath hostport: srv-addr + ipaddr: ipaddr + port: port + srvpkt: the-srv lastmsg: (current-seconds) expires: (+ (current-seconds) 60) ;; this needs to be gathered during the ping )) #t) (start-main-srv))) Index: tests/unittests/basicserver.scm ================================================================== --- tests/unittests/basicserver.scm +++ tests/unittests/basicserver.scm @@ -20,11 +20,11 @@ ;; Run like this: ;; ;; ./rununittest.sh server 1;(cd simplerun;megatest -stop-server 0) -(import rmtmod trace) +(import rmtmod trace http-transportmod) (trace-call-sites #t) (trace ;; rmt:find-main-server ) @@ -32,10 +32,15 @@ (set! *rmt:remote* r) r))) (test #f #f (rmt:get-connection *rmt:remote* *toppath* ".db/main.db")) (test #f #f (rmt:find-main-server *toppath* ".db/main.db")) (test #f #t (rmt:open-main-connection *rmt:remote* *toppath*)) +(pp (hash-table->alist (rmt:remote-conns *rmt:remote*))) +(test #f #t (rmt:conn? (rmt:get-connection *rmt:remote* *toppath* ".db/main.db"))) +(define *main* (rmt:get-connection *rmt:remote* *toppath* ".db/main.db")) + +(test #f 'a (loop-test (rmt:conn-ipaddr *main*)(rmt:conn-port *main*) 'a)) ;; (delete-file* "logs/1.log") ;; (define run-id 1) ;; (test "setup for run" #t (begin (launch:setup)