[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
07/08: marionette: Add #:peek? to ‘wait-for-tcp-port?’.
From: |
guix-commits |
Subject: |
07/08: marionette: Add #:peek? to ‘wait-for-tcp-port?’. |
Date: |
Sat, 10 Feb 2024 17:21:54 -0500 (EST) |
civodul pushed a commit to branch master
in repository guix.
commit 5f34796dc4a615c8fe496bbb9cc18a489bc5d107
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Jan 23 14:27:30 2024 +0100
marionette: Add #:peek? to ‘wait-for-tcp-port?’.
* gnu/build/marionette.scm (wait-for-tcp-port): Add #:peek? parameter
and honor it.
Change-Id: Ie7515a5223299390ab8af6fe5aa3cf63ba5c8078
---
gnu/build/marionette.scm | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/gnu/build/marionette.scm b/gnu/build/marionette.scm
index 27c10e3dfe..0b0a8a70d8 100644
--- a/gnu/build/marionette.scm
+++ b/gnu/build/marionette.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2016-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016-2022, 2024 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
;;; Copyright © 2022, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
@@ -223,29 +223,49 @@ FILE has not shown up after TIMEOUT seconds, raise an
error."
(define* (wait-for-tcp-port port marionette
#:key
(timeout 20)
+ (peek? #f)
(address `(make-socket-address AF_INET
INADDR_LOOPBACK
,port)))
"Wait for up to TIMEOUT seconds for PORT to accept connections in
MARIONETTE. ADDRESS must be an expression that returns a socket address,
-typically a call to 'make-socket-address'. Raise an error on failure."
+typically a call to 'make-socket-address'. When PEEK? is true, attempt to
+read a byte from the socket upon connection; retry if that gives the
+end-of-file object.
+
+Raise an error on failure."
;; Note: The 'connect' loop has to run within the guest because, when we
;; forward ports to the host, connecting to the host never raises
;; ECONNREFUSED.
(match (marionette-eval
- `(let* ((address ,address)
- (sock (socket (sockaddr:fam address) SOCK_STREAM 0)))
- (let loop ((i 0))
+ `(let* ((address ,address))
+ (define (open-socket)
+ (socket (sockaddr:fam address) SOCK_STREAM 0))
+
+ (let loop ((sock (open-socket))
+ (i 0))
(catch 'system-error
(lambda ()
(connect sock address)
+ (when ,peek?
+ (let ((byte ((@ (ice-9 binary-ports) lookahead-u8)
+ sock)))
+ (when (eof-object? byte)
+ (close-port sock)
+ (throw 'system-error
+ "wait-for-tcp-port" "~A"
+ (list (strerror ECONNRESET))
+ (list ECONNRESET)))))
(close-port sock)
'success)
(lambda args
(if (< i ,timeout)
(begin
(sleep 1)
- (loop (+ 1 i)))
+ (loop (if (port-closed? sock)
+ (open-socket)
+ sock)
+ (+ 1 i)))
(list 'failure address))))))
marionette)
('success #t)
- branch master updated (b64862e5cb -> 9edbb2d7a4), guix-commits, 2024/02/10
- 06/08: vm: Add ‘cpu-count’ field to <virtual-machine>., guix-commits, 2024/02/10
- 05/08: vm: Export <virtual-machine> accessors., guix-commits, 2024/02/10
- 03/08: services: secret-service: Make the endpoint configurable., guix-commits, 2024/02/10
- 02/08: gnu: openmolar-1: Update to release 1.1.6-g81838c8 and partial runtime fix., guix-commits, 2024/02/10
- 04/08: vm: Add ‘date’ field to <virtual-machine>., guix-commits, 2024/02/10
- 07/08: marionette: Add #:peek? to ‘wait-for-tcp-port?’.,
guix-commits <=
- 08/08: services: Add ‘virtual-build-machine’ service., guix-commits, 2024/02/10
- 01/08: gnu: Add python-scikit-opt., guix-commits, 2024/02/10