/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_net_Http2WebTransportStream_h #define mozilla_net_Http2WebTransportStream_h #include #include "mozilla/CheckedInt.h" #include "mozilla/Queue.h" #include "WebTransportFlowControl.h" #include "WebTransportStreamBase.h" namespace mozilla::net { class Capsule; class Http2WebTransportSessionImpl; class StreamData final { public: explicit StreamData(nsTArray&& aData) : mData(std::move(aData)) { MOZ_COUNT_CTOR(StreamData); } MOZ_COUNTED_DTOR(StreamData) const nsTArray& GetData() const { return mData; } private: nsTArray mData; }; class Http2WebTransportStream final : public WebTransportStreamBase { public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIINPUTSTREAMCALLBACK NS_DECL_NSIOUTPUTSTREAMCALLBACK explicit Http2WebTransportStream( Http2WebTransportSessionImpl* aWebTransportSession, StreamId aStreamId, uint64_t aInitialMaxStreamData, uint64_t aInitialLocalMaxStreamData, std::function, nsresult>&&)>&& aCallback); explicit Http2WebTransportStream( Http2WebTransportSessionImpl* aWebTransportSession, uint64_t aInitialMaxStreamData, uint64_t aInitialLocalMaxStreamData, StreamId aStreamId); nsresult Init(); StreamId WebTransportStreamId() const override; uint64_t GetStreamId() const override; void SendStopSending(uint8_t aErrorCode) override; void SendFin() override; void Reset(uint64_t aErrorCode) override; already_AddRefed GetSendStreamStats() override; already_AddRefed GetReceiveStreamStats() override; bool RecvDone() const override; void SetSendOrder(Maybe aSendOrder) override; SenderFlowControlBase* SenderFc() override { return &mFc; } ReceiverFlowControlBase* ReceiverFc() override { return &mReceiverFc; } nsresult OnCapsule(Capsule&& aCapsule); void Close(nsresult aResult); void WriteMaintenanceCapsules( mozilla::Queue>& aOutput); void TakeOutputCapsule(mozilla::Queue>& aOutput); void OnStopSending(); void OnReset(uint64_t aSize); void OnStreamDataSent(size_t aCount); private: virtual ~Http2WebTransportStream(); static nsresult ReadRequestSegment(nsIInputStream*, void*, const char*, uint32_t, uint32_t, uint32_t*); nsresult HandleStreamData(bool aFin, nsTArray&& aData); nsresult HandleMaxStreamData(uint64_t aLimit); nsresult HandleStopSending(uint64_t aError); RefPtr mWebTransportSession; class StreamId mStreamId{0u}; nsTArray mBuffer; CheckedUint64 mTotalSent{0}; uint64_t mTotalReceived = 0; Maybe mReliableSize; uint32_t mWriteOffset = 0; bool mSentStopSending = false; bool mSentReset = false; // The queue used for passing data to the upper layer. // When mReceiveStreamPipeOut->Write() returns NS_BASE_STREAM_WOULD_BLOCK, we // need to store the data in this queue. mozilla::Queue> mOutgoingQueue; mozilla::Queue> mCapsuleQueue; UniquePtr mCurrentOut; const RefPtr mOwnerThread; SenderFlowControlStreamId mFc; ReceiverFlowControlStreamId mReceiverFc; Maybe mStopSendingCapsule; Maybe mStreamResetCapsule; }; } // namespace mozilla::net #endif