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
3 // found in the LICENSE file.
5 #include "net/tools/quic/test_tools/server_thread.h"
7 #include "net/quic/test_tools/crypto_test_utils.h"
8 #include "net/tools/quic/quic_dispatcher.h"
9 #include "net/tools/quic/test_tools/quic_server_peer.h"
15 ServerThread::ServerThread(QuicServer
* server
,
17 const IPEndPoint
& address
,
18 bool strike_register_no_startup_period
)
19 : SimpleThread("server_thread"),
20 confirmed_(true, false),
29 if (strike_register_no_startup_period
) {
30 server_
->SetStrikeRegisterNoStartupPeriod();
33 // TODO(rtenneti): replace this with ProofSourceForTesting() when Chromium
34 // has a working ProofSourceForTesting().
35 server_
->SetProofSource(
36 net::test::CryptoTestUtils::FakeProofSourceForTesting());
40 ServerThread::~ServerThread() {}
42 void ServerThread::Initialize() {
47 server_
->Listen(address_
);
50 port_
= server_
->port();
56 void ServerThread::Run() {
61 while (!quit_
.IsSignaled()) {
62 if (pause_
.IsSignaled() && !resume_
.IsSignaled()) {
66 server_
->WaitForEvents();
67 MaybeNotifyOfHandshakeConfirmation();
73 int ServerThread::GetPort() {
80 void ServerThread::WaitForCryptoHandshakeConfirmed() {
84 void ServerThread::Pause() {
85 DCHECK(!pause_
.IsSignaled());
90 void ServerThread::Resume() {
91 DCHECK(!resume_
.IsSignaled());
92 DCHECK(pause_
.IsSignaled());
96 void ServerThread::Quit() {
97 if (pause_
.IsSignaled() && !resume_
.IsSignaled()) {
103 void ServerThread::MaybeNotifyOfHandshakeConfirmation() {
104 if (confirmed_
.IsSignaled()) {
108 QuicDispatcher
* dispatcher
= QuicServerPeer::GetDispatcher(server());
109 if (dispatcher
->session_map().empty()) {
110 // Wait for a session to be created.
113 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
114 if (session
->IsCryptoHandshakeConfirmed()) {