UDPSocketParent.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  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 file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_UDPSocketParent_h__
  6. #define mozilla_dom_UDPSocketParent_h__
  7. #include "mozilla/net/PUDPSocketParent.h"
  8. #include "nsCOMPtr.h"
  9. #include "nsIUDPSocket.h"
  10. #include "nsISocketFilter.h"
  11. #include "mozilla/dom/PermissionMessageUtils.h"
  12. namespace mozilla {
  13. namespace net {
  14. class PNeckoParent;
  15. } // namespace net
  16. namespace dom {
  17. class UDPSocketParent : public mozilla::net::PUDPSocketParent
  18. , public nsIUDPSocketListener
  19. {
  20. public:
  21. NS_DECL_THREADSAFE_ISUPPORTS
  22. NS_DECL_NSIUDPSOCKETLISTENER
  23. explicit UDPSocketParent(PBackgroundParent* aManager);
  24. explicit UDPSocketParent(PNeckoParent* aManager);
  25. bool Init(const IPC::Principal& aPrincipal, const nsACString& aFilter);
  26. virtual bool RecvBind(const UDPAddressInfo& aAddressInfo,
  27. const bool& aAddressReuse, const bool& aLoopback,
  28. const uint32_t& recvBufferSize,
  29. const uint32_t& sendBufferSize) override;
  30. virtual bool RecvConnect(const UDPAddressInfo& aAddressInfo) override;
  31. void DoSendConnectResponse(const UDPAddressInfo& aAddressInfo);
  32. void SendConnectResponse(nsIEventTarget *aThread,
  33. const UDPAddressInfo& aAddressInfo);
  34. void DoConnect(nsCOMPtr<nsIUDPSocket>& aSocket,
  35. nsCOMPtr<nsIEventTarget>& aReturnThread,
  36. const UDPAddressInfo& aAddressInfo);
  37. virtual bool RecvOutgoingData(const UDPData& aData, const UDPSocketAddr& aAddr) override;
  38. virtual bool RecvClose() override;
  39. virtual bool RecvRequestDelete() override;
  40. virtual bool RecvJoinMulticast(const nsCString& aMulticastAddress,
  41. const nsCString& aInterface) override;
  42. virtual bool RecvLeaveMulticast(const nsCString& aMulticastAddress,
  43. const nsCString& aInterface) override;
  44. private:
  45. virtual ~UDPSocketParent();
  46. virtual void ActorDestroy(ActorDestroyReason why) override;
  47. void Send(const InfallibleTArray<uint8_t>& aData, const UDPSocketAddr& aAddr);
  48. void Send(const InputStreamParams& aStream, const UDPSocketAddr& aAddr);
  49. nsresult BindInternal(const nsCString& aHost, const uint16_t& aPort,
  50. const bool& aAddressReuse, const bool& aLoopback,
  51. const uint32_t& recvBufferSize,
  52. const uint32_t& sendBufferSize);
  53. nsresult ConnectInternal(const nsCString& aHost, const uint16_t& aPort);
  54. void FireInternalError(uint32_t aLineNo);
  55. void SendInternalError(nsIEventTarget *aThread,
  56. uint32_t aLineNo);
  57. // One of these will be null and the other non-null.
  58. PBackgroundParent* mBackgroundManager;
  59. PNeckoParent* mNeckoManager;
  60. bool mIPCOpen;
  61. nsCOMPtr<nsIUDPSocket> mSocket;
  62. nsCOMPtr<nsISocketFilter> mFilter;
  63. nsCOMPtr<nsIPrincipal> mPrincipal;
  64. };
  65. } // namespace dom
  66. } // namespace mozilla
  67. #endif // !defined(mozilla_dom_UDPSocketParent_h__)