| 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 <stdint.h> |
| 10 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 11 #include <sys/stat.h> | 12 #include <sys/stat.h> |
| 12 #include <sys/types.h> | 13 #include <sys/types.h> |
| 13 #include <unistd.h> | 14 #include <unistd.h> |
| 14 | 15 |
| 15 #if defined(OS_OPENBSD) | 16 #if defined(OS_OPENBSD) |
| 16 #include <sys/uio.h> | 17 #include <sys/uio.h> |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 #if !defined(OS_NACL_NONSFI) | 20 #if !defined(OS_NACL_NONSFI) |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 cmsg = CMSG_FIRSTHDR(&msgh); | 434 cmsg = CMSG_FIRSTHDR(&msgh); |
| 434 cmsg->cmsg_level = SOL_SOCKET; | 435 cmsg->cmsg_level = SOL_SOCKET; |
| 435 cmsg->cmsg_type = SCM_RIGHTS; | 436 cmsg->cmsg_type = SCM_RIGHTS; |
| 436 cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds); | 437 cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds); |
| 437 msg->attachment_set()->PeekDescriptors( | 438 msg->attachment_set()->PeekDescriptors( |
| 438 reinterpret_cast<int*>(CMSG_DATA(cmsg))); | 439 reinterpret_cast<int*>(CMSG_DATA(cmsg))); |
| 439 msgh.msg_controllen = cmsg->cmsg_len; | 440 msgh.msg_controllen = cmsg->cmsg_len; |
| 440 | 441 |
| 441 // DCHECK_LE above already checks that | 442 // DCHECK_LE above already checks that |
| 442 // num_fds < kMaxDescriptorsPerMessage so no danger of overflow. | 443 // num_fds < kMaxDescriptorsPerMessage so no danger of overflow. |
| 443 msg->header()->num_fds = static_cast<uint16>(num_fds); | 444 msg->header()->num_fds = static_cast<uint16_t>(num_fds); |
| 444 } | 445 } |
| 445 | 446 |
| 446 if (bytes_written == 1) { | 447 if (bytes_written == 1) { |
| 447 fd_written = pipe_.get(); | 448 fd_written = pipe_.get(); |
| 448 bytes_written = HANDLE_EINTR(sendmsg(pipe_.get(), &msgh, MSG_DONTWAIT)); | 449 bytes_written = HANDLE_EINTR(sendmsg(pipe_.get(), &msgh, MSG_DONTWAIT)); |
| 449 } | 450 } |
| 450 if (bytes_written > 0) | 451 if (bytes_written > 0) |
| 451 CloseFileDescriptors(msg); | 452 CloseFileDescriptors(msg); |
| 452 | 453 |
| 453 if (bytes_written < 0 && !SocketWriteErrorIsRecoverable()) { | 454 if (bytes_written < 0 && !SocketWriteErrorIsRecoverable()) { |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 bool ChannelPosix::ShouldDispatchInputMessage(Message* msg) { | 806 bool ChannelPosix::ShouldDispatchInputMessage(Message* msg) { |
| 806 return true; | 807 return true; |
| 807 } | 808 } |
| 808 | 809 |
| 809 // On Posix, we need to fix up the file descriptors before the input message | 810 // On Posix, we need to fix up the file descriptors before the input message |
| 810 // is dispatched. | 811 // is dispatched. |
| 811 // | 812 // |
| 812 // This will read from the input_fds_ (READWRITE mode only) and read more | 813 // This will read from the input_fds_ (READWRITE mode only) and read more |
| 813 // handles from the FD pipe if necessary. | 814 // handles from the FD pipe if necessary. |
| 814 bool ChannelPosix::GetNonBrokeredAttachments(Message* msg) { | 815 bool ChannelPosix::GetNonBrokeredAttachments(Message* msg) { |
| 815 uint16 header_fds = msg->header()->num_fds; | 816 uint16_t header_fds = msg->header()->num_fds; |
| 816 if (!header_fds) | 817 if (!header_fds) |
| 817 return true; // Nothing to do. | 818 return true; // Nothing to do. |
| 818 | 819 |
| 819 // The message has file descriptors. | 820 // The message has file descriptors. |
| 820 const char* error = NULL; | 821 const char* error = NULL; |
| 821 if (header_fds > input_fds_.size()) { | 822 if (header_fds > input_fds_.size()) { |
| 822 // The message has been completely received, but we didn't get | 823 // The message has been completely received, but we didn't get |
| 823 // enough file descriptors. | 824 // enough file descriptors. |
| 824 error = "Message needs unreceived descriptors"; | 825 error = "Message needs unreceived descriptors"; |
| 825 } | 826 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 } | 1045 } |
| 1045 | 1046 |
| 1046 #if defined(OS_LINUX) | 1047 #if defined(OS_LINUX) |
| 1047 // static | 1048 // static |
| 1048 void Channel::SetGlobalPid(int pid) { | 1049 void Channel::SetGlobalPid(int pid) { |
| 1049 ChannelPosix::SetGlobalPid(pid); | 1050 ChannelPosix::SetGlobalPid(pid); |
| 1050 } | 1051 } |
| 1051 #endif // OS_LINUX | 1052 #endif // OS_LINUX |
| 1052 | 1053 |
| 1053 } // namespace IPC | 1054 } // namespace IPC |
| OLD | NEW |