459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
|
;;
;; retval tells send to expect and wait for return data (one line) and return it or time out
;; this is for ping where we don't want to necessarily have set up our own server yet.
;;
(define (send udata host-port handler qrykey data #!key (hostname #f)(pid #f)(params '())(retval #f))
(let* ((my-host-port (udat-my-host-port udata))
(isme (equal? host-port my-host-port)) ;; am I calling myself?
(dat (conc
handler " "
my-host-port " "
(udat-my-pid udata) " "
qrykey
(if (null? params) "" (conc " " (string-intersperse params " "))))))
;; (print "send isme is " (if isme "true!" "false!") ", my-host-port: " my-host-port ", host-port: " host-port)
(if isme
(ulex-handler udata dat data)
(handle-exceptions ;; ERROR - MAKE THIS EXCEPTION HANDLER MORE SPECIFIC
exn
#f
(let-values (((inp oup)(tcp-connect host-port)))
|
|
|
|
|
|
>
|
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
;;
;; retval tells send to expect and wait for return data (one line) and return it or time out
;; this is for ping where we don't want to necessarily have set up our own server yet.
;;
(define (send udata host-port handler qrykey data #!key (hostname #f)(pid #f)(params '())(retval #f))
(let* ((my-host-port (udat-my-host-port udata))
(isme (equal? host-port my-host-port)) ;; am I calling myself?
(dat (list
handler ;; " "
my-host-port ;; " "
(udat-my-pid udata) ;; " "
qrykey
params #;(if (null? params) "" (conc " " (string-intersperse params " ")))
)))
;; (print "send isme is " (if isme "true!" "false!") ", my-host-port: " my-host-port ", host-port: " host-port)
(if isme
(ulex-handler udata dat data)
(handle-exceptions ;; ERROR - MAKE THIS EXCEPTION HANDLER MORE SPECIFIC
exn
#f
(let-values (((inp oup)(tcp-connect host-port)))
|
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
|
(if (eq? res 'MBOX_TIMEOUT)
#f
res))
#f))) ;; #f means failed to communicate
;;
(define (ulex-handler udata controldat data)
;; (print "controldat: " controldat " data: " data)
(match (string-split controldat)
((handlerkey host-port pid qrykey params ...)
;; (print "handlerkey: " handlerkey " host-port: " host-port " pid: " pid " qrykey: " qrykey " params: " params)
(case (string->symbol handlerkey)
((ack)(print "Got ack!"))
((ping) ;; special case - return result immediately on the same connection
(let* ((proc (hash-table-ref/default (udat-handlers udata) 'ping #f))
(val (if proc (proc) "gotping"))
(peer (make-peer addr-port: host-port pid: pid))
(dbshash (udat-dbowners udata)))
(peer-dbs-set! peer params) ;; params for ping is list of dbs owned by pinger
|
|
|
|
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
(if (eq? res 'MBOX_TIMEOUT)
#f
res))
#f))) ;; #f means failed to communicate
;;
(define (ulex-handler udata controldat data)
(print "controldat: " controldat " data: " data)
(match controldat ;; (string-split controldat)
((handlerkey host-port pid qrykey params ...)
;; (print "handlerkey: " handlerkey " host-port: " host-port " pid: " pid " qrykey: " qrykey " params: " params)
(case handlerkey ;; (string->symbol handlerkey)
((ack)(print "Got ack!"))
((ping) ;; special case - return result immediately on the same connection
(let* ((proc (hash-table-ref/default (udat-handlers udata) 'ping #f))
(val (if proc (proc) "gotping"))
(peer (make-peer addr-port: host-port pid: pid))
(dbshash (udat-dbowners udata)))
(peer-dbs-set! peer params) ;; params for ping is list of dbs owned by pinger
|