Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -265,17 +265,10 @@ (assert (not (equal? dbname ".db/main.db")) "ERROR: general-open-connection should never be called with main as the db") (let* ((mdbname (db:run-id->dbname #f)) (fullname (db:dbname->path apath dbname)) (conns (remotedat-conns remdat)) (mconn (rmt:get-conn remdat apath mdbname))) - (if (and mconn - (not (debug:print-logger))) - (if (equal? dbname ".db/main.db") - (debug:print-info 0 *default-log-port* "Not turning on logging to main, I am main!") - (begin - (debug:print-info 0 *default-log-port* "Turning on logging to main, look in logs dir for main log.") - (debug:print-logger rmt:log-to-main)))) (cond ((or (not mconn) ;; no channel open to main? (< (conndat-expires mconn)(+ (current-seconds) 2))) ;; restablish connection if less than 2 seconds on the lease (rmt:open-main-connection remdat apath) (rmt:general-open-connection remdat apath mdbname)) @@ -305,10 +298,11 @@ fullname (make-conndat apath: apath dbname: dbname hostport: (conc host":"port) + socket: (open-nn-connection (conc host":"port)) ipaddr: ipaddr port: port srvkey: servkey lastmsg: (current-seconds) expires: (+ (current-seconds) 60)))) @@ -316,11 +310,16 @@ (debug:print-info 0 *default-log-port* "return data from starting server did not match host port servkey pid ipaddr apath dbname " res))) res) (begin (debug:print-info 0 *default-log-port* "Unexpected result: " res) res))))))) - #t)) + (if (and mconn + (not (debug:print-logger))) + (begin + (debug:print-info 0 *default-log-port* "Turning on logging to main, look in logs dir for main log.") + (debug:print-logger rmt:log-to-main))) + #t)) ;;====================================================================== ;; FOR DEBUGGING SET TO #t ;; (define *localmode* #t) @@ -340,13 +339,12 @@ (indat `((cmd . ,cmd)(params . ,params)))) (api:process-request *dbstruct* indat) ;; (api:process-request dbdat indat) ) (begin - (if rid - (rmt:general-open-connection remdat apath dbname) ;; was conns - (rmt:open-main-connection remdat apath)) + (rmt:open-main-connection remdat apath) + (if rid (rmt:general-open-connection remdat apath dbname)) (rmt:send-receive-real remdat apath dbname cmd params))))) #;(define (rmt:send-receive-setup conn) (if (not (conndat-inport conn)) (let-values (((i o) (tcp-connect (conndat-ipaddr conn) @@ -358,17 +356,19 @@ ;; sometime in the future ;; (define (rmt:send-receive-real remdat apath dbname cmd params) (let* ((conn (rmt:get-conn remdat apath dbname))) (assert conn "FATAL: rmt:send-receive-real called without the needed channels opened") - (let* ((key #f) + (assert (conndat-socket conn) "FATAL: rmt:send-receive-real called without the channel socket opened.") + (let* ((soc (conndat-socket conn)) + (key #f) (host (conndat-ipaddr conn)) (port (conndat-port conn)) (payload `((cmd . ,cmd) (key . ,(conndat-srvkey conn)) (params . ,params))) - (res (open-send-receive-nn (conc host":"port) + (res (send-receive-nn soc ;; (open-send-receive-nn (conc host":"port) (sexpr->string payload)))) (string->sexpr res)))) ;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed ;; sometime in the future. @@ -2392,11 +2392,11 @@ ;;start a server, returns the connection ;; (define (start-nn-server portnum ) (let ((rep (make-rep-socket))) ;; (nn-socket 'rep))) (socket-set! rep 'nng/recvtimeo 2000) - (handle-exceptions + (handle-exceptions ;; why have exception handler here? exn (let ((emsg ((condition-property-accessor 'exn 'message) exn))) (print "ERROR: Failed to start server \"" emsg "\"") (exit 1)) @@ -2404,12 +2404,12 @@ rep)) (define (open-nn-connection host-port) (let ((req (make-req-socket)) (uri (conc "tcp://" host-port))) - (socket-set! req 'nng/recvtimeo 2000) (nng-dial req uri) + (socket-set! req 'nng/recvtimeo 2000) req)) (define (send-receive-nn req msg) (nng-send req msg) (nng-recv req))