The Lambda Lab
/
projects
/
sam.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9253a20
)
Minor fix to send-network-message.
author
Tim Vaughan
<plugd@thelambdalab.xyz>
Wed, 28 Apr 2021 12:44:30 +0000
(14:44 +0200)
committer
Tim Vaughan
<plugd@thelambdalab.xyz>
Wed, 28 Apr 2021 12:44:30 +0000
(14:44 +0200)
sam.scm
patch
|
blob
|
history
diff --git
a/sam.scm
b/sam.scm
index
8e8a730
..
511b953
100644
(file)
--- a/
sam.scm
+++ b/
sam.scm
@@
-25,6
+25,9
@@
#:port port
#:path (list '/ id)))
#:port port
#:path (list '/ id)))
+(define address->string uri->string)
+(define string->address uri-reference)
+
(define (make-local-address . args)
(make-address this-host
this-port
(define (make-local-address . args)
(make-address this-host
this-port
@@
-77,12
+80,15
@@
(define (send-network-message address . message)
(let ((s (udp-open-socket))
(define (send-network-message address . message)
(let ((s (udp-open-socket))
- (machine (address-machine address)))
+ (machine (address-machine address))
+ (packet (with-output-to-string)
+ (lambda ()
+ (print (cons (address->string address) message)))))
(udp-bind! s #f 0)
(udp-connect! s
(machine-host machine)
(machine-port machine))
(udp-bind! s #f 0)
(udp-connect! s
(machine-host machine)
(machine-port machine))
- (udp-send s
message
)
+ (udp-send s
packet
)
(udp-close-socket s)))
(define (next-local-message)
(udp-close-socket s)))
(define (next-local-message)
@@
-147,8
+153,8
@@
(let-values (((n str) (udp-recv s 1024)))
(print "Received " n " bytes over network: " str)
(match (with-input-from-string str read)
(let-values (((n str) (udp-recv s 1024)))
(print "Received " n " bytes over network: " str)
(match (with-input-from-string str read)
- ((
uri
-str message ...)
- (apply send-message (cons (
uri-reference uri
-str) message)))
+ ((
addr
-str message ...)
+ (apply send-message (cons (
string->address addr
-str) message)))
(else
(print "Warning: received badly formatted message string '" str "'"))))
(loop))))))
(else
(print "Warning: received badly formatted message string '" str "'"))))
(loop))))))
@@
-188,4
+194,21
@@
(start-network-listener)
(start-console)
(start-network-listener)
(start-console)
+(define (boot-sam host port)
+ (start-scheduler))
+
;; (thread-join! scheduler-thread)
;; (thread-join! scheduler-thread)
+
+(define (main)
+ (let loop ((args (cdr (argv)))
+ (host "localhost")
+ (port 8000))
+ (match args
+ ((or "-h" "--help")
+ (print-usage))
+ (((or "-p" "--port") pstr rest ...)
+ (loop rest host (string->number pstr)))
+ (("--hostname" hstr rest ...)
+ (loop rest hstr port))
+ (()
+ (boot-sam host port)))))