gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] 02/02: dht/client: Move field construction of <server> t


From: gnunet
Subject: [gnunet-scheme] 02/02: dht/client: Move field construction of <server> to the constructor.
Date: Sat, 19 Feb 2022 15:40:41 +0100

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit bd67a169c1cdfc2b086d423768d39d8c812b8ca7
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sat Feb 19 14:39:02 2022 +0000

    dht/client: Move field construction of <server> to the constructor.
    
    This seems a little tidier.
    
    * gnu/gnunet/dht/client.scm (%make-server): Rename to ...
      (make-server): ... this.
      (<server>)[protocol]: Accept no arguments, construct values for each
      field.
      (reconnect): Adjust to new constructor.
      (spawn-procedure): New procedure.
---
 gnu/gnunet/dht/client.scm | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/gnu/gnunet/dht/client.scm b/gnu/gnunet/dht/client.scm
index 60668e4..cb8636f 100644
--- a/gnu/gnunet/dht/client.scm
+++ b/gnu/gnunet/dht/client.scm
@@ -580,7 +580,7 @@ currently unsupported."
     ;; via the control channel, using 'maybe-send-control-message!'.
     ;; Operations must be put in id->operation-map before sending them
     ;; to the service!
-    (define-record-type (<server> %make-server server?)
+    (define-record-type (<server> make-server server?)
       (parent <losable>)
       ;; terminal-condition: a disconnect has been requested
       (fields (immutable terminal-condition server-terminal-condition)
@@ -589,10 +589,12 @@ currently unsupported."
              ;; Atomic box holding an unsigned 64-bit integer.
              (immutable next-unique-id/box server-next-unique-id/box))
       (protocol (lambda (%make)
-                 (lambda (terminal-condition control-channel lost-and-found
-                                             next-unique-id/box)
-                   ((%make lost-and-found) terminal-condition control-channel
-                    lost-and-found next-unique-id/box)))))
+                 (lambda ()
+                   (define lost-and-found (make-lost-and-found))
+                   ((%make lost-and-found) (make-condition) (make-channel)
+                    lost-and-found
+                    ;; Any ‘small’ natural number will do.
+                    (make-atomic-box 0))))))
 
     (define (maybe-send-control-message!* terminal-condition control-channel
                                          . message)
@@ -765,20 +767,17 @@ when the connection has been made.  The connection can 
break; the optional thunk
 @var{disconnected} is called when it does. If the connection breaks, the client
 code automatically tries to reconnect, so @var{connected} can be called after
 @var{disconnected}.  This procedure returns a DHT server object."
-      (define terminal-condition (make-condition))
       (define old-id->operation-map (make-hash-table))
-      (define control-channel (make-channel))
-      (define lost-and-found (make-lost-and-found))
-      (spawn
-       (lambda ()
-        (reconnect terminal-condition config
-                   old-id->operation-map control-channel lost-and-found
-                   #:connected connected
-                   #:disconnected disconnected
-                   #:spawn spawn)))
-      (%make-server terminal-condition control-channel lost-and-found
-                   ;; Any ‘small’ exact natural number will do.
-                   (make-atomic-box 0)))
+      (define server (make-server))
+      ;; We could do @code{(spawn (lambda () (reconnect ...)))} here instead,
+      ;; but that causes ‘(DHT) garbage collectable’ to fail.
+      (spawn-procedure spawn (server-terminal-condition server) config
+                      old-id->operation-map (server-control-channel server)
+                      (server-lost-and-found server) #:connected connected
+                      #:disconnected disconnected #:spawn spawn)
+      server)
+    (define (spawn-procedure spawn . rest)
+      (spawn (lambda () (apply reconnect rest))))
 
     ;; TODO: put in new module?
     (define (make-weak-reference to)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]