1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
12 #include "chrome/common/child_process_info.h"
14 #include "mozilla/ipc/Transport.h"
15 #include "mozilla/ipc/FileDescriptor.h"
19 using base::ProcessHandle
;
25 CreateTransport(ProcessHandle
/*unused*/, ProcessHandle
/*unused*/,
26 TransportDescriptor
* aOne
, TransportDescriptor
* aTwo
)
28 wstring id
= IPC::Channel::GenerateVerifiedChannelID(std::wstring());
29 // Use MODE_SERVER to force creation of the socketpair
30 Transport
t(id
, Transport::MODE_SERVER
, nullptr);
31 int fd1
= t
.GetFileDescriptor();
33 t
.GetClientFileDescriptorMapping(&fd2
, &dontcare
);
34 if (fd1
< 0 || fd2
< 0) {
38 // The Transport closes these fds when it goes out of scope, so we
42 if (fd1
< 0 || fd2
< 0) {
46 aOne
->mFd
= base::FileDescriptor(fd1
, true/*close after sending*/);
47 aTwo
->mFd
= base::FileDescriptor(fd2
, true/*close after sending*/);
52 OpenDescriptor(const TransportDescriptor
& aTd
, Transport::Mode aMode
)
54 return new Transport(aTd
.mFd
.fd
, aMode
, nullptr);
58 OpenDescriptor(const FileDescriptor
& aFd
, Transport::Mode aMode
)
60 return new Transport(aFd
.PlatformHandle(), aMode
, nullptr);
64 CloseDescriptor(const TransportDescriptor
& aTd
)
70 } // namespace mozilla