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/tools/quic/quic_dispatcher.h"
8 #include "net/tools/quic/test_tools/quic_server_peer.h"
14 ServerThread::ServerThread(QuicServer
* server
,
16 bool strike_register_no_startup_period
)
17 : SimpleThread("server_thread"),
18 confirmed_(true, false),
27 if (strike_register_no_startup_period
) {
28 server_
->SetStrikeRegisterNoStartupPeriod();
32 ServerThread::~ServerThread() {}
34 void ServerThread::Initialize() {
39 server_
->Listen(address_
);
42 port_
= server_
->port();
48 void ServerThread::Run() {
53 while (!quit_
.IsSignaled()) {
54 if (pause_
.IsSignaled() && !resume_
.IsSignaled()) {
58 server_
->WaitForEvents();
59 MaybeNotifyOfHandshakeConfirmation();
65 int ServerThread::GetPort() {
72 void ServerThread::WaitForCryptoHandshakeConfirmed() {
76 void ServerThread::Pause() {
77 DCHECK(!pause_
.IsSignaled());
82 void ServerThread::Resume() {
83 DCHECK(!resume_
.IsSignaled());
84 DCHECK(pause_
.IsSignaled());
88 void ServerThread::Quit() {
89 if (pause_
.IsSignaled() && !resume_
.IsSignaled()) {
95 void ServerThread::MaybeNotifyOfHandshakeConfirmation() {
96 if (confirmed_
.IsSignaled()) {
100 QuicDispatcher
* dispatcher
= QuicServerPeer::GetDispatcher(server());
101 if (dispatcher
->session_map().empty()) {
102 // Wait for a session to be created.
105 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
106 if (session
->IsCryptoHandshakeConfirmed()) {