mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
882fe73908
--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
147 lines
3.7 KiB
C++
147 lines
3.7 KiB
C++
/* 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/. */
|
|
|
|
#include "TCPServerSocketParent.h"
|
|
#include "nsJSUtils.h"
|
|
#include "TCPSocketParent.h"
|
|
#include "mozilla/unused.h"
|
|
#include "mozilla/AppProcessChecker.h"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
static void
|
|
FireInteralError(mozilla::net::PTCPServerSocketParent* aActor,
|
|
uint32_t aLineNo)
|
|
{
|
|
mozilla::unused <<
|
|
aActor->SendCallbackError(NS_LITERAL_STRING("Internal error"),
|
|
NS_LITERAL_STRING(__FILE__), aLineNo, 0);
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION(TCPServerSocketParent, mServerSocket, mIntermediary)
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketParent)
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketParent)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketParent)
|
|
NS_INTERFACE_MAP_ENTRY(nsITCPServerSocketParent)
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
void
|
|
TCPServerSocketParent::ReleaseIPDLReference()
|
|
{
|
|
MOZ_ASSERT(mIPCOpen);
|
|
mIPCOpen = false;
|
|
this->Release();
|
|
}
|
|
|
|
void
|
|
TCPServerSocketParent::AddIPDLReference()
|
|
{
|
|
MOZ_ASSERT(!mIPCOpen);
|
|
mIPCOpen = true;
|
|
this->AddRef();
|
|
}
|
|
|
|
bool
|
|
TCPServerSocketParent::Init(PNeckoParent* neckoParent, const uint16_t& aLocalPort,
|
|
const uint16_t& aBacklog, const nsString& aBinaryType)
|
|
{
|
|
mNeckoParent = neckoParent;
|
|
|
|
nsresult rv;
|
|
mIntermediary = do_CreateInstance("@mozilla.org/tcp-socket-intermediary;1", &rv);
|
|
if (NS_FAILED(rv)) {
|
|
FireInteralError(this, __LINE__);
|
|
return true;
|
|
}
|
|
|
|
rv = mIntermediary->Listen(this, aLocalPort, aBacklog, aBinaryType, getter_AddRefs(mServerSocket));
|
|
if (NS_FAILED(rv) || !mServerSocket) {
|
|
FireInteralError(this, __LINE__);
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
TCPServerSocketParent::SendCallbackAccept(nsITCPSocketParent *socket)
|
|
{
|
|
TCPSocketParent* _socket = static_cast<TCPSocketParent*>(socket);
|
|
PTCPSocketParent* _psocket = static_cast<PTCPSocketParent*>(_socket);
|
|
|
|
_socket->AddIPDLReference();
|
|
|
|
nsresult rv;
|
|
|
|
nsString host;
|
|
rv = socket->GetHost(host);
|
|
if (NS_FAILED(rv)) {
|
|
NS_ERROR("Failed to get host from nsITCPSocketParent");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
uint16_t port;
|
|
rv = socket->GetPort(&port);
|
|
if (NS_FAILED(rv)) {
|
|
NS_ERROR("Failed to get port from nsITCPSocketParent");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (mNeckoParent) {
|
|
if (mNeckoParent->SendPTCPSocketConstructor(_psocket, host, port)) {
|
|
mozilla::unused << PTCPServerSocketParent::SendCallbackAccept(_psocket);
|
|
}
|
|
else {
|
|
NS_ERROR("Sending data from PTCPSocketParent was failed.");
|
|
};
|
|
}
|
|
else {
|
|
NS_ERROR("The member value for NeckoParent is wrong.");
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
TCPServerSocketParent::SendCallbackError(const nsAString& message,
|
|
const nsAString& filename,
|
|
uint32_t lineNumber,
|
|
uint32_t columnNumber)
|
|
{
|
|
mozilla::unused <<
|
|
PTCPServerSocketParent::SendCallbackError(nsString(message), nsString(filename),
|
|
lineNumber, columnNumber);
|
|
return NS_OK;
|
|
}
|
|
|
|
bool
|
|
TCPServerSocketParent::RecvClose()
|
|
{
|
|
NS_ENSURE_TRUE(mServerSocket, true);
|
|
mServerSocket->Close();
|
|
return true;
|
|
}
|
|
|
|
void
|
|
TCPServerSocketParent::ActorDestroy(ActorDestroyReason why)
|
|
{
|
|
if (mServerSocket) {
|
|
mServerSocket->Close();
|
|
mServerSocket = nullptr;
|
|
}
|
|
mNeckoParent = nullptr;
|
|
mIntermediary = nullptr;
|
|
}
|
|
|
|
bool
|
|
TCPServerSocketParent::RecvRequestDelete()
|
|
{
|
|
mozilla::unused << Send__delete__(this);
|
|
return true;
|
|
}
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|