mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 937528 - Initialize port and host for the tcp server accepted socket. r=jduell
This commit is contained in:
parent
c498cbdf36
commit
f325cee3b5
@ -9,7 +9,7 @@ interface nsIDOMWindow;
|
||||
|
||||
// Interface to allow the content process socket to reach the IPC bridge.
|
||||
// Implemented in C++ as TCPSocketChild, referenced as _socketBridge in TCPSocket.js
|
||||
[scriptable, uuid(292ebb3a-beac-4e06-88b0-b5b4e88ebd1c)]
|
||||
[scriptable, uuid(4277aff0-4c33-11e3-8f96-0800200c9a66)]
|
||||
interface nsITCPSocketChild : nsISupports
|
||||
{
|
||||
// Tell the chrome process to open a corresponding connection with the given parameters
|
||||
@ -44,4 +44,7 @@ interface nsITCPSocketChild : nsISupports
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
void setSocketAndWindow(in nsITCPSocketInternal socket, in jsval windowVal);
|
||||
|
||||
readonly attribute DOMString host;
|
||||
readonly attribute unsigned short port;
|
||||
};
|
||||
|
@ -12,7 +12,7 @@ interface nsITCPSocketIntermediary;
|
||||
// Interface required to allow the TCP socket object (TCPSocket.js) in the
|
||||
// parent process to talk to the parent IPC actor, TCPSocketParent, which
|
||||
// is written in C++.
|
||||
[scriptable, uuid(868662a4-681c-4b89-9f02-6fe5b7ace265)]
|
||||
[scriptable, uuid(6f040bf0-6852-11e3-949a-0800200c9a66)]
|
||||
interface nsITCPSocketParent : nsISupports
|
||||
{
|
||||
[implicit_jscontext] void initJS(in jsval intermediary);
|
||||
@ -55,6 +55,9 @@ interface nsITCPSocketParent : nsISupports
|
||||
// to make sure the bufferedAmount updated on the child will correspond
|
||||
// to the latest call of send().
|
||||
void sendUpdateBufferedAmount(in uint32_t bufferedAmount, in uint32_t trackingNumber);
|
||||
|
||||
readonly attribute DOMString host;
|
||||
readonly attribute unsigned short port;
|
||||
};
|
||||
|
||||
// Intermediate class to handle sending multiple possible data types
|
||||
|
@ -74,8 +74,24 @@ TCPServerSocketParent::SendCallbackAccept(nsITCPSocketParent *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)) {
|
||||
if (mNeckoParent->SendPTCPSocketConstructor(_psocket, host, port)) {
|
||||
mozilla::unused << PTCPServerSocketParent::SendCallbackAccept(_psocket);
|
||||
}
|
||||
else {
|
||||
|
@ -437,6 +437,10 @@ TCPSocket.prototype = {
|
||||
that._inputStreamPump = new InputStreamPump(that._socketInputStream, -1, -1, 0, 0, false);
|
||||
that._inputStreamPump.asyncRead(that, null);
|
||||
|
||||
// Grab host/port from SocketTransport.
|
||||
that._host = transport.host;
|
||||
that._port = transport.port;
|
||||
|
||||
return that;
|
||||
},
|
||||
|
||||
@ -448,6 +452,8 @@ TCPSocket.prototype = {
|
||||
that._readyState = kOPEN;
|
||||
socketChild.setSocketAndWindow(that, windowObject);
|
||||
that._socketBridge = socketChild;
|
||||
that._host = socketChild.host;
|
||||
that._port = socketChild.port;
|
||||
|
||||
return that;
|
||||
},
|
||||
|
@ -73,9 +73,16 @@ NS_IMETHODIMP_(MozExternalRefCountType) TCPSocketChild::Release(void)
|
||||
|
||||
TCPSocketChild::TCPSocketChild()
|
||||
: mWindowObj(nullptr)
|
||||
, mHost()
|
||||
, mPort(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TCPSocketChild::Init(const nsString& aHost, const uint16_t& aPort) {
|
||||
mHost = aHost;
|
||||
mPort = aPort;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TCPSocketChild::SendOpen(nsITCPSocketInternal* aSocket,
|
||||
const nsAString& aHost, uint16_t aPort,
|
||||
@ -91,7 +98,7 @@ TCPSocketChild::SendOpen(nsITCPSocketInternal* aSocket,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
AddIPDLReference();
|
||||
gNeckoChild->SendPTCPSocketConstructor(this);
|
||||
gNeckoChild->SendPTCPSocketConstructor(this, nsString(aHost), aPort);
|
||||
PTCPSocketChild::SendOpen(nsString(aHost), aPort,
|
||||
aUseSSL, nsString(aBinaryType));
|
||||
return NS_OK;
|
||||
@ -246,6 +253,20 @@ TCPSocketChild::SetSocketAndWindow(nsITCPSocketInternal *aSocket,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TCPSocketChild::GetHost(nsAString& aHost)
|
||||
{
|
||||
aHost = mHost;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TCPSocketChild::GetPort(uint16_t* aPort)
|
||||
{
|
||||
*aPort = mPort;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
TCPSocketChild::RecvRequestDelete()
|
||||
{
|
||||
|
@ -45,6 +45,8 @@ public:
|
||||
TCPSocketChild();
|
||||
~TCPSocketChild();
|
||||
|
||||
void Init(const nsString& aHost, const uint16_t& aPort);
|
||||
|
||||
virtual bool RecvCallback(const nsString& aType,
|
||||
const CallbackData& aData,
|
||||
const nsString& aReadyState) MOZ_OVERRIDE;
|
||||
@ -53,6 +55,8 @@ public:
|
||||
const uint32_t& aTrackingNumber) MOZ_OVERRIDE;
|
||||
private:
|
||||
JSObject* mWindowObj;
|
||||
nsString mHost;
|
||||
uint16_t mPort;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -278,6 +278,26 @@ TCPSocketParent::SendUpdateBufferedAmount(uint32_t aBufferedAmount,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TCPSocketParent::GetHost(nsAString& aHost)
|
||||
{
|
||||
if (!mSocket) {
|
||||
NS_ERROR("No internal socket instance mSocket!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return mSocket->GetHost(aHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TCPSocketParent::GetPort(uint16_t* aPort)
|
||||
{
|
||||
if (!mSocket) {
|
||||
NS_ERROR("No internal socket instance mSocket!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return mSocket->GetPort(aPort);
|
||||
}
|
||||
|
||||
void
|
||||
TCPSocketParent::ActorDestroy(ActorDestroyReason why)
|
||||
{
|
||||
|
@ -174,6 +174,14 @@ function connectSock() {
|
||||
|
||||
server = TCPSocket.listen(PORT, options, BACKLOG);
|
||||
server.onconnect = function(socket) {
|
||||
// Bug 937528 - Accepted client tcp socket (mozTcpSocket) has
|
||||
// uninitialized host and port.
|
||||
if (socket.host !== '127.0.0.1') {
|
||||
do_throw('got unexpected: connected socket host should be 127.0.0.1 but not ' + socket.host);
|
||||
} else {
|
||||
do_print('Got expected connected socket host: ' + socket.host);
|
||||
}
|
||||
|
||||
connectedsock = socket;
|
||||
connectedsock.ondata = makeFailureCase('serverdata');
|
||||
connectedsock.onerror = makeFailureCase('servererror');
|
||||
@ -187,7 +195,7 @@ function connectSock() {
|
||||
sock.ondrain = null;
|
||||
sock.ondata = makeFailureCase('data');
|
||||
sock.onerror = makeFailureCase('error');
|
||||
sock.onclose = makeFailureCase('close');
|
||||
sock.onclose = makeFailureCase('close');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,7 +205,7 @@ function connectSock() {
|
||||
function openSockInClosingServer() {
|
||||
var success = makeSuccessCase('clientnotopen');
|
||||
var options = { binaryType: 'arraybuffer' };
|
||||
|
||||
|
||||
sock = TCPSocket.open(
|
||||
'127.0.0.1', PORT, options);
|
||||
|
||||
|
@ -201,9 +201,11 @@ NeckoChild::DeallocPRtspChannelChild(PRtspChannelChild* child)
|
||||
}
|
||||
|
||||
PTCPSocketChild*
|
||||
NeckoChild::AllocPTCPSocketChild()
|
||||
NeckoChild::AllocPTCPSocketChild(const nsString& host,
|
||||
const uint16_t& port)
|
||||
{
|
||||
TCPSocketChild* p = new TCPSocketChild();
|
||||
p->Init(host, port);
|
||||
p->AddIPDLReference();
|
||||
return p;
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ protected:
|
||||
AllocPWebSocketChild(const PBrowserOrId&,
|
||||
const SerializedLoadContext&) MOZ_OVERRIDE;
|
||||
virtual bool DeallocPWebSocketChild(PWebSocketChild*) MOZ_OVERRIDE;
|
||||
virtual PTCPSocketChild* AllocPTCPSocketChild() MOZ_OVERRIDE;
|
||||
virtual PTCPSocketChild* AllocPTCPSocketChild(const nsString& host,
|
||||
const uint16_t& port) MOZ_OVERRIDE;
|
||||
virtual bool DeallocPTCPSocketChild(PTCPSocketChild*) MOZ_OVERRIDE;
|
||||
virtual PTCPServerSocketChild*
|
||||
AllocPTCPServerSocketChild(const uint16_t& aLocalPort,
|
||||
|
@ -397,8 +397,12 @@ NeckoParent::DeallocPRtspChannelParent(PRtspChannelParent* actor)
|
||||
}
|
||||
|
||||
PTCPSocketParent*
|
||||
NeckoParent::AllocPTCPSocketParent()
|
||||
NeckoParent::AllocPTCPSocketParent(const nsString& /* host */,
|
||||
const uint16_t& /* port */)
|
||||
{
|
||||
// We actually don't need host/port to construct a TCPSocketParent since
|
||||
// TCPSocketParent will maintain an internal nsIDOMTCPSocket instance which
|
||||
// can be delegated to get the host/port.
|
||||
TCPSocketParent* p = new TCPSocketParent();
|
||||
p->AddIPDLReference();
|
||||
return p;
|
||||
|
@ -127,7 +127,8 @@ protected:
|
||||
AllocPWebSocketParent(const PBrowserOrId& browser,
|
||||
const SerializedLoadContext& aSerialized) MOZ_OVERRIDE;
|
||||
virtual bool DeallocPWebSocketParent(PWebSocketParent*) MOZ_OVERRIDE;
|
||||
virtual PTCPSocketParent* AllocPTCPSocketParent() MOZ_OVERRIDE;
|
||||
virtual PTCPSocketParent* AllocPTCPSocketParent(const nsString& host,
|
||||
const uint16_t& port) MOZ_OVERRIDE;
|
||||
|
||||
virtual PRemoteOpenFileParent*
|
||||
AllocPRemoteOpenFileParent(const SerializedLoadContext& aSerialized,
|
||||
|
@ -102,7 +102,10 @@ child:
|
||||
nsString realm, uint64_t callbackId);
|
||||
|
||||
both:
|
||||
PTCPSocket();
|
||||
// Actually we need PTCPSocket() for parent. But ipdl disallows us having different
|
||||
// signatures on parent and child. So when constructing the parent side object, we just
|
||||
// leave host/port unused.
|
||||
PTCPSocket(nsString host, uint16_t port);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user