WebTransportStreamProxy.h (2557B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef mozilla_net_WebTransportStreamProxy_h 7 #define mozilla_net_WebTransportStreamProxy_h 8 9 #include "nsIAsyncInputStream.h" 10 #include "nsIAsyncOutputStream.h" 11 #include "nsIWebTransportStream.h" 12 #include "nsCOMPtr.h" 13 #include "WebTransportStreamBase.h" 14 15 namespace mozilla::net { 16 17 class WebTransportStreamProxy final 18 : public nsIWebTransportReceiveStream, 19 public nsIWebTransportSendStream, 20 public nsIWebTransportBidirectionalStream { 21 public: 22 NS_DECL_THREADSAFE_ISUPPORTS 23 24 explicit WebTransportStreamProxy(WebTransportStreamBase* aStream); 25 26 NS_IMETHOD SendStopSending(uint8_t aError) override; 27 NS_IMETHOD SendFin() override; 28 NS_IMETHOD Reset(uint8_t aErrorCode) override; 29 NS_IMETHOD GetSendStreamStats( 30 nsIWebTransportStreamStatsCallback* aCallback) override; 31 NS_IMETHOD GetReceiveStreamStats( 32 nsIWebTransportStreamStatsCallback* aCallback) override; 33 34 NS_IMETHOD GetHasReceivedFIN(bool* aHasReceivedFIN) override; 35 36 NS_IMETHOD GetInputStream(nsIAsyncInputStream** aOut) override; 37 NS_IMETHOD GetOutputStream(nsIAsyncOutputStream** aOut) override; 38 39 NS_IMETHOD GetStreamId(uint64_t* aId) override; 40 NS_IMETHOD SetSendOrder(Maybe<int64_t> aSendOrder) override; 41 42 private: 43 virtual ~WebTransportStreamProxy(); 44 45 class AsyncInputStreamWrapper : public nsIAsyncInputStream { 46 public: 47 NS_DECL_THREADSAFE_ISUPPORTS 48 NS_DECL_NSIINPUTSTREAM 49 NS_DECL_NSIASYNCINPUTSTREAM 50 51 AsyncInputStreamWrapper(nsIAsyncInputStream* aStream, 52 WebTransportStreamBase* aWebTransportStream); 53 54 private: 55 virtual ~AsyncInputStreamWrapper(); 56 void MaybeCloseStream(); 57 58 nsCOMPtr<nsIAsyncInputStream> mStream; 59 RefPtr<WebTransportStreamBase> mWebTransportStream; 60 }; 61 62 class AsyncOutputStreamWrapper : public nsIAsyncOutputStream { 63 public: 64 NS_DECL_THREADSAFE_ISUPPORTS 65 NS_DECL_NSIOUTPUTSTREAM 66 NS_DECL_NSIASYNCOUTPUTSTREAM 67 68 explicit AsyncOutputStreamWrapper(nsIAsyncOutputStream* aStream); 69 70 private: 71 virtual ~AsyncOutputStreamWrapper(); 72 73 nsCOMPtr<nsIAsyncOutputStream> mStream; 74 }; 75 76 RefPtr<WebTransportStreamBase> mWebTransportStream; 77 RefPtr<AsyncOutputStreamWrapper> mWriter; 78 RefPtr<AsyncInputStreamWrapper> mReader; 79 }; 80 81 } // namespace mozilla::net 82 83 #endif