Bumping manifests a=b2g-bump
[gecko.git] / ipc / glue / Transport_posix.cpp
blob6f41c2057a4da6940dbafad273722dee42648677
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=8 et :
3 */
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/. */
8 #include <unistd.h>
10 #include <string>
12 #include "chrome/common/child_process_info.h"
14 #include "mozilla/ipc/Transport.h"
15 #include "mozilla/ipc/FileDescriptor.h"
17 using namespace base;
18 using namespace std;
20 namespace mozilla {
21 namespace ipc {
23 bool
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
29 // pointer value
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();
34 int fd2, dontcare;
35 t.GetClientFileDescriptorMapping(&fd2, &dontcare);
36 if (fd1 < 0 || fd2 < 0) {
37 return false;
40 // The Transport closes these fds when it goes out of scope, so we
41 // dup them here
42 fd1 = dup(fd1);
43 fd2 = dup(fd2);
44 if (fd1 < 0 || fd2 < 0) {
45 return false;
48 aOne->mFd = base::FileDescriptor(fd1, true/*close after sending*/);
49 aTwo->mFd = base::FileDescriptor(fd2, true/*close after sending*/);
50 return true;
53 Transport*
54 OpenDescriptor(const TransportDescriptor& aTd, Transport::Mode aMode)
56 return new Transport(aTd.mFd.fd, aMode, nullptr);
59 Transport*
60 OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode)
62 return new Transport(aFd.PlatformHandle(), aMode, nullptr);
65 void
66 CloseDescriptor(const TransportDescriptor& aTd)
68 close(aTd.mFd.fd);
71 } // namespace ipc
72 } // namespace mozilla