Subject: bug#34341: 26.1; url-retrieve-synchronously returns blank buffer

From: Robert Pluim <[email-masked]>
Date: Sun, 12 May 2019 16:55:21 +0200

>>>>> On Sun, 12 May 2019 17:02:56 +0300, Eli Zaretskii <[email-masked]> said:
    >> That patch to src/gnutls.c fixes my testcase, which is imap
    >> over TLS1.3 to gmail. Itʼs pretty simple, I think it could go
    >> to emacs-26. Eli?

    Eli> Didn't I already answer that?  If not, I guess you are now
    Eli> talking about some patch which I didn't see, so please show
    Eli> it.

>From 6d5f5670443f7adfbd6993173ad997ce25827775 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Mon, 6 May 2019 19:55:17 -0400
Subject: [PATCH] Handle GNUTLS_E_AGAIN in emacs_gnutls_read (Bug#34341)

* src/gnutls.c (emacs_gnutls_read): Similar to emacs_gnutls_write,
when gnutls_record_recv returns GNUTLS_E_AGAIN set errno to EGAIN.
---
 src/gnutls.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/gnutls.c b/src/gnutls.c
index 3c16b6c9c3..b724c3592d 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -753,8 +753,15 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte)
     /* The peer closed the connection. */
     return 0;
   else if (emacs_gnutls_handle_error (state, rtnval))
-    /* non-fatal error */
-    return -1;
+    {
+      /* If we get GNUTLS_E_AGAIN, then set errno appropriately so that
+         wait_reading_process_output retries the correct way instead of
+         erroring out.  */
+      if (rtnval == GNUTLS_E_AGAIN)
+        errno = EAGAIN;
+      /* non-fatal error */
+      return -1;
+    }
   else {
     /* a fatal error occurred */
     return 0;
-- 
2.11.0