Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -117,11 +117,11 @@ (defstruct servdat (host (get-host-name)) (port #f) (uuid #f) (dbfile #f) - (uconn (make-udat host: (get-host-name))) ;; this is the listener *FOR THIS PROCESS* + (uconn (make-udat host: (get-host-name))) ;; this is the ulex record *FOR THIS PROCESS* (mode #f) (status 'starting) (trynum 0) ;; count the number of ports we've tried (conns (make-hash-table)) ;; apath/dbname => conndat ) @@ -198,19 +198,12 @@ ;; (define (rmt:open-main-connection remdat apath) (let* ((fullpath (db:dbname->path apath ".db/main.db")) (conns (servdat-conns remdat)) (conn (rmt:get-conn remdat apath ".db/main.db")) ;; (hash-table-ref/default conns fullpath #f)) ;; TODO - create call for this - (start-rmt:run (lambda () - ;; (set! *db-serv-info* (make-servdat host: (get-host-name))) - (servdat-mode-set! *db-serv-info* 'non-db) - (servdat-uconn-set! *db-serv-info* (make-udat)))) - (myconn (servdat-uconn *db-serv-info*))) + (myconn (servdat-uconn remdat))) (cond - ((not *db-serv-info*) ;; myconn) - (start-rmt:run) - (rmt:open-main-connection remdat apath)) ((and conn ;; conn is NOT a socket, just saying ... (< (current-seconds) (conndat-expires conn))) #t) ;; we are current and good to go - we'll deal elsewhere with a server that was killed or died ((and conn (>= (current-seconds)(conndat-expires conn))) @@ -238,11 +231,10 @@ (let* ((srv-addr (server-address the-srv)) ;; need serv (ipaddr (alist-ref 'ipaddr the-srv)) (port (alist-ref 'port the-srv)) (srvkey (alist-ref 'servkey the-srv)) (fullpath (db:dbname->path apath dbname)) - (new-the-srv (make-conndat apath: apath dbname: dbname fullname: fullpath hostport: srv-addr @@ -349,22 +341,16 @@ ;; 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) - (assert (not (eq? 'primordial (thread-name (current-thread)))) "FATAL: Do not call rmt:send-receive-real in the primodial thread.") (let* ((cdat (rmt:get-conn sinfo apath dbname))) (assert cdat "FATAL: rmt:send-receive-real called without the needed channels opened") (let* ((uconn (servdat-uconn sinfo)) ;; get the interface to ulex ;; then send-receive using the ulex layer to host-port stored in cdat - (res (send-receive uconn (conndat-hostport cdat) cmd params)) - #;(th1 (make-thread (lambda () - (set! res (send-receive uconn (conndat-hostport cdat) cmd params))) - "send-receive thread"))) - ;; (thread-start! th1) - ;; (thread-join! th1) ;; gratuitious thread stuff is so that mailbox is not used in primordial thead - ;; since we accessed the server we can bump the expires time up + (res (send-receive uconn (conndat-hostport cdat) cmd params))) + ;; since we accessed the server we can bump the expires time up (conndat-expires-set! cdat (+ (current-seconds) (server:expiration-timeout) -2)) ;; two second margin for network time misalignments etc. res))) @@ -1638,10 +1624,11 @@ (define *rmt:run-mutex* (make-mutex)) (define *rmt:run-flag* #f) ;; Main entry point to start a server. was start-server (define (rmt:run hostn) + (assert (args:get-arg "-server") "FATAL: rmt:run called on non-server process") (mutex-lock! *rmt:run-mutex*) (if *rmt:run-flag* (begin (debug:print-warn 0 *default-log-port* "rmt:run already running.") (mutex-unlock! *rmt:run-mutex*)) Index: ulex-simple/ulex.scm ================================================================== --- ulex-simple/ulex.scm +++ ulex-simple/ulex.scm @@ -173,12 +173,17 @@ (print "cmd loop started") uconn) (assert #f "ERROR: run-listener called without proper setup.")))) (define (wait-and-close uconn) + (let loop () + (if (not (udat-cmd-thread uconn)) + (begin + (thread-sleep! 1) + (loop)))) (thread-join! (udat-cmd-thread uconn)) - (tcp-close (udat-socket uconn))) + #;(tcp-close (udat-socket uconn))) ;;====================================================================== ;; peers and connections ;;======================================================================