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"
24 CreateTransport(ProcessHandle
/*unused*/, ProcessHandle
/*unused*/,
25 TransportDescriptor
* aOne
, TransportDescriptor
* aTwo
)
27 // Gecko doesn't care about this random ID, and the argument to this
28 // function isn't really necessary, it can be just any random
30 wstring id
= ChildProcessInfo::GenerateRandomChannelID(aOne
);
31 // Use MODE_SERVER to force creation of the socketpair
32 Transport
t(id
, Transport::MODE_SERVER
, nullptr);
33 int fd1
= t
.GetFileDescriptor();
35 t
.GetClientFileDescriptorMapping(&fd2
, &dontcare
);
36 if (fd1
< 0 || fd2
< 0) {
40 // The Transport closes these fds when it goes out of scope, so we
44 if (fd1
< 0 || fd2
< 0) {
48 aOne
->mFd
= base::FileDescriptor(fd1
, true/*close after sending*/);
49 aTwo
->mFd
= base::FileDescriptor(fd2
, true/*close after sending*/);
54 OpenDescriptor(const TransportDescriptor
& aTd
, Transport::Mode aMode
)
56 return new Transport(aTd
.mFd
.fd
, aMode
, nullptr);
60 OpenDescriptor(const FileDescriptor
& aFd
, Transport::Mode aMode
)
62 return new Transport(aFd
.PlatformHandle(), aMode
, nullptr);
66 CloseDescriptor(const TransportDescriptor
& aTd
)
72 } // namespace mozilla