Skip to content

Commit 204f20f

Browse files
committed
quic: minor cleanups in quic_buffer
PR-URL: #34087 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent 68634d2 commit 204f20f

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/quic/node_quic_buffer-inl.h

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ QuicBuffer::QuicBuffer(QuicBuffer&& src) noexcept
6464
src.ended_ = false;
6565
}
6666

67-
6867
QuicBuffer& QuicBuffer::operator=(QuicBuffer&& src) noexcept {
6968
if (this == &src) return *this;
7069
this->~QuicBuffer();

src/quic/node_quic_buffer.cc

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ void QuicBufferChunk::MemoryInfo(MemoryTracker* tracker) const {
1717

1818
size_t QuicBuffer::Push(uv_buf_t* bufs, size_t nbufs, DoneCB done) {
1919
size_t len = 0;
20-
if (nbufs == 0 || bufs == nullptr || is_empty(bufs[0])) {
20+
if (UNLIKELY(nbufs == 0)) {
2121
done(0);
2222
return 0;
2323
}
24+
DCHECK_NOT_NULL(bufs);
2425
size_t n = 0;
2526
while (nbufs > 1) {
2627
if (!is_empty(bufs[n])) {
@@ -30,8 +31,14 @@ size_t QuicBuffer::Push(uv_buf_t* bufs, size_t nbufs, DoneCB done) {
3031
n++;
3132
nbufs--;
3233
}
33-
len += bufs[n].len;
34-
Push(bufs[n], done);
34+
if (!is_empty(bufs[n])) {
35+
Push(bufs[n], done);
36+
len += bufs[n].len;
37+
}
38+
// Special case if all the bufs were empty.
39+
if (UNLIKELY(len == 0))
40+
done(0);
41+
3542
return len;
3643
}
3744

src/quic/node_quic_buffer.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using DoneCB = std::function<void(int)>;
2424

2525
// When data is sent over QUIC, we are required to retain it in memory
2626
// until we receive an acknowledgement that it has been successfully
27-
// acknowledged. The QuicBuffer object is what we use to handle that
27+
// received. The QuicBuffer object is what we use to handle that
2828
// and track until it is acknowledged. To understand the QuicBuffer
2929
// object itself, it is important to understand how ngtcp2 and nghttp3
3030
// handle data that is given to it to serialize into QUIC packets.
@@ -52,7 +52,7 @@ using DoneCB = std::function<void(int)>;
5252
// QuicBuffer is further complicated by design quirks and limitations
5353
// of the StreamBase API and how it interacts with the JavaScript side.
5454
//
55-
// QuicBuffer is essentially a linked list of QuicBufferChunk instances.
55+
// QuicBuffer is a linked list of QuicBufferChunk instances.
5656
// A single QuicBufferChunk wraps a single non-zero-length uv_buf_t.
5757
// When the QuicBufferChunk is created, we capture the total length
5858
// of the buffer and the total number of bytes remaining to be sent.
@@ -79,7 +79,7 @@ using DoneCB = std::function<void(int)>;
7979
// along with a callback to be called when the data has
8080
// been consumed.
8181
//
82-
// Any given chunk as a remaining-to-be-acknowledged length (length()) and a
82+
// Any given chunk has a remaining-to-be-acknowledged length (length()) and a
8383
// remaining-to-be-read-length (remaining()). The former tracks the number
8484
// of bytes that have yet to be acknowledged by the QUIC peer. Once the
8585
// remaining-to-be-acknowledged length reaches zero, the done callback
@@ -88,7 +88,7 @@ using DoneCB = std::function<void(int)>;
8888
// serialized into QUIC packets and sent.
8989
// The remaining-to-be-acknowledged length is adjusted using consume(),
9090
// while the remaining-to-be-ead length is adjusted using seek().
91-
class QuicBufferChunk : public MemoryRetainer {
91+
class QuicBufferChunk final : public MemoryRetainer {
9292
public:
9393
// Default non-op done handler.
9494
static void default_done(int status) {}
@@ -149,8 +149,8 @@ class QuicBufferChunk : public MemoryRetainer {
149149
friend class QuicBuffer;
150150
};
151151

152-
class QuicBuffer : public bob::SourceImpl<ngtcp2_vec>,
153-
public MemoryRetainer {
152+
class QuicBuffer final : public bob::SourceImpl<ngtcp2_vec>,
153+
public MemoryRetainer {
154154
public:
155155
QuicBuffer() = default;
156156

0 commit comments

Comments
 (0)