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/. */
7 #ifndef mozilla_dom_UDPSocketChild_h__
8 #define mozilla_dom_UDPSocketChild_h__
10 #include "mozilla/net/PUDPSocketChild.h"
11 #include "nsCycleCollectionParticipant.h"
14 #define UDPSOCKETCHILD_CID \
16 0xb47e5a0f, 0xd384, 0x48ef, { \
17 0x88, 0x85, 0x42, 0x59, 0x79, 0x3d, 0x9c, 0xf0 \
23 class nsIUDPSocketInternal
;
25 namespace mozilla::dom
{
27 class UDPSocketChildBase
: public nsISupports
{
31 void AddIPDLReference();
32 void ReleaseIPDLReference();
36 virtual ~UDPSocketChildBase();
37 nsCOMPtr
<nsIUDPSocketInternal
> mSocket
;
41 class UDPSocketChild
: public mozilla::net::PUDPSocketChild
,
42 public UDPSocketChildBase
{
44 NS_IMETHOD_(MozExternalRefCountType
) Release() override
;
47 virtual ~UDPSocketChild();
49 uint16_t LocalPort() const { return mLocalPort
; }
50 // Local address as UTF-8.
51 const nsACString
& LocalAddress() const { return mLocalAddress
; }
53 nsresult
SetFilterName(const nsACString
& aFilterName
);
55 // Allow hosting this over PBackground instead of PNecko
56 nsresult
SetBackgroundSpinsEvents();
58 // Tell the chrome process to bind the UDP socket to a given local host and
60 nsresult
Bind(nsIUDPSocketInternal
* aSocket
, nsIPrincipal
* aPrincipal
,
61 const nsACString
& aHost
, uint16_t aPort
, bool aAddressReuse
,
62 bool aLoopback
, uint32_t recvBufferSize
,
63 uint32_t sendBufferSize
);
65 // Tell the chrome process to connect the UDP socket to a given remote host
67 void Connect(nsIUDPSocketInternal
* aSocket
, const nsACString
& aHost
,
70 // Send the given data to the given address.
71 nsresult
SendWithAddress(const NetAddr
* aAddr
, const uint8_t* aData
,
72 uint32_t aByteLength
);
74 // Send input stream. This must be a buffered stream implementation.
75 nsresult
SendBinaryStream(const nsACString
& aHost
, uint16_t aPort
,
76 nsIInputStream
* aStream
);
80 // Address and interface are both UTF-8.
81 void JoinMulticast(const nsACString
& aMulticastAddress
,
82 const nsACString
& aInterface
);
83 void LeaveMulticast(const nsACString
& aMulticastAddress
,
84 const nsACString
& aInterface
);
86 mozilla::ipc::IPCResult
RecvCallbackOpened(
87 const UDPAddressInfo
& aAddressInfo
);
88 mozilla::ipc::IPCResult
RecvCallbackConnected(
89 const UDPAddressInfo
& aAddressInfo
);
90 mozilla::ipc::IPCResult
RecvCallbackClosed();
91 mozilla::ipc::IPCResult
RecvCallbackReceivedData(
92 const UDPAddressInfo
& aAddressInfo
, nsTArray
<uint8_t>&& aData
);
93 mozilla::ipc::IPCResult
RecvCallbackError(const nsCString
& aMessage
,
94 const nsCString
& aFilename
,
95 const uint32_t& aLineNumber
);
98 nsresult
SendDataInternal(const UDPSocketAddr
& aAddr
, const uint8_t* aData
,
99 const uint32_t aByteLength
);
101 mozilla::ipc::PBackgroundChild
* mBackgroundManager
;
103 nsCString mLocalAddress
;
104 nsCString mFilterName
;
107 } // namespace mozilla::dom
109 #endif // !defined(mozilla_dom_UDPSocketChild_h__)