From af81ddcad705f722333a5550f523ac4a191e5a8a Mon Sep 17 00:00:00 2001 From: Shiro Kawai Date: Fri, 17 Nov 2023 17:34:57 -1000 Subject: [PATCH] Test system selecting tls server socket port Call tls-bind with port 0, and get the bound port using sockaddr-port. Related: https://github.com/shirok/Gauche/issues/961 --- ext/tls/test.scm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ext/tls/test.scm b/ext/tls/test.scm index 7b1ca1345..0aa68fb72 100644 --- a/ext/tls/test.scm +++ b/ext/tls/test.scm @@ -1,6 +1,7 @@ (use gauche.test) (use gauche.threads) (use gauche.net) +(use gauche.connection) (use file.util) @@ -28,11 +29,15 @@ (build-path (sys-dirname (current-load-path)) "data" filename)) (let ((serv (make :server-name "localhost")) + (serv-port #f) (serv-thread #f)) (unwind-protect (begin - (test* "simple communication" #t - (is-a? (tls-bind serv #f 8087 'tcp) )) + (test* "bind" #t + (begin + (tls-bind serv #f 0 'tcp) + (set! serv-port (sockaddr-port (connection-self-address serv))) + (and (integer? serv-port) (positive? serv-port)))) (test* "loading private key" #t (boolean (tls-load-private-key serv (datafile "test-key.pem") @@ -47,11 +52,12 @@ (let1 clnt (make :server-name "localhost") (unwind-protect (begin - (tls-connect clnt "localhost" 8087 'tcp) + (tls-connect clnt "localhost" serv-port 'tcp) (display "Aloha!\r\n" (tls-output-port clnt)) (flush (tls-output-port clnt)) (read-line (tls-input-port clnt))) (tls-close clnt))))) + (thread-join! serv-thread) ) (tls-close serv))) ]