| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/posix/unix_domain_socket.h" | 5 #include "base/posix/unix_domain_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #include <sys/uio.h> | 9 #include <sys/uio.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 msg.msg_control = control_buffer; | 36 msg.msg_control = control_buffer; |
| 37 msg.msg_controllen = control_len; | 37 msg.msg_controllen = control_len; |
| 38 cmsg = CMSG_FIRSTHDR(&msg); | 38 cmsg = CMSG_FIRSTHDR(&msg); |
| 39 cmsg->cmsg_level = SOL_SOCKET; | 39 cmsg->cmsg_level = SOL_SOCKET; |
| 40 cmsg->cmsg_type = SCM_RIGHTS; | 40 cmsg->cmsg_type = SCM_RIGHTS; |
| 41 cmsg->cmsg_len = CMSG_LEN(sizeof(int) * fds.size()); | 41 cmsg->cmsg_len = CMSG_LEN(sizeof(int) * fds.size()); |
| 42 memcpy(CMSG_DATA(cmsg), &fds[0], sizeof(int) * fds.size()); | 42 memcpy(CMSG_DATA(cmsg), &fds[0], sizeof(int) * fds.size()); |
| 43 msg.msg_controllen = cmsg->cmsg_len; | 43 msg.msg_controllen = cmsg->cmsg_len; |
| 44 } | 44 } |
| 45 | 45 |
| 46 const ssize_t r = HANDLE_EINTR(sendmsg(fd, &msg, 0)); | 46 // When available, take advantage of MSG_NOSIGNAL to avoid |
| 47 // a SIGPIPE if the other end breaks the connection. |
| 48 #if defined(MSG_NOSIGNAL) |
| 49 const int flags = MSG_NOSIGNAL; |
| 50 #else |
| 51 const int flags = 0; |
| 52 #endif |
| 53 const ssize_t r = HANDLE_EINTR(sendmsg(fd, &msg, flags)); |
| 47 const bool ret = static_cast<ssize_t>(length) == r; | 54 const bool ret = static_cast<ssize_t>(length) == r; |
| 48 delete[] control_buffer; | 55 delete[] control_buffer; |
| 49 return ret; | 56 return ret; |
| 50 } | 57 } |
| 51 | 58 |
| 52 // static | 59 // static |
| 53 ssize_t UnixDomainSocket::RecvMsg(int fd, | 60 ssize_t UnixDomainSocket::RecvMsg(int fd, |
| 54 void* buf, | 61 void* buf, |
| 55 size_t length, | 62 size_t length, |
| 56 std::vector<int>* fds) { | 63 std::vector<int>* fds) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 NOTREACHED(); | 144 NOTREACHED(); |
| 138 | 145 |
| 139 return -1; | 146 return -1; |
| 140 } | 147 } |
| 141 | 148 |
| 142 if (result_fd) | 149 if (result_fd) |
| 143 *result_fd = fd_vector.empty() ? -1 : fd_vector[0]; | 150 *result_fd = fd_vector.empty() ? -1 : fd_vector[0]; |
| 144 | 151 |
| 145 return reply_len; | 152 return reply_len; |
| 146 } | 153 } |
| OLD | NEW |