| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #if defined(OS_MACOSX) | 8 #if defined(OS_MACOSX) |
| 9 extern "C" { | 9 extern "C" { |
| 10 #include <sandbox.h> | 10 #include <sandbox.h> |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 FROM_HERE, base::Bind(&PipeChannelHelper::Connect, out.get())); | 262 FROM_HERE, base::Bind(&PipeChannelHelper::Connect, out.get())); |
| 263 } | 263 } |
| 264 | 264 |
| 265 static void DestroyChannel(std::unique_ptr<IPC::Channel>* c, | 265 static void DestroyChannel(std::unique_ptr<IPC::Channel>* c, |
| 266 base::WaitableEvent* event) { | 266 base::WaitableEvent* event) { |
| 267 c->reset(0); | 267 c->reset(0); |
| 268 event->Signal(); | 268 event->Signal(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 ~PipeChannelHelper() { | 271 ~PipeChannelHelper() { |
| 272 base::WaitableEvent a(true, false); | 272 base::WaitableEvent a(base::WaitableEvent::ResetPolicy::MANUAL, |
| 273 base::WaitableEvent b(true, false); | 273 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 274 base::WaitableEvent b(base::WaitableEvent::ResetPolicy::MANUAL, |
| 275 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 274 in_thread_->task_runner()->PostTask( | 276 in_thread_->task_runner()->PostTask( |
| 275 FROM_HERE, base::Bind(&PipeChannelHelper::DestroyChannel, &in, &a)); | 277 FROM_HERE, base::Bind(&PipeChannelHelper::DestroyChannel, &in, &a)); |
| 276 out_thread_->task_runner()->PostTask( | 278 out_thread_->task_runner()->PostTask( |
| 277 FROM_HERE, base::Bind(&PipeChannelHelper::DestroyChannel, &out, &b)); | 279 FROM_HERE, base::Bind(&PipeChannelHelper::DestroyChannel, &out, &b)); |
| 278 a.Wait(); | 280 a.Wait(); |
| 279 b.Wait(); | 281 b.Wait(); |
| 280 } | 282 } |
| 281 | 283 |
| 282 static void Connect(IPC::Channel *channel) { | 284 static void Connect(IPC::Channel *channel) { |
| 283 EXPECT_TRUE(channel->Connect()); | 285 EXPECT_TRUE(channel->Connect()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 308 // threads, the producer thread creates socketpairs and sends one of the fds | 310 // threads, the producer thread creates socketpairs and sends one of the fds |
| 309 // over pipe1 to the middleman thread. The middleman thread simply takes the fd | 311 // over pipe1 to the middleman thread. The middleman thread simply takes the fd |
| 310 // sends it over pipe2 to the consumer thread. The consumer thread writes a byte | 312 // sends it over pipe2 to the consumer thread. The consumer thread writes a byte |
| 311 // to each fd it receives and then closes the pipe. The producer thread reads | 313 // to each fd it receives and then closes the pipe. The producer thread reads |
| 312 // the bytes back from each pair of pipes and make sure that everything worked. | 314 // the bytes back from each pair of pipes and make sure that everything worked. |
| 313 // This feedback mechanism makes sure that not too many file descriptors are | 315 // This feedback mechanism makes sure that not too many file descriptors are |
| 314 // in flight at the same time. For more info on the bug, see: | 316 // in flight at the same time. For more info on the bug, see: |
| 315 // http://crbug.com/298276 | 317 // http://crbug.com/298276 |
| 316 class IPCMultiSendingFdsTest : public testing::Test { | 318 class IPCMultiSendingFdsTest : public testing::Test { |
| 317 public: | 319 public: |
| 318 IPCMultiSendingFdsTest() : received_(true, false) {} | 320 IPCMultiSendingFdsTest() |
| 321 : received_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 322 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 319 | 323 |
| 320 void Producer(PipeChannelHelper* dest, | 324 void Producer(PipeChannelHelper* dest, |
| 321 base::Thread* t, | 325 base::Thread* t, |
| 322 int pipes_to_send) { | 326 int pipes_to_send) { |
| 323 for (int i = 0; i < pipes_to_send; i++) { | 327 for (int i = 0; i < pipes_to_send; i++) { |
| 324 received_.Reset(); | 328 received_.Reset(); |
| 325 std::pair<int, int> pipe_fds = make_socket_pair(); | 329 std::pair<int, int> pipe_fds = make_socket_pair(); |
| 326 t->task_runner()->PostTask( | 330 t->task_runner()->PostTask( |
| 327 FROM_HERE, base::Bind(&PipeChannelHelper::Send, | 331 FROM_HERE, base::Bind(&PipeChannelHelper::Send, |
| 328 base::Unretained(dest), pipe_fds.second)); | 332 base::Unretained(dest), pipe_fds.second)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 base::WaitableEvent received_; | 382 base::WaitableEvent received_; |
| 379 }; | 383 }; |
| 380 | 384 |
| 381 TEST_F(IPCMultiSendingFdsTest, StressTest) { | 385 TEST_F(IPCMultiSendingFdsTest, StressTest) { |
| 382 Run(); | 386 Run(); |
| 383 } | 387 } |
| 384 | 388 |
| 385 } // namespace | 389 } // namespace |
| 386 | 390 |
| 387 #endif // defined(OS_POSIX) | 391 #endif // defined(OS_POSIX) |
| OLD | NEW |