2011-06-03 22:33:56 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2011-06-03 22:33:56 +04:00
|
|
|
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "chrome/common/child_process_info.h"
|
|
|
|
|
|
|
|
#include "mozilla/ipc/Transport.h"
|
2015-04-01 11:40:35 +03:00
|
|
|
#include "mozilla/ipc/ProtocolUtils.h"
|
2011-06-03 22:33:56 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2015-02-11 23:01:26 +03:00
|
|
|
using base::ProcessHandle;
|
|
|
|
|
2011-06-03 22:33:56 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
2015-07-10 03:07:49 +03:00
|
|
|
nsresult
|
2015-04-01 11:40:35 +03:00
|
|
|
CreateTransport(base::ProcessId aProcIdOne,
|
2015-07-10 03:07:49 +03:00
|
|
|
TransportDescriptor* aOne,
|
|
|
|
TransportDescriptor* aTwo)
|
2011-06-03 22:33:56 +04:00
|
|
|
{
|
2015-04-23 13:09:04 +03:00
|
|
|
wstring id = IPC::Channel::GenerateVerifiedChannelID(std::wstring());
|
2011-06-03 22:33:56 +04:00
|
|
|
// Use MODE_SERVER to force creation of the pipe
|
2012-07-30 18:20:58 +04:00
|
|
|
Transport t(id, Transport::MODE_SERVER, nullptr);
|
2011-06-03 22:33:56 +04:00
|
|
|
HANDLE serverPipe = t.GetServerPipeHandle();
|
|
|
|
if (!serverPipe) {
|
2015-07-10 03:07:49 +03:00
|
|
|
return NS_ERROR_TRANSPORT_INIT;
|
2011-06-03 22:33:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NB: we create the server pipe immediately, instead of just
|
|
|
|
// grabbing an ID, on purpose. In the current setup, the client
|
|
|
|
// needs to connect to an existing server pipe, so to prevent race
|
|
|
|
// conditions, we create the server side here and then dup it to the
|
|
|
|
// eventual server process.
|
|
|
|
HANDLE serverDup;
|
|
|
|
DWORD access = 0;
|
|
|
|
DWORD options = DUPLICATE_SAME_ACCESS;
|
2015-04-01 11:40:35 +03:00
|
|
|
if (!DuplicateHandle(serverPipe, aProcIdOne, &serverDup, access, options)) {
|
2015-07-10 03:07:49 +03:00
|
|
|
return NS_ERROR_DUPLICATE_HANDLE;
|
2011-06-03 22:33:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
aOne->mPipeName = aTwo->mPipeName = id;
|
|
|
|
aOne->mServerPipe = serverDup;
|
2013-11-27 11:59:41 +04:00
|
|
|
aTwo->mServerPipe = INVALID_HANDLE_VALUE;
|
2015-07-10 03:07:49 +03:00
|
|
|
return NS_OK;
|
2011-06-03 22:33:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Transport*
|
|
|
|
OpenDescriptor(const TransportDescriptor& aTd, Transport::Mode aMode)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return new Transport(aTd.mPipeName, aTd.mServerPipe, aMode, nullptr);
|
2011-06-03 22:33:56 +04:00
|
|
|
}
|
|
|
|
|
2013-06-03 14:14:37 +04:00
|
|
|
Transport*
|
|
|
|
OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Not implemented!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2011-06-03 22:33:56 +04:00
|
|
|
void
|
|
|
|
CloseDescriptor(const TransportDescriptor& aTd)
|
|
|
|
{
|
|
|
|
CloseHandle(aTd.mServerPipe);
|
|
|
|
}
|
|
|
|
|
2011-06-03 22:33:56 +04:00
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|