OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <sys/socket.h> | 5 #include <sys/socket.h> |
6 #include <sys/types.h> | 6 #include <sys/types.h> |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ScopedVector<base::ScopedFD> recv_fds; | 127 ScopedVector<base::ScopedFD> recv_fds; |
128 const ssize_t nread = UnixDomainSocket::RecvMsgWithPid( | 128 const ssize_t nread = UnixDomainSocket::RecvMsgWithPid( |
129 recv_sock.get(), buf, sizeof(buf), &recv_fds, &sender_pid); | 129 recv_sock.get(), buf, sizeof(buf), &recv_fds, &sender_pid); |
130 ASSERT_EQ(sizeof(kHello), static_cast<size_t>(nread)); | 130 ASSERT_EQ(sizeof(kHello), static_cast<size_t>(nread)); |
131 ASSERT_EQ(0, memcmp(buf, kHello, sizeof(kHello))); | 131 ASSERT_EQ(0, memcmp(buf, kHello, sizeof(kHello))); |
132 ASSERT_EQ(UnixDomainSocket::kMaxFileDescriptors, recv_fds.size()); | 132 ASSERT_EQ(UnixDomainSocket::kMaxFileDescriptors, recv_fds.size()); |
133 | 133 |
134 ASSERT_EQ(getpid(), sender_pid); | 134 ASSERT_EQ(getpid(), sender_pid); |
135 } | 135 } |
136 | 136 |
| 137 // Check that RecvMsgWithPid doesn't DCHECK fail when reading EOF from a |
| 138 // disconnected socket. |
| 139 TEST(UnixDomianSocketTest, RecvPidDisconnectedSocket) { |
| 140 int fds[2]; |
| 141 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); |
| 142 base::ScopedFD recv_sock(fds[0]); |
| 143 base::ScopedFD send_sock(fds[1]); |
| 144 |
| 145 ASSERT_TRUE(UnixDomainSocket::EnableReceiveProcessId(recv_sock.get())); |
| 146 |
| 147 send_sock.reset(); |
| 148 |
| 149 char ch; |
| 150 base::ProcessId sender_pid; |
| 151 ScopedVector<base::ScopedFD> recv_fds; |
| 152 const ssize_t nread = UnixDomainSocket::RecvMsgWithPid( |
| 153 recv_sock.get(), &ch, sizeof(ch), &recv_fds, &sender_pid); |
| 154 ASSERT_EQ(0, nread); |
| 155 ASSERT_EQ(-1, sender_pid); |
| 156 ASSERT_EQ(0U, recv_fds.size()); |
| 157 } |
| 158 |
137 } // namespace | 159 } // namespace |
138 | 160 |
139 } // namespace base | 161 } // namespace base |
OLD | NEW |