store: Add 'port->connection'.

* guix/store.scm (port->connection): New procedure.
This commit is contained in:
Ludovic Courtès 2018-06-25 18:40:10 +02:00
parent 7c7323e432
commit 2f608c1489
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 18 additions and 0 deletions

View File

@ -65,6 +65,7 @@
build-mode build-mode
open-connection open-connection
port->connection
close-connection close-connection
with-store with-store
set-build-options set-build-options
@ -517,6 +518,23 @@ for this connection will be pinned. Return a server object."
(or done? (process-stderr conn))) (or done? (process-stderr conn)))
conn))))))))) conn)))))))))
(define* (port->connection port
#:key (version %protocol-version))
"Assimilate PORT, an input/output port, and return a connection to the
daemon, assuming the given protocol VERSION.
Warning: this procedure assumes that the initial handshake with the daemon has
already taken place on PORT and that we're just continuing on this established
connection. Use with care."
(let-values (((output flush)
(buffering-output-port port (make-bytevector 8192))))
(%make-nix-server port
(protocol-major version)
(protocol-minor version)
output flush
(make-hash-table 100)
(make-hash-table 100))))
(define (write-buffered-output server) (define (write-buffered-output server)
"Flush SERVER's output port." "Flush SERVER's output port."
(force-output (nix-server-output-port server)) (force-output (nix-server-output-port server))