OLD | NEW |
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 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 // The Hello message contains only the process id. | 998 // The Hello message contains only the process id. |
999 PickleIterator iter(msg); | 999 PickleIterator iter(msg); |
1000 | 1000 |
1001 switch (msg.type()) { | 1001 switch (msg.type()) { |
1002 default: | 1002 default: |
1003 NOTREACHED(); | 1003 NOTREACHED(); |
1004 break; | 1004 break; |
1005 | 1005 |
1006 case Channel::HELLO_MESSAGE_TYPE: | 1006 case Channel::HELLO_MESSAGE_TYPE: |
1007 int pid; | 1007 int pid; |
1008 if (!msg.ReadInt(&iter, &pid)) | 1008 if (!iter.ReadInt(&pid)) |
1009 NOTREACHED(); | 1009 NOTREACHED(); |
1010 | 1010 |
1011 #if defined(IPC_USES_READWRITE) | 1011 #if defined(IPC_USES_READWRITE) |
1012 if (mode_ & MODE_SERVER_FLAG) { | 1012 if (mode_ & MODE_SERVER_FLAG) { |
1013 // With IPC_USES_READWRITE, the Hello message from the client to the | 1013 // 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 | 1014 // server also contains the fd_pipe_, which will be used for all |
1015 // subsequent file descriptor passing. | 1015 // subsequent file descriptor passing. |
1016 DCHECK_EQ(msg.file_descriptor_set()->size(), 1U); | 1016 DCHECK_EQ(msg.file_descriptor_set()->size(), 1U); |
1017 base::ScopedFD descriptor; | 1017 base::ScopedFD descriptor; |
1018 if (!msg.ReadFile(&iter, &descriptor)) { | 1018 if (!msg.ReadFile(&iter, &descriptor)) { |
1019 NOTREACHED(); | 1019 NOTREACHED(); |
1020 } | 1020 } |
1021 fd_pipe_.reset(descriptor.release()); | 1021 fd_pipe_.reset(descriptor.release()); |
1022 } | 1022 } |
1023 #endif // IPC_USES_READWRITE | 1023 #endif // IPC_USES_READWRITE |
1024 peer_pid_ = pid; | 1024 peer_pid_ = pid; |
1025 listener()->OnChannelConnected(pid); | 1025 listener()->OnChannelConnected(pid); |
1026 break; | 1026 break; |
1027 | 1027 |
1028 #if defined(OS_MACOSX) | 1028 #if defined(OS_MACOSX) |
1029 case Channel::CLOSE_FD_MESSAGE_TYPE: | 1029 case Channel::CLOSE_FD_MESSAGE_TYPE: |
1030 int fd, hops; | 1030 int fd, hops; |
1031 if (!msg.ReadInt(&iter, &hops)) | 1031 if (!iter.ReadInt(&hops)) |
1032 NOTREACHED(); | 1032 NOTREACHED(); |
1033 if (!msg.ReadInt(&iter, &fd)) | 1033 if (!iter.ReadInt(&fd)) |
1034 NOTREACHED(); | 1034 NOTREACHED(); |
1035 if (hops == 0) { | 1035 if (hops == 0) { |
1036 if (fds_to_close_.erase(fd) > 0) { | 1036 if (fds_to_close_.erase(fd) > 0) { |
1037 if (IGNORE_EINTR(close(fd)) < 0) | 1037 if (IGNORE_EINTR(close(fd)) < 0) |
1038 PLOG(ERROR) << "close"; | 1038 PLOG(ERROR) << "close"; |
1039 } else { | 1039 } else { |
1040 NOTREACHED(); | 1040 NOTREACHED(); |
1041 } | 1041 } |
1042 } else { | 1042 } else { |
1043 QueueCloseFDMessage(fd, hops); | 1043 QueueCloseFDMessage(fd, hops); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 } | 1108 } |
1109 | 1109 |
1110 #if defined(OS_LINUX) | 1110 #if defined(OS_LINUX) |
1111 // static | 1111 // static |
1112 void Channel::SetGlobalPid(int pid) { | 1112 void Channel::SetGlobalPid(int pid) { |
1113 ChannelPosix::SetGlobalPid(pid); | 1113 ChannelPosix::SetGlobalPid(pid); |
1114 } | 1114 } |
1115 #endif // OS_LINUX | 1115 #endif // OS_LINUX |
1116 | 1116 |
1117 } // namespace IPC | 1117 } // namespace IPC |
OLD | NEW |