@@ -3210,6 +3210,33 @@ ossl_ssl_set_incoming_stream_policy(VALUE self, VALUE policy)
32103210
32113211 return policy ;
32123212}
3213+
3214+ /*
3215+ * call-seq:
3216+ * ssl.stream_read_state => Integer
3217+ *
3218+ * Returns the read state of a QUIC stream as an integer. The possible values
3219+ * are:
3220+ *
3221+ * - +SSL_STREAM_STATE_NONE+ (0): not a QUIC stream object
3222+ * - +SSL_STREAM_STATE_OK+ (1): stream is readable
3223+ * - +SSL_STREAM_STATE_WRONG_DIR+ (2): stream is unidirectional in the wrong direction
3224+ * - +SSL_STREAM_STATE_FINISHED+ (3): FIN received, no more data
3225+ * - +SSL_STREAM_STATE_RESET_LOCAL+ (4): stream was reset locally
3226+ * - +SSL_STREAM_STATE_RESET_REMOTE+ (5): stream was reset by the peer (RESET_STREAM)
3227+ * - +SSL_STREAM_STATE_CONN_CLOSED+ (6): connection is closed
3228+ *
3229+ * A state of +SSL_STREAM_STATE_RESET_REMOTE+ or +SSL_STREAM_STATE_CONN_CLOSED+
3230+ * means that calling +read_nonblock+ will raise an +SSLError+.
3231+ */
3232+ static VALUE
3233+ ossl_ssl_stream_read_state (VALUE self )
3234+ {
3235+ SSL * ssl ;
3236+
3237+ GetSSL (self , ssl );
3238+ return INT2NUM (SSL_get_stream_read_state (ssl ));
3239+ }
32133240#endif /* OSSL_USE_QUIC */
32143241
32153242#endif /* !defined(OPENSSL_NO_SOCK) */
@@ -3688,6 +3715,14 @@ Init_ossl_ssl(void)
36883715 rb_define_const (mSSL , "INCOMING_STREAM_POLICY_AUTO" , INT2NUM (SSL_INCOMING_STREAM_POLICY_AUTO ));
36893716 rb_define_const (mSSL , "INCOMING_STREAM_POLICY_ACCEPT" , INT2NUM (SSL_INCOMING_STREAM_POLICY_ACCEPT ));
36903717 rb_define_const (mSSL , "INCOMING_STREAM_POLICY_REJECT" , INT2NUM (SSL_INCOMING_STREAM_POLICY_REJECT ));
3718+ rb_define_method (cSSLSocket , "stream_read_state" , ossl_ssl_stream_read_state , 0 );
3719+ rb_define_const (mSSL , "SSL_STREAM_STATE_NONE" , INT2NUM (SSL_STREAM_STATE_NONE ));
3720+ rb_define_const (mSSL , "SSL_STREAM_STATE_OK" , INT2NUM (SSL_STREAM_STATE_OK ));
3721+ rb_define_const (mSSL , "SSL_STREAM_STATE_WRONG_DIR" , INT2NUM (SSL_STREAM_STATE_WRONG_DIR ));
3722+ rb_define_const (mSSL , "SSL_STREAM_STATE_FINISHED" , INT2NUM (SSL_STREAM_STATE_FINISHED ));
3723+ rb_define_const (mSSL , "SSL_STREAM_STATE_RESET_LOCAL" , INT2NUM (SSL_STREAM_STATE_RESET_LOCAL ));
3724+ rb_define_const (mSSL , "SSL_STREAM_STATE_RESET_REMOTE" , INT2NUM (SSL_STREAM_STATE_RESET_REMOTE ));
3725+ rb_define_const (mSSL , "SSL_STREAM_STATE_CONN_CLOSED" , INT2NUM (SSL_STREAM_STATE_CONN_CLOSED ));
36913726#endif
36923727
36933728 rb_define_const (mSSL , "VERIFY_NONE" , INT2NUM (SSL_VERIFY_NONE ));
0 commit comments