Overview
Comment: | Ulex setup works |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.70-captain-ulex | v1.70-defunct-try |
Files: | files | file ages | folders |
SHA1: |
a24928bf83e8d55361d6b89861a8a870 |
User & Date: | matt on 2020-01-15 21:14:59 |
Other Links: | branch diff | manifest | tags |
Context
2020-01-18
| ||
21:55 | Added placeholder for whoowns check-in: 407a60fccd user: matt tags: v1.70-captain-ulex, v1.70-defunct-try | |
2020-01-15
| ||
21:14 | Ulex setup works check-in: a24928bf83 user: matt tags: v1.70-captain-ulex, v1.70-defunct-try | |
2020-01-14
| ||
22:43 | wip check-in: e858e4927e user: matt tags: v1.70-captain-ulex, v1.70-defunct-try | |
Changes
Modified ulex/ulex.scm from [aa4f6bc6b4] to [4622e1fcb8].
︙ | ︙ | |||
53 54 55 56 57 58 59 60 61 62 63 64 65 66 | ;; find or become the captain ;; setup and return a ulex object ;; (define (setup) (let* ((udata (make-udat)) (cpkts (get-all-captain-pkts udata)) ;; read captain pkts (captn (get-winning-pkt cpkts))) (if captn (let* ((port (alist-ref 'port captn)) (host (alist-ref 'host captn)) (ipaddr (alist-ref 'ipaddr captn)) (pid (alist-ref 'pid captn)) (Z (alist-ref 'Z captn))) (udat-captain-address-set! udata ipaddr) | > > | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | ;; find or become the captain ;; setup and return a ulex object ;; (define (setup) (let* ((udata (make-udat)) (cpkts (get-all-captain-pkts udata)) ;; read captain pkts (captn (get-winning-pkt cpkts))) ;; check to see if our own server is started and start one if not (if (not (udat-serv-listener udata))(start-server-find-port udata)) (if captn (let* ((port (alist-ref 'port captn)) (host (alist-ref 'host captn)) (ipaddr (alist-ref 'ipaddr captn)) (pid (alist-ref 'pid captn)) (Z (alist-ref 'Z captn))) (udat-captain-address-set! udata ipaddr) |
︙ | ︙ | |||
80 81 82 83 84 85 86 | ;; connect to a specific dbfile (define (connect udata dbfname dbtype) udata) (define (ping udata host-port) (let* ((cookie (make-cookie udata)) | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | ;; connect to a specific dbfile (define (connect udata dbfname dbtype) udata) (define (ping udata host-port) (let* ((cookie (make-cookie udata)) (res (send udata host-port 'ping cookie (conc (current-seconds)) retval: #t))) ;; (print "got res=" res) (equal? res cookie) )) ;;====================================================================== ;; network utilities ;;====================================================================== |
︙ | ︙ | |||
339 340 341 342 343 344 345 | (values (peer-inp pdat)(peer-oup pdat)) (values #f #f)))) ;; send structured data to recipient ;; ;; NOTE: qrykey is what was called the "cookie" previously ;; | > > > | > | > | | > > | | > > > | > > > | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | (values (peer-inp pdat)(peer-oup pdat)) (values #f #f)))) ;; send structured data to recipient ;; ;; NOTE: qrykey is what was called the "cookie" previously ;; ;; 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-values (((inp oup)(get-peer-ports udata host-port hostname pid))) ;; CONTROL LINE: (note: removed the hostname - I don't think it adds much value ;; ;; handlerkey host:port pid qrykey params ... ;; (if (and inp oup) (let* ((myhost (udat-my-address udata)) (myport (udat-my-port udata)) (dat (conc handler " " (udat-my-address udata) ":" (udat-my-port udata) " " ;; (udat-my-hostname udata) " " (udat-my-pid udata) " " qrykey (if (null? params) "" (conc " " (string-intersperse params " ")))))) (if (and myhost myport) (begin (write-line dat oup) (write-line data oup) ;; (print "Sent dat: " dat " data: " data) (if retval (read-line inp) #t)) (begin (print "ERROR: send called but no receiver has been setup. Please call setup first!") #f)) ;; NOTE: DO NOT BE TEMPTED TO LOOK AT ANY DATA ON INP HERE! ;; (there is a listener for handling that) ) #f))) ;; #f means failed to connect and send ;; send a request to the given host-port and register a mailbox in udata ;; wait for the mailbox data and return it |
︙ | ︙ | |||
422 423 424 425 426 427 428 | (let loop ((state 'start)) (let-values (((inp oup)(tcp-accept serv-listener))) (print "got here: inp=" inp " oup=" oup) (let* ((controldat (read-line inp)) (data (read-line inp))) (print "controldat: " controldat " data: " data) (match (string-split controldat) | | | | < < > | > > > > | | | | 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | (let loop ((state 'start)) (let-values (((inp oup)(tcp-accept serv-listener))) (print "got here: inp=" inp " oup=" oup) (let* ((controldat (read-line inp)) (data (read-line inp))) (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"))) (write-line qrykey oup) #;(send udata host-port "version" qrykey val) ) (close-input-port inp) (close-output-port oup) ) ((rucaptain) (send udata host-port "iamcaptain" qrykey (if (udat-my-cpkt-key udata) "yes" "no"))) (else ;; (send-ack udata host-port qrykey) (add-to-work-queue udata (get-peer-dat udata host-port) handlerkey qrykey data)))) (else (print "BAD DATA? controldat=" controldat " data=" data))))) (loop state)))) ;; add a proc to the handler list (define (register-handler udata key proc) (hash-table-set! (udat-handlers udata) key proc)) |
︙ | ︙ |