Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: net/tools/quic/test_tools/server_thread.cc

Issue 127633002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/tools/quic/test_tools/server_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(IPEndPoint address,
14 const QuicConfig& config, 14 const QuicConfig& config,
15 const QuicVersionVector& supported_versions, 15 const QuicVersionVector& supported_versions,
16 bool strike_register_no_startup_period) 16 bool strike_register_no_startup_period)
17 : SimpleThread("server_thread"), 17 : SimpleThread("server_thread"),
18 listening_(true, false), 18 listening_(true, false),
19 confirmed_(true, false), 19 confirmed_(true, false),
20 pause_(true, false),
21 paused_(true, false),
22 resume_(true, false),
23 quit_(true, false), 20 quit_(true, false),
24 server_(config, supported_versions), 21 server_(config, supported_versions),
25 address_(address), 22 address_(address),
26 port_(0) { 23 port_(0) {
27 if (strike_register_no_startup_period) { 24 if (strike_register_no_startup_period) {
28 server_.SetStrikeRegisterNoStartupPeriod(); 25 server_.SetStrikeRegisterNoStartupPeriod();
29 } 26 }
30 } 27 }
31 28
32 ServerThread::~ServerThread() { 29 ServerThread::~ServerThread() {
33 } 30 }
34 31
35 void ServerThread::Run() { 32 void ServerThread::Run() {
36 server_.Listen(address_); 33 server_.Listen(address_);
37 34
38 port_lock_.Acquire(); 35 port_lock_.Acquire();
39 port_ = server_.port(); 36 port_ = server_.port();
40 port_lock_.Release(); 37 port_lock_.Release();
41 38
42 listening_.Signal(); 39 listening_.Signal();
43 while (!quit_.IsSignaled()) { 40 while (!quit_.IsSignaled()) {
44 if (pause_.IsSignaled() && !resume_.IsSignaled()) { 41 event_loop_mu_.Acquire();
45 paused_.Signal();
46 resume_.Wait();
47 }
48 server_.WaitForEvents(); 42 server_.WaitForEvents();
49 MaybeNotifyOfHandshakeConfirmation(); 43 MaybeNotifyOfHandshakeConfirmation();
44 event_loop_mu_.Release();
50 } 45 }
51 46
52 server_.Shutdown(); 47 server_.Shutdown();
53 } 48 }
54 49
55 int ServerThread::GetPort() { 50 int ServerThread::GetPort() {
56 port_lock_.Acquire(); 51 port_lock_.Acquire();
57 int rc = port_; 52 int rc = port_;
58 port_lock_.Release(); 53 port_lock_.Release();
59 return rc; 54 return rc;
60 } 55 }
61 56
62 void ServerThread::WaitForServerStartup() { 57 void ServerThread::WaitForServerStartup() {
63 listening_.Wait(); 58 listening_.Wait();
64 } 59 }
65 60
66 void ServerThread::WaitForCryptoHandshakeConfirmed() { 61 void ServerThread::WaitForCryptoHandshakeConfirmed() {
67 confirmed_.Wait(); 62 confirmed_.Wait();
68 } 63 }
69 64
70 void ServerThread::Pause() { 65 void ServerThread::Pause() {
71 DCHECK(!pause_.IsSignaled()); 66 event_loop_mu_.Acquire();
72 pause_.Signal();
73 paused_.Wait();
74 } 67 }
75 68
76 void ServerThread::Resume() { 69 void ServerThread::Resume() {
77 DCHECK(!resume_.IsSignaled()); 70 event_loop_mu_.AssertAcquired(); // Checks the calling thread only!
78 DCHECK(pause_.IsSignaled()); 71 event_loop_mu_.Release();
79 resume_.Signal();
80 } 72 }
81 73
82 void ServerThread::Quit() { 74 void ServerThread::Quit() {
83 if (pause_.IsSignaled() && !resume_.IsSignaled()) {
84 resume_.Signal();
85 }
86 quit_.Signal(); 75 quit_.Signal();
87 } 76 }
88 77
89 void ServerThread::MaybeNotifyOfHandshakeConfirmation() { 78 void ServerThread::MaybeNotifyOfHandshakeConfirmation() {
90 if (confirmed_.IsSignaled()) { 79 if (confirmed_.IsSignaled()) {
91 // Only notify once. 80 // Only notify once.
92 return; 81 return;
93 } 82 }
94 QuicDispatcher* dispatcher = QuicServerPeer::GetDispatcher(server()); 83 QuicDispatcher* dispatcher = QuicServerPeer::GetDispatcher(server());
95 if (dispatcher->session_map().empty()) { 84 if (dispatcher->session_map().empty()) {
96 // Wait for a session to be created. 85 // Wait for a session to be created.
97 return; 86 return;
98 } 87 }
99 QuicSession* session = dispatcher->session_map().begin()->second; 88 QuicSession* session = dispatcher->session_map().begin()->second;
100 if (session->IsCryptoHandshakeConfirmed()) { 89 if (session->IsCryptoHandshakeConfirmed()) {
101 confirmed_.Signal(); 90 confirmed_.Signal();
102 } 91 }
103 } 92 }
104 93
105 } // namespace test 94 } // namespace test
106 } // namespace tools 95 } // namespace tools
107 } // namespace net 96 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/server_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698