[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
04/07: store: 'open-connection' can taken an open port.
From: |
Ludovic Courtès |
Subject: |
04/07: store: 'open-connection' can taken an open port. |
Date: |
Fri, 25 Nov 2016 22:45:43 +0000 (UTC) |
civodul pushed a commit to branch master
in repository guix.
commit 6230d6f04f4bde9ad834f97c5c950db89dde0496
Author: Ludovic Courtès <address@hidden>
Date: Wed Nov 2 22:50:31 2016 +0100
store: 'open-connection' can taken an open port.
* guix/store.scm (open-unix-domain-socket): New procedure.
(open-connection): Add #:port parameter and honor it.
---
guix/store.scm | 58 ++++++++++++++++++++++++++++++++------------------------
1 file changed, 33 insertions(+), 25 deletions(-)
diff --git a/guix/store.scm b/guix/store.scm
index 7f54b87..689a94c 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -345,50 +345,58 @@
(message nix-protocol-error-message)
(status nix-protocol-error-status))
-(define* (open-connection #:optional (file (%daemon-socket-file))
- #:key (reserve-space? #t) cpu-affinity)
- "Connect to the daemon over the Unix-domain socket at FILE. When
-RESERVE-SPACE? is true, instruct it to reserve a little bit of extra space on
-the file system so that the garbage collector can still operate, should the
-disk become full. When CPU-AFFINITY is true, it must be an integer
-corresponding to an OS-level CPU number to which the daemon's worker process
-for this connection will be pinned. Return a server object."
+(define (open-unix-domain-socket file)
+ "Connect to the Unix-domain socket at FILE and return it. Raise a
+'&nix-connection-error' upon error."
(let ((s (with-fluids ((%default-port-encoding #f))
;; This trick allows use of the `scm_c_read' optimization.
(socket PF_UNIX SOCK_STREAM 0)))
(a (make-socket-address PF_UNIX file)))
(catch 'system-error
- (cut connect s a)
+ (lambda ()
+ (connect s a)
+ s)
(lambda args
;; Translate the error to something user-friendly.
(let ((errno (system-error-errno args)))
(raise (condition (&nix-connection-error
(file file)
- (errno errno)))))))
+ (errno errno)))))))))
- (write-int %worker-magic-1 s)
- (let ((r (read-int s)))
+(define* (open-connection #:optional (file (%daemon-socket-file))
+ #:key port (reserve-space? #t) cpu-affinity)
+ "Connect to the daemon over the Unix-domain socket at FILE, or, if PORT is
+not #f, use it as the I/O port over which to communicate to a build daemon.
+
+When RESERVE-SPACE? is true, instruct it to reserve a little bit of extra
+space on the file system so that the garbage collector can still operate,
+should the disk become full. When CPU-AFFINITY is true, it must be an integer
+corresponding to an OS-level CPU number to which the daemon's worker process
+for this connection will be pinned. Return a server object."
+ (let ((port (or port (open-unix-domain-socket file))))
+ (write-int %worker-magic-1 port)
+ (let ((r (read-int port)))
(and (eqv? r %worker-magic-2)
- (let ((v (read-int s)))
+ (let ((v (read-int port)))
(and (eqv? (protocol-major %protocol-version)
(protocol-major v))
(begin
- (write-int %protocol-version s)
+ (write-int %protocol-version port)
(when (>= (protocol-minor v) 14)
- (write-int (if cpu-affinity 1 0) s)
+ (write-int (if cpu-affinity 1 0) port)
(when cpu-affinity
- (write-int cpu-affinity s)))
+ (write-int cpu-affinity port)))
(when (>= (protocol-minor v) 11)
- (write-int (if reserve-space? 1 0) s))
- (let ((s (%make-nix-server s
- (protocol-major v)
- (protocol-minor v)
- (make-hash-table 100)
- (make-hash-table 100))))
- (let loop ((done? (process-stderr s)))
- (or done? (process-stderr s)))
- s))))))))
+ (write-int (if reserve-space? 1 0) port))
+ (let ((conn (%make-nix-server port
+ (protocol-major v)
+ (protocol-minor v)
+ (make-hash-table 100)
+ (make-hash-table 100))))
+ (let loop ((done? (process-stderr conn)))
+ (or done? (process-stderr conn)))
+ conn))))))))
(define (close-connection server)
"Close the connection to SERVER."
- branch master updated (7276b56 -> bc1ad4e), Ludovic Courtès, 2016/11/25
- 04/07: store: 'open-connection' can taken an open port.,
Ludovic Courtès <=
- 05/07: offload: Remove 'with-nar-error-handling' macro., Ludovic Courtès, 2016/11/25
- 07/07: offload: Drop 'remote-pipe'., Ludovic Courtès, 2016/11/25
- 01/07: gnu: guile-ssh: Update to 0.10.2., Ludovic Courtès, 2016/11/25
- 03/07: offload: Reuse SSH session during 'transfer-and-offload'., Ludovic Courtès, 2016/11/25
- 02/07: offload: Use Guile-SSH instead of GNU lsh., Ludovic Courtès, 2016/11/25
- 06/07: offload: Rewrite to make direct RPCs to the remote daemon., Ludovic Courtès, 2016/11/25