diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-24 00:54:31 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-24 00:54:31 +0000 |
commit | d35abeeda0fbe66878d7ae751a560061ee7c6b9c (patch) | |
tree | a283cd5f10ab66f0cf3761bbb502210de3c3a957 /remoting/host/ipc_util_posix.cc | |
parent | 2ce8a162fa7cf3a8544918a028974fbe7880cfef (diff) | |
download | chromium_src-d35abeeda0fbe66878d7ae751a560061ee7c6b9c.zip chromium_src-d35abeeda0fbe66878d7ae751a560061ee7c6b9c.tar.gz chromium_src-d35abeeda0fbe66878d7ae751a560061ee7c6b9c.tar.bz2 |
Make CreateConnectedIpcChannel() a cross-platform API.
CreateConnectedIpcChannel() is used to create a pre-conected IPC channel, the client end of which can be passed to another process. This CL moves this function and related code to dedicated remoting/host/ipc_util.h. It also eliminates platform-specific implementations of DesktopSessionAgent class, since the channel created was the only platform specific code they were implementing.
BUG=225451
Review URL: https://chromiumcodereview.appspot.com/15559004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201947 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/ipc_util_posix.cc')
-rw-r--r-- | remoting/host/ipc_util_posix.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/remoting/host/ipc_util_posix.cc b/remoting/host/ipc_util_posix.cc new file mode 100644 index 0000000..e747a77 --- /dev/null +++ b/remoting/host/ipc_util_posix.cc @@ -0,0 +1,58 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/host/ipc_util.h" + +#include <fcntl.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <unistd.h> + +#include "base/logging.h" +#include "base/posix/eintr_wrapper.h" +#include "base/single_thread_task_runner.h" +#include "ipc/ipc_channel.h" +#include "ipc/ipc_channel_proxy.h" + +namespace remoting { + +bool CreateConnectedIpcChannel( + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, + IPC::Listener* listener, + IPC::PlatformFileForTransit* client_out, + scoped_ptr<IPC::ChannelProxy>* server_out) { + // Create a socket pair. + int pipe_fds[2]; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe_fds) != 0) { + PLOG(ERROR) << "socketpair()"; + return false; + } + + // Set both ends to be non-blocking. + if (fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK) == -1 || + fcntl(pipe_fds[1], F_SETFL, O_NONBLOCK) == -1) { + PLOG(ERROR) << "fcntl(O_NONBLOCK)"; + if (HANDLE_EINTR(close(pipe_fds[0])) < 0) + PLOG(ERROR) << "close()"; + if (HANDLE_EINTR(close(pipe_fds[1])) < 0) + PLOG(ERROR) << "close()"; + return false; + } + + std::string socket_name = "Chromoting socket"; + + // Wrap the pipe into an IPC channel. + base::FileDescriptor fd(pipe_fds[0], false); + IPC::ChannelHandle handle(socket_name, fd); + server_out->reset(new IPC::ChannelProxy( + IPC::ChannelHandle(socket_name, fd), + IPC::Channel::MODE_SERVER, + listener, + io_task_runner)); + + *client_out = base::FileDescriptor(pipe_fds[1], false); + return true; +} + +} // namespace remoting |