From 986fb5638542a943a6d9cd0d38d73605a642c55a Mon Sep 17 00:00:00 2001
From: Dirk Engling <erdgeist@erdgeist.org>
Date: Tue, 17 May 2022 03:09:40 +0200
Subject: Add -2 return code to read() calls that may feature an EAGAIN

---
 vchat-tls.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/vchat-tls.c b/vchat-tls.c
index a6e5e2d..8154521 100755
--- a/vchat-tls.c
+++ b/vchat-tls.c
@@ -464,7 +464,13 @@ ssize_t vc_tls_sendmessage(const void *buf, size_t size) {
 }
 
 ssize_t vc_tls_receivemessage(void *buf, size_t size) {
-   return BIO_read (server_conn, buf, size);
+   ssize_t received = (ssize_t)BIO_read (server_conn, buf, size);
+   fprintf(stderr, "%zd\n", received);
+   if (received != 0)
+      return received;
+   if (BIO_should_retry(server_conn))
+      return -2;
+   return 0;
 }
 
 void vc_tls_cleanup() {
-- 
cgit v1.2.3