all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Christopher Baines <mail@cbaines.net>
To: 70947@debbugs.gnu.org
Cc: "Christopher Baines" <guix@cbaines.net>,
	"Josselin Poiret" <dev@jpoiret.xyz>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Mathieu Othacehe" <othacehe@gnu.org>,
	"Ricardo Wurmus" <rekado@elephly.net>,
	"Simon Tournier" <zimon.toutoune@gmail.com>,
	"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#70947] [PATCH] store: Refactor connect-to-daemon.
Date: Tue, 14 May 2024 17:56:05 +0100	[thread overview]
Message-ID: <d42aea321f7c67d97611c80874c51055ee409021.1715705765.git.mail@cbaines.net> (raw)

Remove the inner connect procedure, as now that #:non-blocking? needs passing
on, this just makes things more difficult.  This commit also fixes not passing
 #:non-blocking? on in the case where open-unix-domain-socket is called as
connect.

* guix/store.scm (connect-to-daemon): Refactor and fix non-blocking
connections to sockets with a filename.

Change-Id: I61cd99920df91baba95567d670bec6fa94043875
---
 guix/store.scm | 69 +++++++++++++++++++++++---------------------------
 1 file changed, 32 insertions(+), 37 deletions(-)

diff --git a/guix/store.scm b/guix/store.scm
index 58ddaa8d15..4070b686cb 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -524,50 +524,45 @@ (define* (open-inet-socket host port #:key non-blocking?)
                                     (errno (system-error-errno args)))))
                  (loop rest)))))))))
 
-(define* (connect-to-daemon uri #:key non-blocking?)
-  "Connect to the daemon at URI, a string that may be an actual URI or a file
-name, and return an input/output port.  If NON-BLOCKING?, use a non-blocking
-socket when using the file, unix or guix URI schemes.
+(define* (connect-to-daemon uri-or-filename #:key non-blocking?)
+  "Connect to the daemon at URI-OR-FILENAME and return an input/output port.
+If NON-BLOCKING?, use a non-blocking socket when using the file, unix or guix
+URI schemes.
 
 This is a low-level procedure that does not perform the initial handshake with
 the daemon.  Use 'open-connection' for that."
   (define (not-supported)
     (raise (condition (&store-connection-error
-                       (file uri)
+                       (file uri-or-filename)
                        (errno ENOTSUP)))))
 
-  (define connect
-    (match (string->uri uri)
-      (#f                                         ;URI is a file name
-       open-unix-domain-socket)
-      ((? uri? uri)
-       (match (uri-scheme uri)
-         ((or #f 'file 'unix)
-          (lambda (_)
-            (open-unix-domain-socket (uri-path uri)
-                                     #:non-blocking? non-blocking?)))
-         ('guix
-          (lambda (_)
-            (open-inet-socket (uri-host uri)
-                              (or (uri-port uri) %default-guix-port)
-                              #:non-blocking? non-blocking?)))
-         ((? symbol? scheme)
-          ;; Try to dynamically load a module for SCHEME.
-          ;; XXX: Errors are swallowed.
-          (match (false-if-exception
-                  (resolve-interface `(guix store ,scheme)))
-            ((? module? module)
-             (match (false-if-exception
-                     (module-ref module 'connect-to-daemon))
-               ((? procedure? connect)
-                (lambda (_)
-                  (connect uri)))
-               (x (not-supported))))
-            (#f (not-supported))))
-         (x
-          (not-supported))))))
-
-  (connect uri))
+  (match (string->uri uri-or-filename)
+    (#f                                 ;URI is a file name
+     (open-unix-domain-socket uri-or-filename
+                              #:non-blocking? non-blocking?))
+    ((? uri? uri)
+     (match (uri-scheme uri)
+       ((or #f 'file 'unix)
+        (open-unix-domain-socket (uri-path uri)
+                                 #:non-blocking? non-blocking?))
+       ('guix
+        (open-inet-socket (uri-host uri)
+                          (or (uri-port uri) %default-guix-port)
+                          #:non-blocking? non-blocking?))
+       ((? symbol? scheme)
+        ;; Try to dynamically load a module for SCHEME.
+        ;; XXX: Errors are swallowed.
+        (match (false-if-exception
+                (resolve-interface `(guix store ,scheme)))
+          ((? module? module)
+           (match (false-if-exception
+                   (module-ref module 'connect-to-daemon))
+             ((? procedure? connect)
+              (connect uri))
+             (x (not-supported))))
+          (#f (not-supported))))
+       (x
+        (not-supported))))))
 
 (define* (open-connection #:optional (uri (%daemon-socket-uri))
                           #:key port (reserve-space? #t) cpu-affinity

base-commit: 6e86089d563ccb67ae04cd941ca7b66c1777831f
-- 
2.41.0





                 reply	other threads:[~2024-05-14 16:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d42aea321f7c67d97611c80874c51055ee409021.1715705765.git.mail@cbaines.net \
    --to=mail@cbaines.net \
    --cc=70947@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=guix@cbaines.net \
    --cc=ludo@gnu.org \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=rekado@elephly.net \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.