UDPSocketChild.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_UDPSocketChild_h__
  6. #define mozilla_dom_UDPSocketChild_h__
  7. #include "mozilla/net/PUDPSocketChild.h"
  8. #include "nsIUDPSocketChild.h"
  9. #include "nsCycleCollectionParticipant.h"
  10. #include "nsCOMPtr.h"
  11. #define UDPSOCKETCHILD_CID \
  12. {0xb47e5a0f, 0xd384, 0x48ef, { 0x88, 0x85, 0x42, 0x59, 0x79, 0x3d, 0x9c, 0xf0 }}
  13. namespace mozilla {
  14. namespace dom {
  15. class UDPSocketChildBase : public nsIUDPSocketChild {
  16. public:
  17. NS_DECL_ISUPPORTS
  18. void AddIPDLReference();
  19. void ReleaseIPDLReference();
  20. protected:
  21. UDPSocketChildBase();
  22. virtual ~UDPSocketChildBase();
  23. nsCOMPtr<nsIUDPSocketInternal> mSocket;
  24. bool mIPCOpen;
  25. };
  26. class UDPSocketChild : public mozilla::net::PUDPSocketChild
  27. , public UDPSocketChildBase
  28. {
  29. public:
  30. NS_DECL_NSIUDPSOCKETCHILD
  31. NS_IMETHOD_(MozExternalRefCountType) Release() override;
  32. UDPSocketChild();
  33. virtual ~UDPSocketChild();
  34. nsresult CreatePBackgroundSpinUntilDone();
  35. virtual bool RecvCallbackOpened(const UDPAddressInfo& aAddressInfo) override;
  36. virtual bool RecvCallbackConnected(const UDPAddressInfo& aAddressInfo) override;
  37. virtual bool RecvCallbackClosed() override;
  38. virtual bool RecvCallbackReceivedData(const UDPAddressInfo& aAddressInfo,
  39. InfallibleTArray<uint8_t>&& aData) override;
  40. virtual bool RecvCallbackError(const nsCString& aMessage,
  41. const nsCString& aFilename,
  42. const uint32_t& aLineNumber) override;
  43. private:
  44. nsresult SendDataInternal(const UDPSocketAddr& aAddr,
  45. const uint8_t* aData,
  46. const uint32_t aByteLength);
  47. mozilla::ipc::PBackgroundChild* mBackgroundManager;
  48. uint16_t mLocalPort;
  49. nsCString mLocalAddress;
  50. nsCString mFilterName;
  51. };
  52. } // namespace dom
  53. } // namespace mozilla
  54. #endif // !defined(mozilla_dom_UDPSocketChild_h__)