@@ -28,22 +28,23 @@ struct PathDescriptor final {
2828 std::string ToString () const ;
2929};
3030
31- // A Packet encapsulates serialized outbound QUIC data.
32- // Packets must never be larger than the path MTU. The
33- // default QUIC packet maximum length is 1200 bytes,
34- // which we assume by default. The packet storage will
35- // be stack allocated up to this size.
31+ // A Packet encapsulates serialized outbound QUIC data. Packets must never be
32+ // larger than the path MTU. The default QUIC packet maximum length is 1200
33+ // bytes, which we assume by default. The packet storage will be stack allocated
34+ // up to this size.
3635//
37- // Packets are maintained in a freelist held by the
38- // BindingData instance. When using Create() to create
39- // a Packet, we'll check to see if there is a free
40- // packet in the freelist and use it instead of starting
41- // fresh with a new packet. The freelist can store at
42- // most kMaxFreeList packets
36+ // Packets are maintained in a freelist held by the BindingData instance. When
37+ // using Create() to create a Packet, we'll check to see if there is a free
38+ // packet in the freelist and use it instead of starting fresh with a new
39+ // packet. The freelist can store at most kMaxFreeList packets. This is a
40+ // performance optimization to avoid excessive allocation churn when creating
41+ // lots of packets since each one is ReqWrap and has a fair amount of associated
42+ // overhead. However, we don't want to accumulate too many of these in the
43+ // freelist either, so we cap the size.
4344//
44- // Packets are always encrypted so their content should
45- // be considered opaque to us. We leave it entirely up
46- // to ngtcp2 how to encode QUIC frames into the packet.
45+ // Packets are always encrypted so their content should be considered opaque
46+ // to us. We leave it entirely up to ngtcp2 how to encode QUIC frames into
47+ // the packet.
4748class Packet final : public ReqWrap<uv_udp_send_t > {
4849 private:
4950 struct Data ;
@@ -56,11 +57,9 @@ class Packet final : public ReqWrap<uv_udp_send_t> {
5657 virtual void PacketDone (int status) = 0;
5758 };
5859
59- // Do not use the Packet constructors directly to create
60- // them. These are public only to support MakeBaseObject.
61- // Use the Create, or Create variants to create or
62- // acquire packet instances.
63-
60+ // Do not use the Packet constructors directly to create them. These are
61+ // public only to support MakeBaseObject. Use the Create, or Create variants
62+ // to create or acquire packet instances.
6463 Packet (Environment* env,
6564 Listener* listener,
6665 v8::Local<v8::Object> object,
@@ -80,13 +79,17 @@ class Packet final : public ReqWrap<uv_udp_send_t> {
8079 size_t length () const ;
8180 operator uv_buf_t () const ;
8281 operator ngtcp2_vec () const ;
82+ operator bool () const ;
8383
8484 // Modify the size of the packet after ngtcp2 has written
8585 // to it. len must be <= length(). We call this after we've
8686 // asked ngtcp2 to encode frames into the packet and ngtcp2
8787 // tells us how many of the packets bytes were used.
8888 void Truncate (size_t len);
8989
90+ // Create (or acquire from the freelist) a Packet with the given
91+ // destination and length. The diagnostic_label is used to help
92+ // identify the packet purpose in debugging output.
9093 static BaseObjectPtr<Packet> Create (
9194 Environment* env,
9295 Listener* listener,
0 commit comments