Index: common.scm ================================================================== --- common.scm +++ common.scm @@ -158,11 +158,11 @@ (hash-table-set! *common:denoise* key currtime) #t) #f))) (define (common:get-megatest-exe) - (if (getenv "MT_MEGATEST") (getenv "MT_MEGATEST") "megatest")) + (or (getenv "MT_MEGATEST") "megatest")) (define (common:read-encoded-string instr) (handle-exceptions exn (handle-exceptions @@ -768,15 +768,116 @@ (vector->list (hostinfo-addresses (hostname->hostinfo hostname)))) (string-intersperse (map number->string (u8vector->list (if res res (hostname->ip hostname)))) "."))) + +(define (common:open-nm-req addr) + (let* ((req (nn-socket 'req)) + (res (nn-connect req addr))) + req)) + +;; (with-output-to-string (lambda ()(serialize obj))) +(define (common:nm-send-receive soc msg) + (nn-send soc msg) + (nn-recv soc)) + +(define (common:close-nm-req soc) + (nn-close soc)) (define (common:send-dboard-main-changed) - (let ((dashboard-ips (mddb:get-dashboards))) - #f)) + (let* ((dashboard-ips (mddb:get-dashboards))) + (for-each + (lambda (ipadr) + (let* ((soc (common:open-nm-req (conc "tcp://" ipadr))) + (msg (conc "main " *toppath*)) + (res (common:nm-send-receive-timeout soc msg))) + (if (not res) ;; couldn't reach that dashboard - remove it from db + (print "ERROR: couldn't reach dashboard " ipadr)) + res)) + dashboard-ips))) + +(define (common:nm-send-receive-timeout req msg) + (let* ((key "ping") + (success #f) + (keepwaiting #t) + (result #f) + (sendrec (make-thread + (lambda () + (nn-send req msg) + (set! result (nn-recv req)) + (set! success #t)) + "send-receive")) + (timeout (make-thread (lambda () + (let loop ((count 0)) + (thread-sleep! 1) + (print "still waiting after count seconds...") + (if (and keepwaiting (< count 10)) + (loop (+ count 1)))) + (if keepwaiting + (begin + (print "timeout waiting for reply") + (thread-terminate! sendrec)))) + "timeout"))) + (handle-exceptions + exn + (begin + (print-call-chain) + (print 0 " message: " ((condition-property-accessor 'exn 'message) exn)) + (print "exn=" (condition->list exn))) + (thread-start! timeout) + (thread-start! sendrec) + (thread-join! sendrec) + (if success (thread-terminate! timeout))) + result)) +(define (common:ping-nm req) + ;; send a random number and check that we get it back + (let* ((key "ping") + (success #f) + (keepwaiting #t) + (ping (make-thread + (lambda () + (print "ping: sending string \"" key "\", expecting " (current-process-id)) + (nn-send req key) + (let ((result (nn-recv req))) + (if (equal? (conc (current-process-id)) result) + (begin + (print "ping, success: received \"" result "\"") + (set! success #t)) + (begin + (print "ping, failed: received key \"" result "\"") + (set! keepwaiting #f) + (set! success #f))))) + "ping")) + (timeout (make-thread (lambda () + (let loop ((count 0)) + (thread-sleep! 1) + (print "still waiting after count seconds...") + (if (and keepwaiting (< count 10)) + (loop (+ count 1)))) + (if keepwaiting + (begin + (print "timeout waiting for ping") + (thread-terminate! ping)))) + "timeout"))) + (handle-exceptions + exn + (begin + (print-call-chain) + (print 0 " message: " ((condition-property-accessor 'exn 'message) exn)) + (print "exn=" (condition->list exn)) + (print "ping failed to connect to tcp://" hostport)) + (thread-start! timeout) + (thread-start! ping) + (thread-join! ping) + (if success (thread-terminate! timeout))) + (if return-socket + (if success req #f) + (begin + (nn-close req) + success)))) ;;====================================================================== ;; D A S H B O A R D D B ;;====================================================================== Index: multi-dboard.scm ================================================================== --- multi-dboard.scm +++ multi-dboard.scm @@ -469,25 +469,38 @@ (let loop ((msg-in (nn-recv soc)) (count 0)) (if (eq? 0 (modulo count 1000)) (print "server received: " msg-in ", count=" count)) (cond + ;; + ;; quit + ;; ((equal? msg-in "quit") (nn-send soc "Ok, quitting")) + ;; + ;; ping + ;; ((and (>= (string-length msg-in) 4) (equal? (substring msg-in 0 4) "ping")) (nn-send soc (conc (current-process-id))) (loop (nn-recv soc)(+ count 1))) + ;; + ;; main changed + ;; + ((and (>= (string-length msg-in) 4) + (equal? (substring msg-in 0 4) "main")) + (let ((parts (string-split msg-in " "))) + (hash-table-set! *changed-main* (cadr parts) #t) + (nn-send soc "got it!"))) + ;; + ;; ?? + ;; (else - (mutex-lock! *current-delay-mutex*) - (let ((current-delay *current-delay*)) - (mutex-unlock! *current-delay-mutex*) - ;; (thread-sleep! current-delay) - (nn-send soc (conc current-delay " hello " msg-in " you waited " current-delay " seconds")) - (loop (nn-recv soc)(if (> count 20000000) - 0 - (+ count 1)))))))) + (nn-send soc "hello " msg-in " you got to the else clause!"))) + (loop (nn-recv soc)(if (> count 20000000) + 0 + (+ count 1))))) (define (dboard:one-time-ping-receive soc port) (let ((msg-in (nn-recv soc))) (if (and (>= (string-length msg-in) 4) (equal? (substring msg-in 0 4) "ping"))