Bug 1061174 - Part 1 - imported patch test_udpsocket-debug.patch. r=khuey

This commit is contained in:
Shih-Chiang Chien 2015-03-09 10:25:20 +08:00
parent 9724ca2e3a
commit 7b1d4f7c79
2 changed files with 45 additions and 2 deletions

View File

@ -20,6 +20,10 @@
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS(UDPSocket::ListenerProxy,
nsIUDPSocketListener,
nsIUDPSocketInternal)
NS_IMPL_CYCLE_COLLECTION_CLASS(UDPSocket)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(UDPSocket, DOMEventTargetHelper)
@ -175,6 +179,11 @@ UDPSocket::CloseWithReason(nsresult aReason)
mReadyState = SocketReadyState::Closed;
if (mListenerProxy) {
mListenerProxy->Disconnect();
mListenerProxy = nullptr;
}
if (mSocket) {
mSocket->Close();
mSocket = nullptr;
@ -430,7 +439,9 @@ UDPSocket::InitLocal(const nsAString& aLocalAddress,
}
mLocalPort.SetValue(localPort);
rv = mSocket->AsyncListen(this);
mListenerProxy = new ListenerProxy(this);
rv = mSocket->AsyncListen(mListenerProxy);
if (NS_FAILED(rv)) {
return rv;
}
@ -458,7 +469,14 @@ UDPSocket::InitRemote(const nsAString& aLocalAddress,
return rv;
}
rv = sock->Bind(this, NS_ConvertUTF16toUTF8(aLocalAddress), aLocalPort, mAddressReuse, mLoopback);
mListenerProxy = new ListenerProxy(this);
rv = sock->Bind(mListenerProxy,
NS_ConvertUTF16toUTF8(aLocalAddress),
aLocalPort,
mAddressReuse,
mLoopback);
if (NS_FAILED(rv)) {
return rv;
}

View File

@ -128,6 +128,30 @@ public:
ErrorResult& aRv);
private:
class ListenerProxy : public nsIUDPSocketListener
, public nsIUDPSocketInternal
{
public:
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIUDPSOCKETLISTENER(mSocket)
NS_FORWARD_SAFE_NSIUDPSOCKETINTERNAL(mSocket)
explicit ListenerProxy(UDPSocket* aSocket)
: mSocket(aSocket)
{
}
void Disconnect()
{
mSocket = nullptr;
}
private:
virtual ~ListenerProxy() {}
UDPSocket* mSocket;
};
UDPSocket(nsPIDOMWindow* aOwner,
const nsCString& aRemoteAddress,
const Nullable<uint16_t>& aRemotePort);
@ -176,6 +200,7 @@ private:
nsCOMPtr<nsIUDPSocket> mSocket;
nsCOMPtr<nsIUDPSocketChild> mSocketChild;
nsRefPtr<ListenerProxy> mListenerProxy;
struct MulticastCommand {
enum CommandType { Join, Leave };