UDPSocketParent.h (3372B)
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_UDPSocketParent_h__ 8 #define mozilla_dom_UDPSocketParent_h__ 9 10 #include "mozilla/dom/PermissionMessageUtils.h" 11 #include "mozilla/net/PUDPSocketParent.h" 12 #include "nsCOMPtr.h" 13 #include "nsISocketFilter.h" 14 #include "nsIUDPSocket.h" 15 16 namespace mozilla { 17 namespace net { 18 class PNeckoParent; 19 } // namespace net 20 21 namespace dom { 22 23 class UDPSocketParent : public mozilla::net::PUDPSocketParent, 24 public nsIUDPSocketListener { 25 public: 26 NS_DECL_THREADSAFE_ISUPPORTS 27 NS_DECL_NSIUDPSOCKETLISTENER 28 29 explicit UDPSocketParent(PBackgroundParent* aManager); 30 explicit UDPSocketParent(PNeckoParent* aManager); 31 32 bool Init(nsIPrincipal* aPrincipal, const nsACString& aFilter); 33 34 mozilla::ipc::IPCResult RecvBind(const UDPAddressInfo& aAddressInfo, 35 const bool& aAddressReuse, 36 const bool& aLoopback, 37 const uint32_t& recvBufferSize, 38 const uint32_t& sendBufferSize); 39 mozilla::ipc::IPCResult RecvConnect(const UDPAddressInfo& aAddressInfo); 40 void DoSendConnectResponse(const UDPAddressInfo& aAddressInfo); 41 void SendConnectResponse(const nsCOMPtr<nsIEventTarget>& aThread, 42 const UDPAddressInfo& aAddressInfo); 43 void DoConnect(const nsCOMPtr<nsIUDPSocket>& aSocket, 44 const nsCOMPtr<nsIEventTarget>& aReturnThread, 45 const UDPAddressInfo& aAddressInfo); 46 47 mozilla::ipc::IPCResult RecvOutgoingData(const UDPData& aData, 48 const UDPSocketAddr& aAddr); 49 50 mozilla::ipc::IPCResult RecvClose(); 51 mozilla::ipc::IPCResult RecvRequestDelete(); 52 mozilla::ipc::IPCResult RecvJoinMulticast(const nsCString& aMulticastAddress, 53 const nsCString& aInterface); 54 mozilla::ipc::IPCResult RecvLeaveMulticast(const nsCString& aMulticastAddress, 55 const nsCString& aInterface); 56 57 private: 58 virtual ~UDPSocketParent(); 59 60 virtual void ActorDestroy(ActorDestroyReason why) override; 61 void Send(const nsTArray<uint8_t>& aData, const UDPSocketAddr& aAddr); 62 void Send(const IPCStream& aStream, const UDPSocketAddr& aAddr); 63 nsresult BindInternal(const nsCString& aHost, const uint16_t& aPort, 64 const bool& aAddressReuse, const bool& aLoopback, 65 const uint32_t& recvBufferSize, 66 const uint32_t& sendBufferSize); 67 nsresult ConnectInternal(const nsCString& aHost, const uint16_t& aPort); 68 void FireInternalError(uint32_t aLineNo); 69 void SendInternalError(const nsCOMPtr<nsIEventTarget>& aThread, 70 uint32_t aLineNo); 71 72 PBackgroundParent* mBackgroundManager; 73 74 bool mIPCOpen; 75 nsCOMPtr<nsIUDPSocket> mSocket; 76 nsCOMPtr<nsISocketFilter> mFilter; 77 nsCOMPtr<nsIPrincipal> mPrincipal; 78 UDPAddressInfo mAddress; 79 }; 80 81 } // namespace dom 82 } // namespace mozilla 83 84 #endif // !defined(mozilla_dom_UDPSocketParent_h__)