Ludovic Courtès <[email protected]> writes:

> Christopher Baines <[email protected]> skribis:
>
>> As described in the GnuTLS documentation on Asynchronous operation,
>> GNUTLS_NONBLOCK should be passed to gnutls_init, and the Guile
>> equivalent is passing connection-flag/nonblock to make-session.
>>
>> Additionally, error/again or error/interrupted should lead to a retry of
>> the handshake, after waiting for the appropriate I/O on the port.  As
>> record-get-direction is new in Guile-GnuTLS, specifically check if this
>> is defined.
>>
>> * module/web/client.scm (tls-wrap): Call make-session with
>> connection-flag/nonblock if the port is non-blocking, and handle waiting
>> for I/O when performing the handshake.
>
> [...]
>
>> +  (let ((session
>> +         (apply
>> +          make-session
>> +          (cons connection-end/client
>> +                (if (zero? (logand O_NONBLOCK (fcntl port F_GETFL)))
>> +                    '()
>> +                    ;; If the port is non-blocking, tell GnuTLS
>> +                    (list connection-flag/nonblock)))))
>
> You can avoid ‘cons’ here:
>
>   (apply make-session connection-end/client
>          (if … '() (list …)))

That looks good to me.

>> +          (cond ((and
>> +                  (or (eq? err error/again)
>> +                      (eq? err error/interrupted))
>> +                  (module-defined? (resolve-interface '(gnutls))
>> +                                   'record-get-direction)) ; Guile-GnuTLS 
>> >= 4.0.0
>> +                 (if (= 0 (record-get-direction session))
>> +                     ((current-read-waiter) port)
>> +                     ((current-write-waiter) port))
>
> Should EINTR (error/interrupted) really be treated in the same way as
> EAGAIN?  That looks fishy.

I don't know, I got this from the documentation for record-get-direction
https://gnutls.org/manual/html_node/Asynchronous-operation.html

> Also, this only addresses handshake, but what about ‘error/again’ raise
> while transferring data over the session record port?

I'm not sure, but here I'm just trying to change the behaviour for the
handshake. I'm already using gnutls over nonblocking ports, and I'm not
aware of any significant issues.

I'm coming back to this issue after a while, and I've also opened a Pull
Request here now https://codeberg.org/guile/guile/pulls/95

Attachment: signature.asc
Description: PGP signature

Reply via email to