OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ipc/unix_domain_socket_util.h" | 5 #include "ipc/unix_domain_socket_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class SocketAcceptor : public base::MessageLoopForIO::Watcher { | 26 class SocketAcceptor : public base::MessageLoopForIO::Watcher { |
27 public: | 27 public: |
28 SocketAcceptor(int fd, base::SingleThreadTaskRunner* target_thread) | 28 SocketAcceptor(int fd, base::SingleThreadTaskRunner* target_thread) |
29 : server_fd_(-1), | 29 : server_fd_(-1), |
30 target_thread_(target_thread), | 30 target_thread_(target_thread), |
31 started_watching_event_(false, false), | 31 started_watching_event_( |
32 accepted_event_(false, false) { | 32 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 33 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 34 accepted_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 35 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
33 target_thread->PostTask(FROM_HERE, | 36 target_thread->PostTask(FROM_HERE, |
34 base::Bind(&SocketAcceptor::StartWatching, base::Unretained(this), fd)); | 37 base::Bind(&SocketAcceptor::StartWatching, base::Unretained(this), fd)); |
35 } | 38 } |
36 | 39 |
37 ~SocketAcceptor() override { | 40 ~SocketAcceptor() override { |
38 Close(); | 41 Close(); |
39 } | 42 } |
40 | 43 |
41 int server_fd() const { return server_fd_; } | 44 int server_fd() const { return server_fd_; } |
42 | 45 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 HANDLE_EINTR(send(connection.client_fd(), buffer, buf_len, 0)); | 172 HANDLE_EINTR(send(connection.client_fd(), buffer, buf_len, 0)); |
170 ASSERT_EQ(buf_len, sent_bytes); | 173 ASSERT_EQ(buf_len, sent_bytes); |
171 char recv_buf[sizeof(buffer)]; | 174 char recv_buf[sizeof(buffer)]; |
172 size_t received_bytes = | 175 size_t received_bytes = |
173 HANDLE_EINTR(recv(connection.server_fd(), recv_buf, buf_len, 0)); | 176 HANDLE_EINTR(recv(connection.server_fd(), recv_buf, buf_len, 0)); |
174 ASSERT_EQ(buf_len, received_bytes); | 177 ASSERT_EQ(buf_len, received_bytes); |
175 ASSERT_EQ(0, memcmp(recv_buf, buffer, buf_len)); | 178 ASSERT_EQ(0, memcmp(recv_buf, buffer, buf_len)); |
176 } | 179 } |
177 | 180 |
178 } // namespace | 181 } // namespace |
OLD | NEW |