1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set sw=2 ts=8 et tw=80 ft=cpp : */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef webrtc_tcp_socket_wrapper__ 8 #define webrtc_tcp_socket_wrapper__ 9 10 #include <memory> 11 12 #include "nsCOMPtr.h" 13 #include "nsTArray.h" 14 15 #include "mozilla/net/WebrtcTCPSocketCallback.h" 16 17 class nsIEventTarget; 18 19 namespace mozilla { 20 21 class NrSocketProxyConfig; 22 23 namespace net { 24 25 class WebrtcTCPSocketChild; 26 27 /** 28 * WebrtcTCPSocketWrapper is a protector class for mtransport and IPDL. 29 * mtransport and IPDL cannot include headers from each other due to conflicting 30 * typedefs. Also it helps users by dispatching calls to the appropriate thread 31 * based on mtransport's and IPDL's threading requirements. 32 * 33 * WebrtcTCPSocketWrapper is only used in the child process. 34 * WebrtcTCPSocketWrapper does not dispatch for the parent process. 35 * WebrtcTCPSocketCallback calls are dispatched to the STS thread. 36 * IPDL calls are dispatched to the main thread. 37 */ 38 class WebrtcTCPSocketWrapper : public WebrtcTCPSocketCallback { 39 public: 40 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebrtcTCPSocketWrapper, override) 41 42 explicit WebrtcTCPSocketWrapper(WebrtcTCPSocketCallback* aCallbacks); 43 44 virtual void AsyncOpen(const nsCString& aHost, const int& aPort, 45 const nsCString& aLocalAddress, const int& aLocalPort, 46 bool aUseTls, 47 const std::shared_ptr<NrSocketProxyConfig>& aConfig); 48 virtual void SendWrite(nsTArray<uint8_t>&& aReadData); 49 virtual void Close(); 50 51 // WebrtcTCPSocketCallback 52 virtual void OnClose(nsresult aReason) override; 53 virtual void OnConnected(const nsCString& aProxyType) override; 54 virtual void OnRead(nsTArray<uint8_t>&& aReadData) override; 55 56 protected: 57 RefPtr<WebrtcTCPSocketCallback> mProxyCallbacks; 58 RefPtr<WebrtcTCPSocketChild> mWebrtcTCPSocket; 59 60 nsCOMPtr<nsIEventTarget> mMainThread; 61 nsCOMPtr<nsIEventTarget> mSocketThread; 62 63 virtual ~WebrtcTCPSocketWrapper(); 64 }; 65 66 } // namespace net 67 } // namespace mozilla 68 69 #endif // webrtc_tcp_socket_wrapper__ 70