diff --git a/iocore/net/quic/QUICBidirectionalStream.cc b/iocore/net/quic/QUICBidirectionalStream.cc index 9565b0ac444..936b5fbbc85 100644 --- a/iocore/net/quic/QUICBidirectionalStream.cc +++ b/iocore/net/quic/QUICBidirectionalStream.cc @@ -355,8 +355,16 @@ bool QUICBidirectionalStream::will_generate_frame(QUICEncryptionLevel level, size_t current_packet_size, bool ack_eliciting, uint32_t seq_num) { - return this->_local_flow_controller.will_generate_frame(level, current_packet_size, ack_eliciting, seq_num) || - !this->is_retransmited_frame_queue_empty() || this->_write_vio.get_reader()->is_read_avail_more_than(0); + if (this->_local_flow_controller.will_generate_frame(level, current_packet_size, ack_eliciting, seq_num)) { + return true; + } + if (!this->is_retransmited_frame_queue_empty()) { + return true; + } + if (this->_write_vio.op != VIO::NONE && this->_write_vio.get_reader()->is_read_avail_more_than(0)) { + return true; + }; + return false; } QUICFrame * diff --git a/iocore/net/quic/QUICUnidirectionalStream.cc b/iocore/net/quic/QUICUnidirectionalStream.cc index 9a2d32143e0..73846221b6f 100644 --- a/iocore/net/quic/QUICUnidirectionalStream.cc +++ b/iocore/net/quic/QUICUnidirectionalStream.cc @@ -127,7 +127,13 @@ QUICSendStream::state_stream_closed(int event, void *data) bool QUICSendStream::will_generate_frame(QUICEncryptionLevel level, size_t current_packet_size, bool ack_eliciting, uint32_t seq_num) { - return !this->is_retransmited_frame_queue_empty() || this->_write_vio.get_reader()->is_read_avail_more_than(0); + if (!this->is_retransmited_frame_queue_empty()) { + return true; + } + if (this->_write_vio.op != VIO::NONE && this->_write_vio.get_reader()->is_read_avail_more_than(0)) { + return true; + } + return false; } QUICFrame * @@ -529,8 +535,13 @@ QUICReceiveStream::is_cancelled() const bool QUICReceiveStream::will_generate_frame(QUICEncryptionLevel level, size_t current_packet_size, bool ack_eliciting, uint32_t seq_num) { - return this->_local_flow_controller.will_generate_frame(level, current_packet_size, ack_eliciting, seq_num) || - (this->_stop_sending_reason != nullptr && this->_is_stop_sending_sent == false); + if (this->_local_flow_controller.will_generate_frame(level, current_packet_size, ack_eliciting, seq_num)) { + return true; + } + if (this->_stop_sending_reason != nullptr && this->_is_stop_sending_sent == false) { + return true; + } + return false; } QUICFrame * diff --git a/iocore/net/quic/test/test_QUICStream.cc b/iocore/net/quic/test/test_QUICStream.cc index 3d57a81ba06..8a7d2ee98bc 100644 --- a/iocore/net/quic/test/test_QUICStream.cc +++ b/iocore/net/quic/test/test_QUICStream.cc @@ -836,3 +836,22 @@ TEST_CASE("QUIC send only stream", "[quic]") CHECK(frame->type() == QUICFrameType::RESET_STREAM); } } + +TEST_CASE("will_generate_frame", "[quic]") +{ + SECTION("Return false if a stream has not initialized for IO") + { + QUICRTTMeasure rtt_provider; + MockQUICConnectionInfoProvider cinfo_provider; + + std::unique_ptr stream_bidi( + new QUICBidirectionalStream(&rtt_provider, &cinfo_provider, 0, 1024, 1024)); + CHECK(stream_bidi->will_generate_frame(QUICEncryptionLevel::ONE_RTT, 0, false, 0) == false); + + std::unique_ptr stream_uni1(new QUICSendStream(&cinfo_provider, 2, 1024)); + CHECK(stream_uni1->will_generate_frame(QUICEncryptionLevel::ONE_RTT, 0, false, 0) == false); + + std::unique_ptr stream_uni2(new QUICReceiveStream(&rtt_provider, &cinfo_provider, 3, 1024)); + CHECK(stream_uni2->will_generate_frame(QUICEncryptionLevel::ONE_RTT, 0, false, 0) == false); + } +}