Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -57,28 +57,29 @@ chicken.time chicken.time.posix (prefix sqlite3 sqlite3:) directory-utils - http-client - intarweb + ;; http-client + ;; intarweb matchable md5 message-digest (prefix base64 base64:) (prefix sqlite3 sqlite3:) regex s11n - spiffy - spiffy-directory-listing - spiffy-request-vars + ;; spiffy + ;; spiffy-directory-listing + ;; spiffy-request-vars srfi-1 srfi-13 srfi-18 srfi-69 stack system-information + tcp6 typed-records uri-common z3 apimod @@ -110,12 +111,12 @@ ;; (use srfi-1 posix regex regex-case srfi-69 hostinfo md5 message-digest posix-extras) ;; ;; (use spiffy uri-common intarweb http-client spiffy-request-vars intarweb spiffy-directory-listing) ;; ;; Configurations for server -(tcp-buffer-size 2048) -(max-connections 2048) +;; (tcp-buffer-size 2048) +;; (max-connections 2048) ;; info about me as a server ;; (defstruct servdat (host #f) @@ -255,10 +256,11 @@ (begin (debug:print-info 0 *default-log-port* "Unexpected result: " res) res))))))))) ;;====================================================================== + ;; Defaults to current area ;; (define (rmt:send-receive cmd rid params #!key (attemptnum 1)(area-dat #f)) (if (not *rmt:remote*)(set! *rmt:remote* (make-rmt:remote))) @@ -266,14 +268,19 @@ (conns *rmt:remote*) (dbname (db:run-id->dbname rid))) (rmt:general-open-connection conns apath dbname) (rmt:send-receive-real conns apath dbname cmd params))) +(define (rmt:send-receive-real host port data) + (let-values ((i o) (tcp-connect "localhost" 4242)) + (write-line "Good Bye!" o) + (print (read-line i)))) + ;; db is at apath/.db/dbname, rid is an intermediary solution and will be removed ;; sometime in the future ;; -(define (rmt:send-receive-real remote apath dbname cmd params) +#;(define (rmt:send-receive-real remote apath dbname cmd params) (let* ((conn (rmt:get-conn remote apath dbname))) (assert conn "FATAL: rmt:send-receive-real called without the needed channels opened") (let* ((payload (sexpr->string params)) (res (with-input-from-request (rmt:conn->uri conn "api") @@ -292,11 +299,11 @@ ;; for the given area path and dbname ;; (define (rmt:send-receive-server-start remote apath dbname) (let* ((conn (rmt:get-conn remote apath dbname))) (assert conn "FATAL: Unable to connect to db "apath"/"dbname) - (let* ((res (with-input-from-request + #;(let* ((res (with-input-from-request (rmt:conn->uri conn "api") `((params . (,apath ,dbname))) read-string))) (string->sexpr res)))) @@ -1459,11 +1466,11 @@ (if (sqlite3:database? db) (begin (sqlite3:interrupt! db) (sqlite3:finalize! db #t) (bdat-task-db-set! *bdat* #f))))) - (http-client#close-idle-connections!) + #;(http-client#close-idle-connections!) (if (not (eq? *default-log-port* (current-error-port))) (close-output-port *default-log-port*)) (set! *default-log-port* (current-error-port))) "Cleanup db exit thread")) (th2 (make-thread (lambda () (debug:print 4 *default-log-port* "Attempting clean exit. Please be patient and wait a few seconds...") @@ -1519,11 +1526,19 @@ (define (http-handle-api dbstruct $) (if (api-proc) ((api-proc) dbstruct $) ;; ($) => alist 'no-api-proc-set)) -(define (http-transport:run hostn) +(define (rmt:launch-server hostn) + (let* ((l (tcp-listen 4242))) + (define-values (i o) (tcp-accept l)) + (write-line "Hello!" o) + (print (read-line i)) + (close-input-port i) + (close-output-port o))) + +#;(define (http-transport:run hostn) ;; Configurations for server (tcp-buffer-size 2048) (max-connections 2048) (debug:print 2 *default-log-port* "Attempting to start the server ...") (let* ((db #f) ;; (open-db)) ;; we don't want the server to be opening and closing the db unnecesarily @@ -1605,11 +1620,11 @@ (else (continue)))))))) (http-transport:try-start-server ipaddrstr start-port))) ;; This is recursively run by http-transport:run until sucessful, it then runs until server is stopped ;; -(define (http-transport:try-start-server ipaddrstr portnum) +#;(define (http-transport:try-start-server ipaddrstr portnum) (let ((config-hostname (configf:lookup *configdat* "server" "hostname")) (config-use-proxy (equal? (configf:lookup *configdat* "client" "use-http_proxy") "yes"))) (if (not config-use-proxy) (determine-proxy (constantly #f))) ;; any error in following steps will result in a retry @@ -1699,11 +1714,11 @@ (if (> etime (current-seconds)) (begin (thread-sleep! 0.052) (loop etime)) (debug:print-error 0 *default-log-port* "requests still in progress after 5 seconds of waiting. I'm going to pass on cleaning up http connections")) - (close-idle-connections!))) + #;(close-idle-connections!))) (set! *http-connections-next-cleanup* (+ (current-seconds) 10)) (mutex-unlock! *http-mutex*)) (define (http-transport:inc-requests-and-prep-to-close-all-connections) (mutex-lock! *http-mutex*) @@ -1846,31 +1861,37 @@ (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 + + #;(let* ((res (with-input-from-request (conc "http://"host":"port"/ping") ;; returns *toppath*/dbname #f read-string))) (if (equal? res key) #t (begin (debug:print-info 0 *default-log-port* "server-ready? key="key", received="res) - #f)))) + #f))) + + #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 '()))) - (let* ((payload (sexpr->string data)) + #;(let* ((payload (sexpr->string data)) (res (with-input-from-request (conc "http://"host":"port"/loop-test") `((data . ,payload)) read-string))) - (string->sexpr res))) + (string->sexpr res)) + #f + ) ; 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 ;; @@ -2197,11 +2218,11 @@ ;; (server-started (conc tmp-area "/.server-started")) ;; (start-time (common:lazy-modification-time server-start)) ;; (started-time (common:lazy-modification-time server-started)) ;; (server-starting (< start-time started-time)) ;; if start-time is less than started-time then a server is still starting ;; (start-time-old (> (- (current-seconds) start-time) 5)) - (let* ((th2 (make-thread (lambda () + #;(let* ((th2 (make-thread (lambda () (debug:print-info 0 *default-log-port* "Server run thread started") (http-transport:run (if (args:get-arg "-server") (args:get-arg "-server") "-") @@ -2213,11 +2234,14 @@ (thread-start! th2) (thread-sleep! 0.252) ;; give the server time to settle before starting the keep-running monitor. (thread-start! th3) (set! *didsomething* #t) (thread-join! th2) - (exit))) + (exit)) + + #f + ) ;; Generate a unique signature for this server (define (server:mk-signature) (message-digest-string (md5-primitive) (with-output-to-string