| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 ASSERT_TRUE(message_thread.Start()); | 29 ASSERT_TRUE(message_thread.Start()); |
| 30 | 30 |
| 31 int fds[2]; | 31 int fds[2]; |
| 32 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); | 32 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); |
| 33 ScopedFD scoped_fd0(fds[0]); | 33 ScopedFD scoped_fd0(fds[0]); |
| 34 ScopedFD scoped_fd1(fds[1]); | 34 ScopedFD scoped_fd1(fds[1]); |
| 35 | 35 |
| 36 // Have the thread send a synchronous message via the socket. | 36 // Have the thread send a synchronous message via the socket. |
| 37 Pickle request; | 37 Pickle request; |
| 38 message_thread.task_runner()->PostTask( | 38 message_thread.task_runner()->PostTask( |
| 39 FROM_HERE, | 39 FROM_HERE, BindOnce(IgnoreResult(&UnixDomainSocket::SendRecvMsg), fds[1], |
| 40 Bind(IgnoreResult(&UnixDomainSocket::SendRecvMsg), fds[1], | 40 static_cast<uint8_t*>(NULL), 0U, |
| 41 static_cast<uint8_t*>(NULL), 0U, static_cast<int*>(NULL), request)); | 41 static_cast<int*>(NULL), request)); |
| 42 | 42 |
| 43 // Receive the message. | 43 // Receive the message. |
| 44 std::vector<ScopedFD> message_fds; | 44 std::vector<ScopedFD> message_fds; |
| 45 uint8_t buffer[16]; | 45 uint8_t buffer[16]; |
| 46 ASSERT_EQ(static_cast<int>(request.size()), | 46 ASSERT_EQ(static_cast<int>(request.size()), |
| 47 UnixDomainSocket::RecvMsg(fds[0], buffer, sizeof(buffer), | 47 UnixDomainSocket::RecvMsg(fds[0], buffer, sizeof(buffer), |
| 48 &message_fds)); | 48 &message_fds)); |
| 49 ASSERT_EQ(1U, message_fds.size()); | 49 ASSERT_EQ(1U, message_fds.size()); |
| 50 | 50 |
| 51 // Close the reply FD. | 51 // Close the reply FD. |
| 52 message_fds.clear(); | 52 message_fds.clear(); |
| 53 | 53 |
| 54 // Check that the thread didn't get blocked. | 54 // Check that the thread didn't get blocked. |
| 55 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, | 55 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 56 WaitableEvent::InitialState::NOT_SIGNALED); | 56 WaitableEvent::InitialState::NOT_SIGNALED); |
| 57 message_thread.task_runner()->PostTask( | 57 message_thread.task_runner()->PostTask( |
| 58 FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); | 58 FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&event))); |
| 59 ASSERT_TRUE(event.TimedWait(TimeDelta::FromMilliseconds(5000))); | 59 ASSERT_TRUE(event.TimedWait(TimeDelta::FromMilliseconds(5000))); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST(UnixDomainSocketTest, SendRecvMsgAvoidsSIGPIPE) { | 62 TEST(UnixDomainSocketTest, SendRecvMsgAvoidsSIGPIPE) { |
| 63 // Make sure SIGPIPE isn't being ignored. | 63 // Make sure SIGPIPE isn't being ignored. |
| 64 struct sigaction act = {}, oldact; | 64 struct sigaction act = {}, oldact; |
| 65 act.sa_handler = SIG_DFL; | 65 act.sa_handler = SIG_DFL; |
| 66 ASSERT_EQ(0, sigaction(SIGPIPE, &act, &oldact)); | 66 ASSERT_EQ(0, sigaction(SIGPIPE, &act, &oldact)); |
| 67 int fds[2]; | 67 int fds[2]; |
| 68 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); | 68 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 const ssize_t nread = UnixDomainSocket::RecvMsgWithPid( | 154 const ssize_t nread = UnixDomainSocket::RecvMsgWithPid( |
| 155 recv_sock.get(), &ch, sizeof(ch), &recv_fds, &sender_pid); | 155 recv_sock.get(), &ch, sizeof(ch), &recv_fds, &sender_pid); |
| 156 ASSERT_EQ(0, nread); | 156 ASSERT_EQ(0, nread); |
| 157 ASSERT_EQ(-1, sender_pid); | 157 ASSERT_EQ(-1, sender_pid); |
| 158 ASSERT_EQ(0U, recv_fds.size()); | 158 ASSERT_EQ(0U, recv_fds.size()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace | 161 } // namespace |
| 162 | 162 |
| 163 } // namespace base | 163 } // namespace base |
| OLD | NEW |