Index: apimod.scm ================================================================== --- apimod.scm +++ apimod.scm @@ -403,16 +403,16 @@ ;; api:process-request ;; db:* ;; ;; NB// Runs on the server as part of the server loop ;; -(define (api:process-request dbstruct $) ;; the $ is the request vars proc +(define (api:process-request dbstruct indat) ;; the $ is the request vars proc (debug:print 0 *default-log-port* "server-id:" *server-id*) - (let* ((cmd-in ($ 'cmd)) + (let* ((cmd-in (alist-ref 'cmd indat)) ;; ($ 'cmd)) (cmd (if (string? cmd-in)(string->symbol cmd-in) cmd-in)) - (params (string->sexpr ($ 'params))) - (key ($ 'key)) ;; TODO - add this back + (params (string->sexpr (alist-ref 'params indat))) + (key (alist-ref 'key indat)) ;; TODO - add this back ) (debug:print 0 *default-log-port* "cmd:" cmd " with params " params "key " key) (if (equal? key "nokey") ;; *server-id*) ;; TODO - get real key involved (begin (set! *api-process-request-count* (+ *api-process-request-count* 1)) Index: commonmod.scm ================================================================== --- commonmod.scm +++ commonmod.scm @@ -3781,8 +3781,8 @@ exn (begin (debug:print 0 *default-log-port* "ERROR: string->sexpr bad input \""instr"\"") #f) (with-input-from-string instr - (lambda ()(read))))) + read))) ) Index: fullrununit.sh ================================================================== --- fullrununit.sh +++ fullrununit.sh @@ -1,6 +1,6 @@ #!/bin/bash (killall mtest -v;sleep 1;killall mtest -v -9;rm -f tests/simplerun/.db/* tests/simplerun/logs/* tests/basicserver.log) & ck5 make -j install && wait && -ck5 make unit +script -c "ck5 make unit" Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -51,11 +51,12 @@ chicken.process chicken.process-context chicken.process-context.posix chicken.sort chicken.string - chicken.tcp chicken.random + ;; chicken.tcp + chicken.random chicken.time chicken.time.posix (prefix sqlite3 sqlite3:) directory-utils @@ -272,12 +273,12 @@ (rmt:general-open-connection conns apath dbname) (rmt:send-receive-real conns apath dbname cmd params))) (define (rmt:send-receive-setup conn) (if (not (rmt:conn-inport conn)) - (let-values ((i o) (tcp-connect (rmt:conn-ipaddr conn) - (rmt:conn-port port))) + (let-values (((i o) (tcp-connect (rmt:conn-ipaddr conn) + (rmt:conn-port conn)))) (rmt:conn-inport-set! conn i) (rmt:conn-outport-set! conn o)))) ;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed ;; sometime in the future @@ -296,10 +297,12 @@ (rmt:conn-inport conn) read-string)))) (if (string? res) (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 @@ -1810,28 +1813,30 @@ (define (server-address srv-pkt) (conc (alist-ref 'host srv-pkt) ":" (alist-ref 'port srv-pkt))) (define (server-ready? host port key) ;; 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* ((res (with-input-from-request - (conc "http://"host":"port"/ping") ;; returns *toppath*/dbname - #f - read-string))) - (if (equal? res key) - #t + (let-values (((i o)(handle-exceptions + exn + (values #f #f) + (tcp-connect host port)))) + (if (and i o) (begin - (debug:print-info 0 *default-log-port* "server-ready? key="key", received="res) - #f))) - - #f - ) - + (write `((cmd . ping) + (key . ,key) + (params . ())) o) + (let ((res (with-input-from-port i + read))) + (close-output-port o) + (close-input-port i) + (if (string? res) + (string->sexpr res) + res))) + (begin ;; connection failed + (debug:print-info 0 *default-log-port* "Server at "host":"port" is not responding.") + #f)))) + (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 '()))) Index: tests/unittests/basicserver.scm ================================================================== --- tests/unittests/basicserver.scm +++ tests/unittests/basicserver.scm @@ -22,10 +22,11 @@ ;; ;; ./rununittest.sh server 1;(cd simplerun;megatest -stop-server 0) (import rmtmod trace http-client apimod dbmod launchmod) + (trace-call-sites #t) (trace ;; db:get-dbdat ;; rmt:find-main-server rmt:send-receive-real @@ -39,11 +40,13 @@ ;; common:watchdog ;; rmt:find-main-server ;; get-all-server-pkts ;; get-viable-servers ;; get-best-candidate - ;; api:run-server-process + api:run-server-process + rmt:run + rmt:try-start-server ) (test #f #t (rmt:remote? (let ((r (make-rmt:remote))) (set! *rmt:remote* r) r))) @@ -70,10 +73,13 @@ (define remote *rmt:remote*) (define keyvals '(("SYSTEM" "a")("RELEASE" "b"))) (test #f 'server-started (api:execute-requests *db* 'get-server (list *toppath* ".db/2.db"))) (set! *dbstruct-db* #f) + +(exit) + (test #f #t (rmt:open-main-connection remote apath)) (test #f #t (rmt:conn? (rmt:get-conn *rmt:remote* *toppath* ".db/main.db"))) (test #f 'server-started (rmt:send-receive-real *rmt:remote* *toppath* ".db/main.db" 'get-server `(,apath ,dbname))) (thread-sleep! 2)