UDPSocketChild.h (3637B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 mozilla_dom_UDPSocketChild_h__ 8 #define mozilla_dom_UDPSocketChild_h__ 9 10 #include "mozilla/net/PUDPSocketChild.h" 11 #include "nsCOMPtr.h" 12 #include "nsCycleCollectionParticipant.h" 13 14 #define UDPSOCKETCHILD_CID \ 15 {0xb47e5a0f, 0xd384, 0x48ef, {0x88, 0x85, 0x42, 0x59, 0x79, 0x3d, 0x9c, 0xf0}} 16 17 class nsIInputStream; 18 class nsIPrincipal; 19 class nsIUDPSocketInternal; 20 21 namespace mozilla::dom { 22 23 class UDPSocketChildBase : public nsISupports { 24 public: 25 NS_DECL_ISUPPORTS 26 27 void AddIPDLReference(); 28 void ReleaseIPDLReference(); 29 30 protected: 31 UDPSocketChildBase(); 32 virtual ~UDPSocketChildBase(); 33 nsCOMPtr<nsIUDPSocketInternal> mSocket; 34 bool mIPCOpen; 35 }; 36 37 class UDPSocketChild : public mozilla::net::PUDPSocketChild, 38 public UDPSocketChildBase { 39 public: 40 NS_IMETHOD_(MozExternalRefCountType) Release() override; 41 42 UDPSocketChild(); 43 virtual ~UDPSocketChild(); 44 45 uint16_t LocalPort() const { return mLocalPort; } 46 // Local address as UTF-8. 47 const nsACString& LocalAddress() const { return mLocalAddress; } 48 49 nsresult SetFilterName(const nsACString& aFilterName); 50 51 // Allow hosting this over PBackground instead of PNecko 52 nsresult SetBackgroundSpinsEvents(); 53 54 // Tell the chrome process to bind the UDP socket to a given local host and 55 // port 56 nsresult Bind(nsIUDPSocketInternal* aSocket, nsIPrincipal* aPrincipal, 57 const nsACString& aHost, uint16_t aPort, bool aAddressReuse, 58 bool aLoopback, uint32_t recvBufferSize, 59 uint32_t sendBufferSize); 60 61 // Tell the chrome process to connect the UDP socket to a given remote host 62 // and port 63 void Connect(nsIUDPSocketInternal* aSocket, const nsACString& aHost, 64 uint16_t aPort); 65 66 // Send the given data to the given address. 67 nsresult SendWithAddress(const NetAddr* aAddr, const uint8_t* aData, 68 uint32_t aByteLength); 69 70 // Send input stream. This must be a buffered stream implementation. 71 nsresult SendBinaryStream(const nsACString& aHost, uint16_t aPort, 72 nsIInputStream* aStream); 73 74 void Close(); 75 76 // Address and interface are both UTF-8. 77 void JoinMulticast(const nsACString& aMulticastAddress, 78 const nsACString& aInterface); 79 void LeaveMulticast(const nsACString& aMulticastAddress, 80 const nsACString& aInterface); 81 82 mozilla::ipc::IPCResult RecvCallbackOpened( 83 const UDPAddressInfo& aAddressInfo); 84 mozilla::ipc::IPCResult RecvCallbackConnected( 85 const UDPAddressInfo& aAddressInfo); 86 mozilla::ipc::IPCResult RecvCallbackClosed(); 87 mozilla::ipc::IPCResult RecvCallbackReceivedData( 88 const UDPAddressInfo& aAddressInfo, nsTArray<uint8_t>&& aData); 89 mozilla::ipc::IPCResult RecvCallbackError(const nsCString& aMessage, 90 const nsCString& aFilename, 91 const uint32_t& aLineNumber); 92 93 private: 94 nsresult SendDataInternal(const UDPSocketAddr& aAddr, const uint8_t* aData, 95 const uint32_t aByteLength); 96 97 mozilla::ipc::PBackgroundChild* mBackgroundManager; 98 uint16_t mLocalPort; 99 nsCString mLocalAddress; 100 nsCString mFilterName; 101 }; 102 103 } // namespace mozilla::dom 104 105 #endif // !defined(mozilla_dom_UDPSocketChild_h__)