Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -44,11 +44,11 @@ megatest.scm : transport-mode.scm dashboard.scm : dashboard-transport-mode.scm # dbmod.import.o is just a hack here -mofiles/dbfile.o : mofiles/debugprint.o mofiles/commonmod.o dbmod.import.o +mofiles/dbfile.o : mofiles/debugprint.o mofiles/commonmod.o configf.o : commonmod.import.o db.o : dbmod.import.o mofiles/debugprint.o : mofiles/mtargs.o # ftail.scm rmtmod.scm commonmod.scm removed Index: tcp-transportmod.scm ================================================================== --- tcp-transportmod.scm +++ tcp-transportmod.scm @@ -22,47 +22,63 @@ (declare (uses debugprint)) (declare (uses commonmod)) (declare (uses dbfile)) (declare (uses dbmod)) -(use address-info) - (module tcp-transportmod * - (import scheme - (prefix sqlite3 sqlite3:) - chicken +(import scheme) +(cond-expand + (chicken-4 + (import chicken data-structures - - address-info - directory-utils + hostinfo extras files - hostinfo - matchable - md5 - message-digest + directory-utils ports posix - regex - regex-case - s11n - srfi-1 - srfi-18 - srfi-4 - srfi-69 - stack - typed-records - tcp-server - tcp - - debugprint - commonmod - dbfile - dbmod - ) + )) + (chicken-5 + (import chicken.base + chicken.condition + chicken.file + chicken.file.posix + chicken.io + chicken.port + chicken.process + chicken.process-context + chicken.process-context.posix + chicken.sort + chicken.string + chicken.time + system-information + socket + ) + (define unsetenv unset-environment-variable!))) + +(import (prefix sqlite3 sqlite3:)) +(import address-info) +(import matchable) +(import md5) +(import message-digest) +(import regex) +(import regex-case) +(import s11n) +(import srfi-1) +(import srfi-18) +(import srfi-4) +(import srfi-69) +(import stack) +(import typed-records) +(import tcp-server) +(import tcp6) +(import debugprint) +(import commonmod) +(import dbfile) +(import dbmod) ;;====================================================================== ;; client ;;====================================================================== @@ -69,17 +85,17 @@ ;; (define keep-age-param (make-parameter 10)) ;; qif file age, if over move to attic ;; Used ONLY for client ;; (defstruct tt-conn - host - port - host-port - dbfname - server-id - server-start - pid + (host #f) + (port #f) + (host-port #f) + (dbfname #f) + (server-id #f) + (server-start #f) + (pid #f) ) ;; Used for BOTH clients and servers (defstruct tt ;; client related @@ -686,24 +702,39 @@ (lambda () (write (list areapath (current-process-id) (argv))))))) - (define (tt:get-best-guess-address hostname) - (let ((res #f)) - (for-each - (lambda (adr) - (if (not (eq? (u8vector-ref adr 0) 127)) - (set! res adr))) - ;; NOTE: This can fail when there is no mention of the host in /etc/hosts. FIXME - (vector->list (hostinfo-addresses (hostname->hostinfo hostname)))) - (string-intersperse - (map number->string - (u8vector->list - (if res res (hostname->ip hostname)))) "."))) - + (cond-expand + (chicken-4 + (let ((res #f)) + (for-each + (lambda (adr) + (if (not (eq? (u8vector-ref adr 0) 127)) + (set! res adr))) + ;; NOTE: This can fail when there is no mention of the host in /etc/hosts. FIXME + (vector->list (hostinfo-addresses (hostname->hostinfo hostname)))) + (string-intersperse + (map number->string + (u8vector->list + (if res res (hostname->ip hostname)))) "."))) + (chicken-5 + (let* ((get-first (lambda (str) ;; "1.2.3.4" => 1, but "127.1.2.3 => 0 so it sorts last + (let* ((res (string->number (car (string-split str "."))))) + (if (eq? res 127) + 0 + res)))) + (addresses (sort + (map address-info-host (address-infos hostname)) + (lambda (a b) + (let* ((a-first (get-first a)) + (b-first (get-first b))) + (> a-first b-first)))))) + (car addresses))))) + + (define (tt:get-servinfo-dir areapath) (let* ((spath (conc areapath"/.servinfo"))) (if (not (file-exists? spath)) (create-directory spath #t)) spath))