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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/sync_socket.h" | 6 #include "base/sync_socket.h" |
7 #include "base/threading/simple_thread.h" | 7 #include "base/threading/simple_thread.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 const int kReceiveTimeoutInMilliseconds = 750; | 13 const int kReceiveTimeoutInMilliseconds = 750; |
14 | 14 |
15 class HangingReceiveThread : public base::DelegateSimpleThread::Delegate { | 15 class HangingReceiveThread : public base::DelegateSimpleThread::Delegate { |
16 public: | 16 public: |
17 explicit HangingReceiveThread(base::SyncSocket* socket) | 17 explicit HangingReceiveThread(base::SyncSocket* socket) |
18 : socket_(socket), | 18 : socket_(socket), |
19 thread_(this, "HangingReceiveThread") { | 19 thread_(this, "HangingReceiveThread") { |
20 thread_.Start(); | 20 thread_.Start(); |
21 } | 21 } |
22 | 22 |
23 virtual ~HangingReceiveThread() {} | 23 virtual ~HangingReceiveThread() {} |
24 | 24 |
25 virtual void Run() OVERRIDE { | 25 void Run() override { |
26 int data = 0; | 26 int data = 0; |
27 ASSERT_EQ(socket_->Peek(), 0u); | 27 ASSERT_EQ(socket_->Peek(), 0u); |
28 | 28 |
29 // Use receive with timeout so we don't hang the test harness indefinitely. | 29 // Use receive with timeout so we don't hang the test harness indefinitely. |
30 ASSERT_EQ(0u, socket_->ReceiveWithTimeout( | 30 ASSERT_EQ(0u, socket_->ReceiveWithTimeout( |
31 &data, sizeof(data), base::TimeDelta::FromMilliseconds( | 31 &data, sizeof(data), base::TimeDelta::FromMilliseconds( |
32 kReceiveTimeoutInMilliseconds))); | 32 kReceiveTimeoutInMilliseconds))); |
33 } | 33 } |
34 | 34 |
35 void Stop() { | 35 void Stop() { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 ASSERT_TRUE(socket_b.Shutdown()); | 122 ASSERT_TRUE(socket_b.Shutdown()); |
123 thread.Stop(); | 123 thread.Stop(); |
124 | 124 |
125 // Ensure the receive didn't just timeout. | 125 // Ensure the receive didn't just timeout. |
126 ASSERT_LT((base::TimeTicks::Now() - start).InMilliseconds(), | 126 ASSERT_LT((base::TimeTicks::Now() - start).InMilliseconds(), |
127 kReceiveTimeoutInMilliseconds); | 127 kReceiveTimeoutInMilliseconds); |
128 | 128 |
129 ASSERT_TRUE(socket_a.Close()); | 129 ASSERT_TRUE(socket_a.Close()); |
130 ASSERT_TRUE(socket_b.Close()); | 130 ASSERT_TRUE(socket_b.Close()); |
131 } | 131 } |
OLD | NEW |