/* -*- 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_WebTransportStreamBase_h #define mozilla_net_WebTransportStreamBase_h #include "nsISupportsImpl.h" #include "mozilla/net/neqo_glue_ffi_generated.h" #include "mozilla/Mutex.h" #include "nsCOMPtr.h" #include "nsIAsyncInputStream.h" #include "nsIAsyncOutputStream.h" class nsIWebTransportSendStreamStats; class nsIWebTransportReceiveStreamStats; namespace mozilla::net { class WebTransportStreamBase : public nsIInputStreamCallback, public nsIOutputStreamCallback { public: NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING explicit WebTransportStreamBase( uint64_t aSessionId, WebTransportStreamType aType, std::function, nsresult>&&)>&& aCallback); WebTransportStreamType StreamType() const { return mStreamType; } void GetWriterAndReader(nsIAsyncOutputStream** aOutOutputStream, nsIAsyncInputStream** aOutInputStream); virtual uint64_t StreamId() const = 0; virtual void SendStopSending(uint8_t aErrorCode) = 0; virtual void SendFin() = 0; virtual void Reset(uint64_t aErrorCode) = 0; virtual already_AddRefed GetSendStreamStats() = 0; virtual already_AddRefed GetReceiveStreamStats() = 0; virtual bool RecvDone() const = 0; virtual void SetSendOrder(Maybe aSendOrder) = 0; protected: virtual ~WebTransportStreamBase(); nsresult InitOutputPipe(); nsresult InitInputPipe(); uint64_t mSessionId{UINT64_MAX}; WebTransportStreamType mStreamType{WebTransportStreamType::BiDi}; enum StreamRole { INCOMING, OUTGOING, } mStreamRole{INCOMING}; enum SendStreamState { WAITING_TO_ACTIVATE, WAITING_DATA, SENDING, SEND_DONE, } mSendState{WAITING_TO_ACTIVATE}; enum RecvStreamState { BEFORE_READING, READING, RECEIVED_FIN, RECV_DONE }; Atomic mRecvState{BEFORE_READING}; nsresult mSocketOutCondition = NS_ERROR_NOT_INITIALIZED; nsresult mSocketInCondition = NS_ERROR_NOT_INITIALIZED; std::function, nsresult>&&)> mStreamReadyCallback; Mutex mMutex{"WebTransportStreamBase::mMutex"}; nsCOMPtr mSendStreamPipeIn; nsCOMPtr mSendStreamPipeOut MOZ_GUARDED_BY(mMutex); nsCOMPtr mReceiveStreamPipeIn MOZ_GUARDED_BY(mMutex); nsCOMPtr mReceiveStreamPipeOut; }; } // namespace mozilla::net inline nsISupports* ToSupports(mozilla::net::WebTransportStreamBase* aStream) { return static_cast(aStream); } #endif // mozilla_net_WebTransportStreamBase_h