From 882336f2f5d74856222f5be79ea4709481a2c602 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Sat, 1 May 2021 21:41:21 +0200 Subject: [PATCH] No longer using URIs for internal address representation. --- chat_client.scm | 4 ++-- sam.scm | 41 ++++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/chat_client.scm b/chat_client.scm index 4bf02d8..f6b16d6 100644 --- a/chat_client.scm +++ b/chat_client.scm @@ -10,7 +10,7 @@ (match message (('start) (send-message system 'print "Welcome to chat!\n" - "Your client address is " self ".\n" + "Your client address is " (address->string self) ".\n" "Type '/help' for a list of commands.\n") (send-message system 'read self)) (('show-msg from text) @@ -36,7 +36,7 @@ (if (string-null? arg) (send-message system 'print "Missing address of client.") (begin - (set! recipients (cons arg recipients)) + (set! recipients (cons (string->address arg) recipients)) (send-message system 'print "Added recipient to chat.")))) ((or "c" "clear") (set! recipients '()) diff --git a/sam.scm b/sam.scm index 110a55c..17c6f41 100644 --- a/sam.scm +++ b/sam.scm @@ -1,13 +1,16 @@ ;; Simple Actor Machine ;; -;; Houses a population of actors which can communicate using messages -;; with actors on the same machine or other machines via the network. +;; A virtual machine which houses a population of actors which can +;; communicate using messages with actors on the same machine or other +;; machines via the network. (module sam (boot-sam make-actor send-message - send-message-later) + send-message-later + address->string + string->address) (import scheme (chicken base) @@ -19,7 +22,6 @@ srfi-18 ; threads srfi-69 ; hash-table uuid ; ids for actors - uri-generic udp fifo) @@ -31,11 +33,7 @@ (define sam-port 8000) (define (make-address host port id) - (uri->string - (make-uri #:scheme "actor" - #:host host - #:port port - #:path (list '/ id)))) + (list id host port)) (define (make-local-address . args) (make-address sam-host @@ -45,14 +43,20 @@ (car args)))) (define (address-id address) - (cadr (uri-path (uri-reference address)))) - - (define address->uri uri-reference) + (car address)) + (define (address-host address) + (cadr address)) + (define (address-port address) + (caddr address)) + (define (address->string address) + (with-output-to-string + (lambda () (write address)))) + (define (string->address str) + (with-input-from-string str read)) (define (address-local? address) - (let ((uri (address->uri address))) - (and (equal? (uri-host uri) sam-host) - (equal? (uri-port uri) sam-port)))) + (and (equal? (address-host address) sam-host) + (equal? (address-port address) sam-port))) (define actor-table (make-hash-table)) @@ -94,14 +98,13 @@ (define (send-network-message address . message) (let ((s (udp-open-socket)) - (uri (address->uri address)) (packet (with-output-to-string (lambda () (write (cons address message)))))) (udp-bind! s #f 0) (udp-connect! s - (uri-host uri) - (uri-port uri)) + (address-host address) + (address-port address)) (udp-send s packet) (udp-close-socket s))) @@ -135,7 +138,7 @@ (let ((s (udp-open-socket*))) (udp-bind! s #f sam-port) (let loop () - (let-values (((n str) (udp-recv s 1024))) + (let-values (((n str) (udp-recv s 65536))) (match (with-input-from-string str read) ((address message ...) (apply send-message (cons address message))) -- 2.20.1