]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC QSM: Add function to determine if data is waiting
authorHugo Landau <hlandau@openssl.org>
Thu, 28 Mar 2024 08:58:50 +0000 (08:58 +0000)
committerTomas Mraz <tomas@openssl.org>
Wed, 10 Apr 2024 13:48:25 +0000 (15:48 +0200)
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24040)

(cherry picked from commit 3c2bc702eb9287b84e8584ad427e72da0ab21ec1)

include/internal/quic_stream_map.h

index 5c1e1b35b9c81d88d3492cdfa0fcd300e3bf3d93..55a395de16e7343540f57aa6df0147db7871d3a9 100644 (file)
@@ -503,6 +503,40 @@ static ossl_inline ossl_unused int ossl_quic_stream_recv_get_final_size(const QU
     }
 }
 
+/*
+ * Determines the number of bytes available still to be read, and whether a FIN
+ * has yet to be read.
+ */
+static ossl_inline ossl_unused int ossl_quic_stream_recv_pending(const QUIC_STREAM *s)
+{
+    size_t avail;
+    int fin = 0;
+
+    switch (s->recv_state) {
+    default:
+    case QUIC_RSTREAM_STATE_NONE:
+        return 0;
+
+    case QUIC_RSTREAM_STATE_RECV:
+    case QUIC_RSTREAM_STATE_SIZE_KNOWN:
+    case QUIC_RSTREAM_STATE_DATA_RECVD:
+        if (!ossl_quic_rstream_available(s->rstream, &avail, &fin))
+            avail = 0;
+
+        if (avail == 0 && fin)
+            avail = 1;
+
+        return avail;
+
+    case QUIC_RSTREAM_STATE_RESET_RECVD:
+        return 1;
+
+    case QUIC_RSTREAM_STATE_DATA_READ:
+    case QUIC_RSTREAM_STATE_RESET_READ:
+        return 0;
+    }
+}
+
 /*
  * QUIC Stream Map
  * ===============