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/tools/quic/test_tools/quic_server_peer.h" | 7 #include "net/tools/quic/test_tools/quic_server_peer.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 namespace tools { | 10 namespace tools { |
11 namespace test { | 11 namespace test { |
12 | 12 |
13 ServerThread::ServerThread(IPEndPoint address, | 13 ServerThread::ServerThread(QuicServer* server, |
14 const QuicConfig& config, | 14 IPEndPoint address, |
15 const QuicVersionVector& supported_versions, | 15 bool strike_register_no_startup_period) |
16 bool strike_register_no_startup_period, | |
17 uint32 server_initial_flow_control_receive_window) | |
18 : SimpleThread("server_thread"), | 16 : SimpleThread("server_thread"), |
19 confirmed_(true, false), | 17 confirmed_(true, false), |
20 pause_(true, false), | 18 pause_(true, false), |
21 paused_(true, false), | 19 paused_(true, false), |
22 resume_(true, false), | 20 resume_(true, false), |
23 quit_(true, false), | 21 quit_(true, false), |
24 server_(config, | 22 server_(server), |
25 supported_versions, | |
26 server_initial_flow_control_receive_window), | |
27 address_(address), | 23 address_(address), |
28 port_(0), | 24 port_(0), |
29 initialized_(false) { | 25 initialized_(false) { |
30 if (strike_register_no_startup_period) { | 26 if (strike_register_no_startup_period) { |
31 server_.SetStrikeRegisterNoStartupPeriod(); | 27 server_->SetStrikeRegisterNoStartupPeriod(); |
32 } | 28 } |
33 } | 29 } |
34 | 30 |
35 ServerThread::~ServerThread() {} | 31 ServerThread::~ServerThread() {} |
36 | 32 |
37 void ServerThread::Initialize() { | 33 void ServerThread::Initialize() { |
38 if (initialized_) { | 34 if (initialized_) { |
39 return; | 35 return; |
40 } | 36 } |
41 | 37 |
42 server_.Listen(address_); | 38 server_->Listen(address_); |
43 | 39 |
44 port_lock_.Acquire(); | 40 port_lock_.Acquire(); |
45 port_ = server_.port(); | 41 port_ = server_->port(); |
46 port_lock_.Release(); | 42 port_lock_.Release(); |
47 | 43 |
48 initialized_ = true; | 44 initialized_ = true; |
49 } | 45 } |
50 | 46 |
51 void ServerThread::Run() { | 47 void ServerThread::Run() { |
52 if (!initialized_) { | 48 if (!initialized_) { |
53 Initialize(); | 49 Initialize(); |
54 } | 50 } |
55 | 51 |
56 while (!quit_.IsSignaled()) { | 52 while (!quit_.IsSignaled()) { |
57 if (pause_.IsSignaled() && !resume_.IsSignaled()) { | 53 if (pause_.IsSignaled() && !resume_.IsSignaled()) { |
58 paused_.Signal(); | 54 paused_.Signal(); |
59 resume_.Wait(); | 55 resume_.Wait(); |
60 } | 56 } |
61 server_.WaitForEvents(); | 57 server_->WaitForEvents(); |
62 MaybeNotifyOfHandshakeConfirmation(); | 58 MaybeNotifyOfHandshakeConfirmation(); |
63 } | 59 } |
64 | 60 |
65 server_.Shutdown(); | 61 server_->Shutdown(); |
66 } | 62 } |
67 | 63 |
68 int ServerThread::GetPort() { | 64 int ServerThread::GetPort() { |
69 port_lock_.Acquire(); | 65 port_lock_.Acquire(); |
70 int rc = port_; | 66 int rc = port_; |
71 port_lock_.Release(); | 67 port_lock_.Release(); |
72 return rc; | 68 return rc; |
73 } | 69 } |
74 | 70 |
75 void ServerThread::WaitForCryptoHandshakeConfirmed() { | 71 void ServerThread::WaitForCryptoHandshakeConfirmed() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 103 } |
108 QuicSession* session = dispatcher->session_map().begin()->second; | 104 QuicSession* session = dispatcher->session_map().begin()->second; |
109 if (session->IsCryptoHandshakeConfirmed()) { | 105 if (session->IsCryptoHandshakeConfirmed()) { |
110 confirmed_.Signal(); | 106 confirmed_.Signal(); |
111 } | 107 } |
112 } | 108 } |
113 | 109 |
114 } // namespace test | 110 } // namespace test |
115 } // namespace tools | 111 } // namespace tools |
116 } // namespace net | 112 } // namespace net |
OLD | NEW |