Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(979)

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 883093003: IPC::Message Refactoring: Move POSIX specific bits to PlatformFileAttachment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ipc/ipc_channel_posix.h" 5 #include "ipc/ipc_channel_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 24 matching lines...) Expand all
35 #include "base/process/process_handle.h" 35 #include "base/process/process_handle.h"
36 #include "base/rand_util.h" 36 #include "base/rand_util.h"
37 #include "base/stl_util.h" 37 #include "base/stl_util.h"
38 #include "base/strings/string_util.h" 38 #include "base/strings/string_util.h"
39 #include "base/synchronization/lock.h" 39 #include "base/synchronization/lock.h"
40 #include "ipc/ipc_descriptors.h" 40 #include "ipc/ipc_descriptors.h"
41 #include "ipc/ipc_listener.h" 41 #include "ipc/ipc_listener.h"
42 #include "ipc/ipc_logging.h" 42 #include "ipc/ipc_logging.h"
43 #include "ipc/ipc_message_attachment_set.h" 43 #include "ipc/ipc_message_attachment_set.h"
44 #include "ipc/ipc_message_utils.h" 44 #include "ipc/ipc_message_utils.h"
45 #include "ipc/ipc_platform_file_attachment.h"
45 #include "ipc/ipc_switches.h" 46 #include "ipc/ipc_switches.h"
46 #include "ipc/unix_domain_socket_util.h" 47 #include "ipc/unix_domain_socket_util.h"
47 48
48 namespace IPC { 49 namespace IPC {
49 50
50 // IPC channels on Windows use named pipes (CreateNamedPipe()) with 51 // IPC channels on Windows use named pipes (CreateNamedPipe()) with
51 // channel ids as the pipe names. Channels on POSIX use sockets as 52 // channel ids as the pipe names. Channels on POSIX use sockets as
52 // pipes These don't quite line up. 53 // pipes These don't quite line up.
53 // 54 //
54 // When creating a child subprocess we use a socket pair and the parent side of 55 // When creating a child subprocess we use a socket pair and the parent side of
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 // Create the Hello message 787 // Create the Hello message
787 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, 788 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE,
788 HELLO_MESSAGE_TYPE, 789 HELLO_MESSAGE_TYPE,
789 IPC::Message::PRIORITY_NORMAL)); 790 IPC::Message::PRIORITY_NORMAL));
790 if (!msg->WriteInt(GetHelloMessageProcId())) { 791 if (!msg->WriteInt(GetHelloMessageProcId())) {
791 NOTREACHED() << "Unable to pickle hello message proc id"; 792 NOTREACHED() << "Unable to pickle hello message proc id";
792 } 793 }
793 #if defined(IPC_USES_READWRITE) 794 #if defined(IPC_USES_READWRITE)
794 scoped_ptr<Message> hello; 795 scoped_ptr<Message> hello;
795 if (remote_fd_pipe_.is_valid()) { 796 if (remote_fd_pipe_.is_valid()) {
796 if (!msg->WriteBorrowingFile(remote_fd_pipe_.get())) { 797 if (!msg->WriteAttachment(
798 new internal::PlatformFileAttachment(remote_fd_pipe_.get()))) {
797 NOTREACHED() << "Unable to pickle hello message file descriptors"; 799 NOTREACHED() << "Unable to pickle hello message file descriptors";
798 } 800 }
799 DCHECK_EQ(msg->attachment_set()->size(), 1U); 801 DCHECK_EQ(msg->attachment_set()->size(), 1U);
800 } 802 }
801 #endif // IPC_USES_READWRITE 803 #endif // IPC_USES_READWRITE
802 output_queue_.push(msg.release()); 804 output_queue_.push(msg.release());
803 } 805 }
804 806
805 ChannelPosix::ReadState ChannelPosix::ReadData( 807 ChannelPosix::ReadState ChannelPosix::ReadData(
806 char* buffer, 808 char* buffer,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 int pid; 1009 int pid;
1008 if (!iter.ReadInt(&pid)) 1010 if (!iter.ReadInt(&pid))
1009 NOTREACHED(); 1011 NOTREACHED();
1010 1012
1011 #if defined(IPC_USES_READWRITE) 1013 #if defined(IPC_USES_READWRITE)
1012 if (mode_ & MODE_SERVER_FLAG) { 1014 if (mode_ & MODE_SERVER_FLAG) {
1013 // With IPC_USES_READWRITE, the Hello message from the client to the 1015 // With IPC_USES_READWRITE, the Hello message from the client to the
1014 // server also contains the fd_pipe_, which will be used for all 1016 // server also contains the fd_pipe_, which will be used for all
1015 // subsequent file descriptor passing. 1017 // subsequent file descriptor passing.
1016 DCHECK_EQ(msg.attachment_set()->size(), 1U); 1018 DCHECK_EQ(msg.attachment_set()->size(), 1U);
1017 base::ScopedFD descriptor; 1019 scoped_refptr<MessageAttachment> attachment;
1018 if (!msg.ReadFile(&iter, &descriptor)) { 1020 if (!msg.ReadAttachment(&iter, &attachment)) {
1019 NOTREACHED(); 1021 NOTREACHED();
1020 } 1022 }
1021 fd_pipe_.reset(descriptor.release()); 1023 fd_pipe_.reset(attachment->TakePlatformFile());
1022 } 1024 }
1023 #endif // IPC_USES_READWRITE 1025 #endif // IPC_USES_READWRITE
1024 peer_pid_ = pid; 1026 peer_pid_ = pid;
1025 listener()->OnChannelConnected(pid); 1027 listener()->OnChannelConnected(pid);
1026 break; 1028 break;
1027 1029
1028 #if defined(OS_MACOSX) 1030 #if defined(OS_MACOSX)
1029 case Channel::CLOSE_FD_MESSAGE_TYPE: 1031 case Channel::CLOSE_FD_MESSAGE_TYPE:
1030 int fd, hops; 1032 int fd, hops;
1031 if (!iter.ReadInt(&hops)) 1033 if (!iter.ReadInt(&hops))
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 } 1129 }
1128 1130
1129 #if defined(OS_LINUX) 1131 #if defined(OS_LINUX)
1130 // static 1132 // static
1131 void Channel::SetGlobalPid(int pid) { 1133 void Channel::SetGlobalPid(int pid) {
1132 ChannelPosix::SetGlobalPid(pid); 1134 ChannelPosix::SetGlobalPid(pid);
1133 } 1135 }
1134 #endif // OS_LINUX 1136 #endif // OS_LINUX
1135 1137
1136 } // namespace IPC 1138 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698