| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/ipc_util.h" | |
| 6 | |
| 7 #include <fcntl.h> | |
| 8 #include <sys/socket.h> | |
| 9 #include <sys/types.h> | |
| 10 #include <unistd.h> | |
| 11 | |
| 12 #include "base/files/file.h" | |
| 13 #include "base/logging.h" | |
| 14 #include "base/posix/eintr_wrapper.h" | |
| 15 #include "base/single_thread_task_runner.h" | |
| 16 #include "ipc/attachment_broker.h" | |
| 17 #include "ipc/ipc_channel.h" | |
| 18 #include "ipc/ipc_channel_proxy.h" | |
| 19 | |
| 20 namespace remoting { | |
| 21 | |
| 22 bool CreateConnectedIpcChannel( | |
| 23 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | |
| 24 IPC::Listener* listener, | |
| 25 base::File* client_out, | |
| 26 std::unique_ptr<IPC::ChannelProxy>* server_out) { | |
| 27 // Create a socket pair. | |
| 28 int pipe_fds[2]; | |
| 29 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe_fds) != 0) { | |
| 30 PLOG(ERROR) << "socketpair()"; | |
| 31 return false; | |
| 32 } | |
| 33 | |
| 34 // Set both ends to be non-blocking. | |
| 35 if (fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK) == -1 || | |
| 36 fcntl(pipe_fds[1], F_SETFL, O_NONBLOCK) == -1) { | |
| 37 PLOG(ERROR) << "fcntl(O_NONBLOCK)"; | |
| 38 if (IGNORE_EINTR(close(pipe_fds[0])) < 0) | |
| 39 PLOG(ERROR) << "close()"; | |
| 40 if (IGNORE_EINTR(close(pipe_fds[1])) < 0) | |
| 41 PLOG(ERROR) << "close()"; | |
| 42 return false; | |
| 43 } | |
| 44 | |
| 45 std::string socket_name = "Chromoting socket"; | |
| 46 | |
| 47 // Wrap the pipe into an IPC channel. | |
| 48 base::FileDescriptor fd(pipe_fds[0], false); | |
| 49 server_out->reset(new IPC::ChannelProxy(listener, io_task_runner)); | |
| 50 if (IPC::AttachmentBroker::GetGlobal()) { | |
| 51 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | |
| 52 server_out->get(), io_task_runner); | |
| 53 } | |
| 54 (*server_out) | |
| 55 ->Init(IPC::ChannelHandle(socket_name, fd), IPC::Channel::MODE_SERVER, | |
| 56 true); | |
| 57 | |
| 58 *client_out = base::File(pipe_fds[1]); | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 } // namespace remoting | |
| OLD | NEW |