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 "net/tools/quic/test_tools/server_thread.h" | 5 #include "net/tools/quic/test_tools/server_thread.h" |
6 | 6 |
7 #include "net/quic/test_tools/crypto_test_utils.h" | 7 #include "net/quic/test_tools/crypto_test_utils.h" |
8 #include "net/tools/quic/quic_dispatcher.h" | 8 #include "net/tools/quic/quic_dispatcher.h" |
9 #include "net/tools/quic/test_tools/quic_server_peer.h" | 9 #include "net/tools/quic/test_tools/quic_server_peer.h" |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 if (!initialized_) { | 54 if (!initialized_) { |
55 Initialize(); | 55 Initialize(); |
56 } | 56 } |
57 | 57 |
58 while (!quit_.IsSignaled()) { | 58 while (!quit_.IsSignaled()) { |
59 if (pause_.IsSignaled() && !resume_.IsSignaled()) { | 59 if (pause_.IsSignaled() && !resume_.IsSignaled()) { |
60 paused_.Signal(); | 60 paused_.Signal(); |
61 resume_.Wait(); | 61 resume_.Wait(); |
62 } | 62 } |
63 server_->WaitForEvents(); | 63 server_->WaitForEvents(); |
| 64 ExecuteScheduledActions(); |
64 MaybeNotifyOfHandshakeConfirmation(); | 65 MaybeNotifyOfHandshakeConfirmation(); |
65 } | 66 } |
66 | 67 |
67 server_->Shutdown(); | 68 server_->Shutdown(); |
68 } | 69 } |
69 | 70 |
70 int ServerThread::GetPort() { | 71 int ServerThread::GetPort() { |
71 port_lock_.Acquire(); | 72 port_lock_.Acquire(); |
72 int rc = port_; | 73 int rc = port_; |
73 port_lock_.Release(); | 74 port_lock_.Release(); |
74 return rc; | 75 return rc; |
75 } | 76 } |
76 | 77 |
| 78 void ServerThread::Schedule(std::function<void()> action) { |
| 79 DCHECK(!quit_.IsSignaled()); |
| 80 base::AutoLock lock(scheduled_actions_lock_); |
| 81 scheduled_actions_.push_back(std::move(action)); |
| 82 } |
| 83 |
77 void ServerThread::WaitForCryptoHandshakeConfirmed() { | 84 void ServerThread::WaitForCryptoHandshakeConfirmed() { |
78 confirmed_.Wait(); | 85 confirmed_.Wait(); |
79 } | 86 } |
80 | 87 |
81 void ServerThread::Pause() { | 88 void ServerThread::Pause() { |
82 DCHECK(!pause_.IsSignaled()); | 89 DCHECK(!pause_.IsSignaled()); |
83 pause_.Signal(); | 90 pause_.Signal(); |
84 paused_.Wait(); | 91 paused_.Wait(); |
85 } | 92 } |
86 | 93 |
(...skipping 19 matching lines...) Expand all Loading... |
106 if (dispatcher->session_map().empty()) { | 113 if (dispatcher->session_map().empty()) { |
107 // Wait for a session to be created. | 114 // Wait for a session to be created. |
108 return; | 115 return; |
109 } | 116 } |
110 QuicSession* session = dispatcher->session_map().begin()->second; | 117 QuicSession* session = dispatcher->session_map().begin()->second; |
111 if (session->IsCryptoHandshakeConfirmed()) { | 118 if (session->IsCryptoHandshakeConfirmed()) { |
112 confirmed_.Signal(); | 119 confirmed_.Signal(); |
113 } | 120 } |
114 } | 121 } |
115 | 122 |
| 123 void ServerThread::ExecuteScheduledActions() { |
| 124 std::deque<std::function<void()>> actions; |
| 125 { |
| 126 base::AutoLock lock(scheduled_actions_lock_); |
| 127 actions.swap(scheduled_actions_); |
| 128 } |
| 129 while (!actions.empty()) { |
| 130 actions.front()(); |
| 131 actions.pop_front(); |
| 132 } |
| 133 } |
| 134 |
116 } // namespace test | 135 } // namespace test |
117 } // namespace net | 136 } // namespace net |
OLD | NEW |