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