mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
acfc90e91a
--HG-- rename : dom/network/src/Connection.cpp => dom/network/Connection.cpp rename : dom/network/src/Connection.h => dom/network/Connection.h rename : dom/network/src/Constants.h => dom/network/Constants.h rename : dom/network/src/NetUtils.cpp => dom/network/NetUtils.cpp rename : dom/network/src/NetUtils.h => dom/network/NetUtils.h rename : dom/network/src/NetworkStatsDB.jsm => dom/network/NetworkStatsDB.jsm rename : dom/network/src/NetworkStatsManager.js => dom/network/NetworkStatsManager.js rename : dom/network/src/NetworkStatsManager.manifest => dom/network/NetworkStatsManager.manifest rename : dom/network/src/NetworkStatsService.jsm => dom/network/NetworkStatsService.jsm rename : dom/network/src/NetworkStatsServiceProxy.js => dom/network/NetworkStatsServiceProxy.js rename : dom/network/src/NetworkStatsServiceProxy.manifest => dom/network/NetworkStatsServiceProxy.manifest rename : dom/network/src/PTCPServerSocket.ipdl => dom/network/PTCPServerSocket.ipdl rename : dom/network/src/PTCPSocket.ipdl => dom/network/PTCPSocket.ipdl rename : dom/network/src/PUDPSocket.ipdl => dom/network/PUDPSocket.ipdl rename : dom/network/src/TCPServerSocket.js => dom/network/TCPServerSocket.js rename : dom/network/src/TCPServerSocketChild.cpp => dom/network/TCPServerSocketChild.cpp rename : dom/network/src/TCPServerSocketChild.h => dom/network/TCPServerSocketChild.h rename : dom/network/src/TCPServerSocketParent.cpp => dom/network/TCPServerSocketParent.cpp rename : dom/network/src/TCPServerSocketParent.h => dom/network/TCPServerSocketParent.h rename : dom/network/src/TCPSocket.js => dom/network/TCPSocket.js rename : dom/network/src/TCPSocket.manifest => dom/network/TCPSocket.manifest rename : dom/network/src/TCPSocketChild.cpp => dom/network/TCPSocketChild.cpp rename : dom/network/src/TCPSocketChild.h => dom/network/TCPSocketChild.h rename : dom/network/src/TCPSocketParent.cpp => dom/network/TCPSocketParent.cpp rename : dom/network/src/TCPSocketParent.h => dom/network/TCPSocketParent.h rename : dom/network/src/TCPSocketParentIntermediary.js => dom/network/TCPSocketParentIntermediary.js rename : dom/network/src/Types.h => dom/network/Types.h rename : dom/network/src/UDPSocket.cpp => dom/network/UDPSocket.cpp rename : dom/network/src/UDPSocket.h => dom/network/UDPSocket.h rename : dom/network/src/UDPSocketChild.cpp => dom/network/UDPSocketChild.cpp rename : dom/network/src/UDPSocketChild.h => dom/network/UDPSocketChild.h rename : dom/network/src/UDPSocketParent.cpp => dom/network/UDPSocketParent.cpp rename : dom/network/src/UDPSocketParent.h => dom/network/UDPSocketParent.h
198 lines
4.4 KiB
C++
198 lines
4.4 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef mozilla_dom_UDPSocket_h__
|
|
#define mozilla_dom_UDPSocket_h__
|
|
|
|
#include "mozilla/Attributes.h"
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
#include "mozilla/ErrorResult.h"
|
|
#include "mozilla/dom/Promise.h"
|
|
#include "mozilla/dom/SocketCommonBinding.h"
|
|
#include "nsIUDPSocket.h"
|
|
#include "nsIUDPSocketChild.h"
|
|
#include "nsTArray.h"
|
|
|
|
struct JSContext;
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
struct UDPOptions;
|
|
class StringOrBlobOrArrayBufferOrArrayBufferView;
|
|
|
|
class UDPSocket MOZ_FINAL : public DOMEventTargetHelper
|
|
, public nsIUDPSocketListener
|
|
, public nsIUDPSocketInternal
|
|
{
|
|
public:
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UDPSocket, DOMEventTargetHelper)
|
|
NS_DECL_NSIUDPSOCKETLISTENER
|
|
NS_DECL_NSIUDPSOCKETINTERNAL
|
|
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
|
|
|
|
public:
|
|
nsPIDOMWindow*
|
|
GetParentObject() const
|
|
{
|
|
return GetOwner();
|
|
}
|
|
|
|
virtual JSObject*
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
|
|
|
virtual void
|
|
DisconnectFromOwner() MOZ_OVERRIDE;
|
|
|
|
static already_AddRefed<UDPSocket>
|
|
Constructor(const GlobalObject& aGlobal, const UDPOptions& aOptions, ErrorResult& aRv);
|
|
|
|
void
|
|
GetLocalAddress(nsString& aRetVal) const
|
|
{
|
|
aRetVal = mLocalAddress;
|
|
}
|
|
|
|
Nullable<uint16_t>
|
|
GetLocalPort() const
|
|
{
|
|
return mLocalPort;
|
|
}
|
|
|
|
void
|
|
GetRemoteAddress(nsString& aRetVal) const
|
|
{
|
|
if (mRemoteAddress.IsVoid()) {
|
|
SetDOMStringToNull(aRetVal);
|
|
return;
|
|
}
|
|
|
|
aRetVal = NS_ConvertUTF8toUTF16(mRemoteAddress);
|
|
}
|
|
|
|
Nullable<uint16_t>
|
|
GetRemotePort() const
|
|
{
|
|
return mRemotePort;
|
|
}
|
|
|
|
bool
|
|
AddressReuse() const
|
|
{
|
|
return mAddressReuse;
|
|
}
|
|
|
|
bool
|
|
Loopback() const
|
|
{
|
|
return mLoopback;
|
|
}
|
|
|
|
SocketReadyState
|
|
ReadyState() const
|
|
{
|
|
return mReadyState;
|
|
}
|
|
|
|
Promise*
|
|
Opened() const
|
|
{
|
|
return mOpened;
|
|
}
|
|
|
|
Promise*
|
|
Closed() const
|
|
{
|
|
return mClosed;
|
|
}
|
|
|
|
IMPL_EVENT_HANDLER(message)
|
|
|
|
already_AddRefed<Promise>
|
|
Close();
|
|
|
|
void
|
|
JoinMulticastGroup(const nsAString& aMulticastGroupAddress, ErrorResult& aRv);
|
|
|
|
void
|
|
LeaveMulticastGroup(const nsAString& aMulticastGroupAddress, ErrorResult& aRv);
|
|
|
|
bool
|
|
Send(const StringOrBlobOrArrayBufferOrArrayBufferView& aData,
|
|
const Optional<nsAString>& aRemoteAddress,
|
|
const Optional<Nullable<uint16_t>>& aRemotePort,
|
|
ErrorResult& aRv);
|
|
|
|
private:
|
|
UDPSocket(nsPIDOMWindow* aOwner,
|
|
const nsCString& aRemoteAddress,
|
|
const Nullable<uint16_t>& aRemotePort);
|
|
|
|
virtual ~UDPSocket();
|
|
|
|
nsresult
|
|
Init(const nsString& aLocalAddress,
|
|
const Nullable<uint16_t>& aLocalPort,
|
|
const bool& aAddressReuse,
|
|
const bool& aLoopback);
|
|
|
|
nsresult
|
|
InitLocal(const nsAString& aLocalAddress, const uint16_t& aLocalPort);
|
|
|
|
nsresult
|
|
InitRemote(const nsAString& aLocalAddress, const uint16_t& aLocalPort);
|
|
|
|
void
|
|
HandleReceivedData(const nsACString& aRemoteAddress,
|
|
const uint16_t& aRemotePort,
|
|
const uint8_t* aData,
|
|
const uint32_t& aDataLength);
|
|
|
|
nsresult
|
|
DispatchReceivedData(const nsACString& aRemoteAddress,
|
|
const uint16_t& aRemotePort,
|
|
const uint8_t* aData,
|
|
const uint32_t& aDataLength);
|
|
|
|
void
|
|
CloseWithReason(nsresult aReason);
|
|
|
|
nsresult
|
|
DoPendingMcastCommand();
|
|
|
|
nsString mLocalAddress;
|
|
Nullable<uint16_t> mLocalPort;
|
|
nsCString mRemoteAddress;
|
|
Nullable<uint16_t> mRemotePort;
|
|
bool mAddressReuse;
|
|
bool mLoopback;
|
|
SocketReadyState mReadyState;
|
|
nsRefPtr<Promise> mOpened;
|
|
nsRefPtr<Promise> mClosed;
|
|
|
|
nsCOMPtr<nsIUDPSocket> mSocket;
|
|
nsCOMPtr<nsIUDPSocketChild> mSocketChild;
|
|
|
|
struct MulticastCommand {
|
|
enum CommandType { Join, Leave };
|
|
|
|
MulticastCommand(CommandType aCommand, const nsAString& aAddress)
|
|
: mCommand(aCommand), mAddress(aAddress)
|
|
{ }
|
|
|
|
CommandType mCommand;
|
|
nsString mAddress;
|
|
};
|
|
|
|
nsTArray<MulticastCommand> mPendingMcastCommands;
|
|
};
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|
|
|
|
#endif // mozilla_dom_UDPSocket_h__
|