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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 // Receive the message. | 39 // Receive the message. |
40 std::vector<int> message_fds; | 40 std::vector<int> message_fds; |
41 uint8_t buffer[16]; | 41 uint8_t buffer[16]; |
42 ASSERT_EQ(static_cast<int>(request.size()), | 42 ASSERT_EQ(static_cast<int>(request.size()), |
43 UnixDomainSocket::RecvMsg(fds[0], buffer, sizeof(buffer), | 43 UnixDomainSocket::RecvMsg(fds[0], buffer, sizeof(buffer), |
44 &message_fds)); | 44 &message_fds)); |
45 ASSERT_EQ(1U, message_fds.size()); | 45 ASSERT_EQ(1U, message_fds.size()); |
46 | 46 |
47 // Close the reply FD. | 47 // Close the reply FD. |
48 ASSERT_EQ(0, HANDLE_EINTR(close(message_fds.front()))); | 48 ASSERT_EQ(0, IGNORE_EINTR(close(message_fds.front()))); |
49 | 49 |
50 // Check that the thread didn't get blocked. | 50 // Check that the thread didn't get blocked. |
51 WaitableEvent event(false, false); | 51 WaitableEvent event(false, false); |
52 message_thread.message_loop()->PostTask( | 52 message_thread.message_loop()->PostTask( |
53 FROM_HERE, | 53 FROM_HERE, |
54 Bind(&WaitableEvent::Signal, Unretained(&event))); | 54 Bind(&WaitableEvent::Signal, Unretained(&event))); |
55 ASSERT_TRUE(event.TimedWait(TimeDelta::FromMilliseconds(5000))); | 55 ASSERT_TRUE(event.TimedWait(TimeDelta::FromMilliseconds(5000))); |
56 } | 56 } |
57 | 57 |
58 TEST(UnixDomainSocketTest, SendRecvMsgAvoidsSIGPIPE) { | 58 TEST(UnixDomainSocketTest, SendRecvMsgAvoidsSIGPIPE) { |
59 // Make sure SIGPIPE isn't being ignored. | 59 // Make sure SIGPIPE isn't being ignored. |
60 struct sigaction act = {}, oldact; | 60 struct sigaction act = {}, oldact; |
61 act.sa_handler = SIG_DFL; | 61 act.sa_handler = SIG_DFL; |
62 ASSERT_EQ(0, sigaction(SIGPIPE, &act, &oldact)); | 62 ASSERT_EQ(0, sigaction(SIGPIPE, &act, &oldact)); |
63 int fds[2]; | 63 int fds[2]; |
64 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); | 64 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); |
65 file_util::ScopedFD scoped_fd1(&fds[1]); | 65 file_util::ScopedFD scoped_fd1(&fds[1]); |
66 ASSERT_EQ(0, HANDLE_EINTR(close(fds[0]))); | 66 ASSERT_EQ(0, IGNORE_EINTR(close(fds[0]))); |
67 | 67 |
68 // Have the thread send a synchronous message via the socket. Unless the | 68 // Have the thread send a synchronous message via the socket. Unless the |
69 // message is sent with MSG_NOSIGNAL, this shall result in SIGPIPE. | 69 // message is sent with MSG_NOSIGNAL, this shall result in SIGPIPE. |
70 Pickle request; | 70 Pickle request; |
71 ASSERT_EQ(-1, | 71 ASSERT_EQ(-1, |
72 UnixDomainSocket::SendRecvMsg(fds[1], static_cast<uint8_t*>(NULL), | 72 UnixDomainSocket::SendRecvMsg(fds[1], static_cast<uint8_t*>(NULL), |
73 0U, static_cast<int*>(NULL), request)); | 73 0U, static_cast<int*>(NULL), request)); |
74 ASSERT_EQ(EPIPE, errno); | 74 ASSERT_EQ(EPIPE, errno); |
75 // Restore the SIGPIPE handler. | 75 // Restore the SIGPIPE handler. |
76 ASSERT_EQ(0, sigaction(SIGPIPE, &oldact, NULL)); | 76 ASSERT_EQ(0, sigaction(SIGPIPE, &oldact, NULL)); |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 } // namespace base | 81 } // namespace base |
OLD | NEW |