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 <sys/socket.h> | 5 #include <sys/socket.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 int server_fd_; | 71 int server_fd_; |
72 base::MessageLoopProxy* target_thread_; | 72 base::MessageLoopProxy* target_thread_; |
73 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> watcher_; | 73 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> watcher_; |
74 base::WaitableEvent started_watching_event_; | 74 base::WaitableEvent started_watching_event_; |
75 base::WaitableEvent accepted_event_; | 75 base::WaitableEvent accepted_event_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(SocketAcceptor); | 77 DISALLOW_COPY_AND_ASSIGN(SocketAcceptor); |
78 }; | 78 }; |
79 | 79 |
80 const base::FilePath GetChannelDir() { | 80 const base::FilePath GetChannelDir() { |
81 #if defined(OS_ANDROID) | |
82 base::FilePath tmp_dir; | 81 base::FilePath tmp_dir; |
83 PathService::Get(base::DIR_CACHE, &tmp_dir); | 82 PathService::Get(base::DIR_TEMP, &tmp_dir); |
84 return tmp_dir; | 83 return tmp_dir; |
85 #else | |
86 return base::FilePath("/var/tmp"); | |
87 #endif | |
88 } | 84 } |
89 | 85 |
90 class TestUnixSocketConnection { | 86 class TestUnixSocketConnection { |
91 public: | 87 public: |
92 TestUnixSocketConnection() | 88 TestUnixSocketConnection() |
93 : worker_("WorkerThread"), | 89 : worker_("WorkerThread"), |
94 server_listen_fd_(-1), | 90 server_listen_fd_(-1), |
95 server_fd_(-1), | 91 server_fd_(-1), |
96 client_fd_(-1) { | 92 client_fd_(-1) { |
97 socket_name_ = GetChannelDir().Append("TestSocket"); | 93 socket_name_ = GetChannelDir().Append("TestSocket"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 HANDLE_EINTR(send(connection.client_fd(), buffer, buf_len, 0)); | 162 HANDLE_EINTR(send(connection.client_fd(), buffer, buf_len, 0)); |
167 ASSERT_EQ(buf_len, sent_bytes); | 163 ASSERT_EQ(buf_len, sent_bytes); |
168 char recv_buf[sizeof(buffer)]; | 164 char recv_buf[sizeof(buffer)]; |
169 size_t received_bytes = | 165 size_t received_bytes = |
170 HANDLE_EINTR(recv(connection.server_fd(), recv_buf, buf_len, 0)); | 166 HANDLE_EINTR(recv(connection.server_fd(), recv_buf, buf_len, 0)); |
171 ASSERT_EQ(buf_len, received_bytes); | 167 ASSERT_EQ(buf_len, received_bytes); |
172 ASSERT_EQ(0, memcmp(recv_buf, buffer, buf_len)); | 168 ASSERT_EQ(0, memcmp(recv_buf, buffer, buf_len)); |
173 } | 169 } |
174 | 170 |
175 } // namespace | 171 } // namespace |
OLD | NEW |