From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Baines Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Allow specifying the socket style for open-socket-for-uri. Date: Thu, 20 Jul 2023 15:08:38 +0100 Message-ID: <20230720140838.24179-1-mail@cbaines.net> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30393"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Jul 20 16:09:04 2023 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qMUL0-0007cL-JC for guile-devel@m.gmane-mx.org; Thu, 20 Jul 2023 16:09:02 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qMUKg-0006KE-Hz; Thu, 20 Jul 2023 10:08:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qMUKe-0006K1-RX for guile-devel@gnu.org; Thu, 20 Jul 2023 10:08:40 -0400 Original-Received: from mira.cbaines.net ([212.71.252.8]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qMUKd-0000FP-CA for guile-devel@gnu.org; Thu, 20 Jul 2023 10:08:40 -0400 Original-Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:54d1:d5d4:280e:f699]) by mira.cbaines.net (Postfix) with ESMTPSA id 690C327BBE2 for ; Thu, 20 Jul 2023 15:08:38 +0100 (BST) Original-Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 7559fc82 for ; Thu, 20 Jul 2023 14:08:38 +0000 (UTC) X-Mailer: git-send-email 2.41.0 Received-SPF: pass client-ip=212.71.252.8; envelope-from=mail@cbaines.net; helo=mira.cbaines.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:21904 Archived-At: Since this allows specifying additional behaviours for the socket through using SOCK_CLOEXEC and/or SOCK_NONBLOCK (when bitwise or'ed with SOCK_STREAM). Note that Guile/guile-gnutls currently doesn't support performing the TLS handshake on a non-blocking socket, so this currently won't work. * module/web/client.scm (open-socket-for-uri): Allow specifying the socket style. --- module/web/client.scm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/module/web/client.scm b/module/web/client.scm index 6c54c5021..a5405d17f 100644 --- a/module/web/client.scm +++ b/module/web/client.scm @@ -317,9 +317,11 @@ host name without trailing dot." (read-response port)) (define* (open-socket-for-uri uri-or-string - #:key (verify-certificate? #t)) + #:key (verify-certificate? #t) + (socket-style SOCK_STREAM)) "Return an open input/output port for a connection to URI-OR-STRING. -When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates." +When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates. +SOCKET-STYLE is passed as the second argument to the socket procedure." (define uri (ensure-uri-reference uri-or-string)) (define https? @@ -346,7 +348,9 @@ When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates." (let* ((ai (car addresses)) (s (with-fluids ((%default-port-encoding #f)) ;; Restrict ourselves to TCP. - (socket (addrinfo:fam ai) SOCK_STREAM IPPROTO_IP)))) + (socket (addrinfo:fam ai) + socket-style + IPPROTO_IP)))) (catch 'system-error (lambda () (connect s (addrinfo:addr ai)) -- 2.41.0