Ludovic Courtès skribis: > The custom input/output port wrapping the TLS session record port would > introduce overhead, and it would also prevent its uses in a non-blocking > context--e.g., with Fibers. The port close mechanism added in GnuTLS > 3.7.7 allows us to get rid of that wrapper. > > * guix/build/download.scm (wrap-record-port-for-gnutls<3.7.7): New > procedure, with code formerly in 'tls-wrap'. > (tls-wrap): Check for 'set-session-record-port-close!' and use it when > available; otherwise call 'wrap-record-port-for-gnutls<3.7.7'. I synchronized Guile's copy of this code: 317b06bf8 web: 'tls-wrap' retries handshake upon non-fatal errors. c01ca10b3 web: Do not wrap TLS port on GnuTLS >= 3.7.7. I realized that’s not enough to make it possible to use non-blocking ports though. First, I noticed that GnuTLS doesn’t implement ‘write_wait_fd’, only ‘read_wait_fd’ (not sure how problematic that is): --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> ,use(web client) scheme@(guile-user)> (define p (open-socket-for-uri "https://guix.gnu.org")) scheme@(guile-user)> ((@@ (ice-9 suspendable-ports) wait-for-writable) p) ice-9/boot-9.scm:1685:16: In procedure raise-exception: In procedure write_wait_fd: unimplemented Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> ,q scheme@(guile-user)> ,use(gnutls) scheme@(guile-user)> (gnutls-version) $1 = "3.7.7" scheme@(guile-user)> ((@@ (ice-9 suspendable-ports) wait-for-readable) p) $2 = 1 --8<---------------cut here---------------end--------------->8--- Second, ‘open-socket-for-uri’ creates a blocking socket and uses that as the backing file descriptor of the TLS session. We’d need a way to pass flags for the ‘socket’ call made by ‘open-socket-for-uri’ so we can pass O_NONBLOCK, maybe as show below: