From c521620b4e6ccc61bc3275565f8b09b3504e7ae2 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 9 Jan 2020 10:48:53 -0800 Subject: [PATCH] [Squash] nits --- src/quic/node_quic_default_application.cc | 14 +++++----- src/quic/node_quic_session-inl.h | 2 +- src/quic/node_quic_session.cc | 4 +-- src/quic/node_quic_session.h | 3 +-- src/quic/node_quic_stream-inl.h | 28 -------------------- src/quic/node_quic_stream.cc | 31 +++++++++++++++++++++-- src/quic/node_quic_stream.h | 8 +++--- 7 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/quic/node_quic_default_application.cc b/src/quic/node_quic_default_application.cc index 4665c24f33..a151796b93 100644 --- a/src/quic/node_quic_default_application.cc +++ b/src/quic/node_quic_default_application.cc @@ -124,7 +124,7 @@ int DefaultApplication::GetStreamData(StreamData* stream_data) { &stream_data->count, MAX_VECTOR_COUNT); - stream_data->user_data = stream; + stream_data->stream.reset(stream); stream_data->id = stream->id(); stream_data->fin = stream->is_writable() ? 0 : 1; @@ -133,7 +133,7 @@ int DefaultApplication::GetStreamData(StreamData* stream_data) { // that yet as it depends entirely on how much data actually gets // serialized by ngtcp2. if (stream_data->count > 0) - ScheduleStream(stream->id()); + stream->Schedule(&stream_queue_); Debug(session(), "Selected %" PRId64 " buffers for stream %" PRId64 "%s", stream_data->count, @@ -145,20 +145,18 @@ int DefaultApplication::GetStreamData(StreamData* stream_data) { bool DefaultApplication::StreamCommit( StreamData* stream_data, size_t datalen) { - QuicStream* stream = static_cast(stream_data->user_data); - CHECK_NOT_NULL(stream); + CHECK(stream_data->stream); stream_data->remaining -= datalen; Consume(&stream_data->buf, &stream_data->count, datalen); - stream->Commit(datalen); + stream_data->stream->Commit(datalen); return true; } bool DefaultApplication::ShouldSetFin(const StreamData& stream_data) { - if (stream_data.user_data == nullptr || + if (!stream_data.stream || !IsEmpty(stream_data.buf, stream_data.count)) return false; - QuicStream* stream = static_cast(stream_data.user_data); - return !stream->is_writable(); + return !stream_data.stream->is_writable(); } } // namespace quic diff --git a/src/quic/node_quic_session-inl.h b/src/quic/node_quic_session-inl.h index aebd3c939e..62fda5fd57 100644 --- a/src/quic/node_quic_session-inl.h +++ b/src/quic/node_quic_session-inl.h @@ -149,7 +149,7 @@ ssize_t QuicApplication::WriteVStream( uint8_t* buf, ssize_t* ndatalen, const StreamData& stream_data) { - CHECK_LE(stream_data.count, 16); + CHECK_LE(stream_data.count, MAX_VECTOR_COUNT); return ngtcp2_conn_writev_stream( session()->connection(), &path->path, diff --git a/src/quic/node_quic_session.cc b/src/quic/node_quic_session.cc index a430b49e47..8b44247fcf 100644 --- a/src/quic/node_quic_session.cc +++ b/src/quic/node_quic_session.cc @@ -1111,7 +1111,7 @@ void QuicApplication::Acknowledge( bool QuicApplication::SendPendingData() { // The maximum number of packets to send per call - static constexpr size_t MAX_PACKETS = 16; + static constexpr size_t kMaxPackets = 16; QuicPathStorage path; std::unique_ptr packet; uint8_t* pos = nullptr; @@ -1190,7 +1190,7 @@ bool QuicApplication::SendPendingData() { packet.reset(); pos = nullptr; MaybeSetFin(stream_data); - if (++packets_sent == MAX_PACKETS) + if (++packets_sent == kMaxPackets) break; } return true; diff --git a/src/quic/node_quic_session.h b/src/quic/node_quic_session.h index e2c162e0cf..e2d893cb00 100644 --- a/src/quic/node_quic_session.h +++ b/src/quic/node_quic_session.h @@ -548,8 +548,7 @@ class QuicApplication : public MemoryRetainer { int fin = 0; ngtcp2_vec data[MAX_VECTOR_COUNT] {}; ngtcp2_vec* buf = nullptr; - void* user_data = nullptr; - uint8_t* pos = nullptr; + BaseObjectPtr stream; StreamData() { buf = data; } }; diff --git a/src/quic/node_quic_stream-inl.h b/src/quic/node_quic_stream-inl.h index 530fddc3c8..9981ead8df 100644 --- a/src/quic/node_quic_stream-inl.h +++ b/src/quic/node_quic_stream-inl.h @@ -75,14 +75,6 @@ bool QuicStream::is_read_paused() const { return flags_ & QUICSTREAM_FLAG_READ_PAUSED; } -bool QuicStream::IsAlive() { - return !is_destroyed() && !IsClosing(); -} - -bool QuicStream::IsClosing() { - return !is_writable() && !is_readable(); -} - void QuicStream::set_fin_sent() { CHECK(!is_writable()); flags_ |= QUICSTREAM_FLAG_FIN_SENT; @@ -168,26 +160,6 @@ void QuicStream::Commit(ssize_t amount) { streambuf_.Seek(amount); } -int QuicStream::ReadStart() { - CHECK(!is_destroyed()); - CHECK(is_readable()); - set_read_start(); - set_read_resume(); - IncrementStat( - inbound_consumed_data_while_paused_, - &stream_stats_, - &stream_stats::max_offset); - session_->ExtendStreamOffset(this, inbound_consumed_data_while_paused_); - return 0; -} - -int QuicStream::ReadStop() { - CHECK(!is_destroyed()); - CHECK(is_readable()); - set_read_pause(); - return 0; -} - void QuicStream::ResetStream(uint64_t app_error_code) { // On calling shutdown, the stream will no longer be // readable or writable, all any pending data in the diff --git a/src/quic/node_quic_stream.cc b/src/quic/node_quic_stream.cc index 54e0bf315e..d9dc24f2ef 100644 --- a/src/quic/node_quic_stream.cc +++ b/src/quic/node_quic_stream.cc @@ -203,8 +203,7 @@ int QuicStream::DoShutdown(ShutdownWrap* req_wrap) { session()->ResumeStream(stream_id_); } - req_wrap->Done(0); - return 0; + return 1; } int QuicStream::DoWrite( @@ -265,6 +264,34 @@ int QuicStream::DoWrite( return 0; } +bool QuicStream::IsAlive() { + return !is_destroyed() && !IsClosing(); +} + +bool QuicStream::IsClosing() { + return !is_writable() && !is_readable(); +} + +int QuicStream::ReadStart() { + CHECK(!is_destroyed()); + CHECK(is_readable()); + set_read_start(); + set_read_resume(); + IncrementStat( + inbound_consumed_data_while_paused_, + &stream_stats_, + &stream_stats::max_offset); + session_->ExtendStreamOffset(this, inbound_consumed_data_while_paused_); + return 0; +} + +int QuicStream::ReadStop() { + CHECK(!is_destroyed()); + CHECK(is_readable()); + set_read_pause(); + return 0; +} + void QuicStream::IncrementStats(size_t datalen) { uint64_t len = static_cast(datalen); IncrementStat(len, &stream_stats_, &stream_stats::bytes_received); diff --git a/src/quic/node_quic_stream.h b/src/quic/node_quic_stream.h index a0b7a767c7..6853925ae5 100644 --- a/src/quic/node_quic_stream.h +++ b/src/quic/node_quic_stream.h @@ -341,10 +341,10 @@ class QuicStream : public AsyncWrap, public StreamBase { inline bool SubmitTrailers(v8::Local headers); // Required for StreamBase - inline bool IsAlive() override; - inline bool IsClosing() override; - inline int ReadStart() override; - inline int ReadStop() override; + bool IsAlive() override; + bool IsClosing() override; + int ReadStart() override; + int ReadStop() override; int DoShutdown(ShutdownWrap* req_wrap) override; AsyncWrap* GetAsyncWrap() override { return this; }