OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic_test_client.h" | 5 #include "net/tools/quic/test_tools/quic_test_client.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "net/base/completion_callback.h" | 8 #include "net/base/completion_callback.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/cert/cert_verify_result.h" | 10 #include "net/cert/cert_verify_result.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 "http://www.google.com"; | 97 "http://www.google.com"; |
98 full_uri.append(uri.as_string()); | 98 full_uri.append(uri.as_string()); |
99 headers->SetRequestUri(full_uri); | 99 headers->SetRequestUri(full_uri); |
100 } | 100 } |
101 return headers; | 101 return headers; |
102 } | 102 } |
103 | 103 |
104 MockableQuicClient::MockableQuicClient( | 104 MockableQuicClient::MockableQuicClient( |
105 IPEndPoint server_address, | 105 IPEndPoint server_address, |
106 const QuicServerId& server_id, | 106 const QuicServerId& server_id, |
107 const QuicVersionVector& supported_versions) | 107 const QuicVersionVector& supported_versions, |
| 108 EpollServer* epoll_server) |
108 : QuicClient(server_address, | 109 : QuicClient(server_address, |
109 server_id, | 110 server_id, |
110 supported_versions, | 111 supported_versions, |
111 false), | 112 false, |
| 113 epoll_server), |
112 override_connection_id_(0), | 114 override_connection_id_(0), |
113 test_writer_(NULL) {} | 115 test_writer_(NULL) {} |
114 | 116 |
115 MockableQuicClient::MockableQuicClient( | 117 MockableQuicClient::MockableQuicClient( |
116 IPEndPoint server_address, | 118 IPEndPoint server_address, |
117 const QuicServerId& server_id, | 119 const QuicServerId& server_id, |
118 const QuicConfig& config, | 120 const QuicConfig& config, |
119 const QuicVersionVector& supported_versions) | 121 const QuicVersionVector& supported_versions, |
| 122 EpollServer* epoll_server) |
120 : QuicClient(server_address, | 123 : QuicClient(server_address, |
121 server_id, | 124 server_id, |
122 supported_versions, | 125 supported_versions, |
123 false, | 126 false, |
124 config), | 127 config, |
| 128 epoll_server), |
125 override_connection_id_(0), | 129 override_connection_id_(0), |
126 test_writer_(NULL) {} | 130 test_writer_(NULL) {} |
127 | 131 |
128 MockableQuicClient::~MockableQuicClient() { | 132 MockableQuicClient::~MockableQuicClient() { |
129 if (connected()) { | 133 if (connected()) { |
130 Disconnect(); | 134 Disconnect(); |
131 } | 135 } |
132 } | 136 } |
133 | 137 |
134 QuicPacketWriter* MockableQuicClient::CreateQuicPacketWriter() { | 138 QuicPacketWriter* MockableQuicClient::CreateQuicPacketWriter() { |
(...skipping 21 matching lines...) Expand all Loading... |
156 } | 160 } |
157 | 161 |
158 QuicTestClient::QuicTestClient(IPEndPoint server_address, | 162 QuicTestClient::QuicTestClient(IPEndPoint server_address, |
159 const string& server_hostname, | 163 const string& server_hostname, |
160 const QuicVersionVector& supported_versions) | 164 const QuicVersionVector& supported_versions) |
161 : client_(new MockableQuicClient(server_address, | 165 : client_(new MockableQuicClient(server_address, |
162 QuicServerId(server_hostname, | 166 QuicServerId(server_hostname, |
163 server_address.port(), | 167 server_address.port(), |
164 false, | 168 false, |
165 PRIVACY_MODE_DISABLED), | 169 PRIVACY_MODE_DISABLED), |
166 supported_versions)) { | 170 supported_versions, |
| 171 &epoll_server_)) { |
167 Initialize(true); | 172 Initialize(true); |
168 } | 173 } |
169 | 174 |
170 QuicTestClient::QuicTestClient(IPEndPoint server_address, | 175 QuicTestClient::QuicTestClient(IPEndPoint server_address, |
171 const string& server_hostname, | 176 const string& server_hostname, |
172 bool secure, | 177 bool secure, |
173 const QuicVersionVector& supported_versions) | 178 const QuicVersionVector& supported_versions) |
174 : client_(new MockableQuicClient(server_address, | 179 : client_(new MockableQuicClient(server_address, |
175 QuicServerId(server_hostname, | 180 QuicServerId(server_hostname, |
176 server_address.port(), | 181 server_address.port(), |
177 secure, | 182 secure, |
178 PRIVACY_MODE_DISABLED), | 183 PRIVACY_MODE_DISABLED), |
179 supported_versions)) { | 184 supported_versions, |
| 185 &epoll_server_)) { |
180 Initialize(secure); | 186 Initialize(secure); |
181 } | 187 } |
182 | 188 |
183 QuicTestClient::QuicTestClient( | 189 QuicTestClient::QuicTestClient( |
184 IPEndPoint server_address, | 190 IPEndPoint server_address, |
185 const string& server_hostname, | 191 const string& server_hostname, |
186 bool secure, | 192 bool secure, |
187 const QuicConfig& config, | 193 const QuicConfig& config, |
188 const QuicVersionVector& supported_versions) | 194 const QuicVersionVector& supported_versions) |
189 : client_( | 195 : client_( |
190 new MockableQuicClient(server_address, | 196 new MockableQuicClient(server_address, |
191 QuicServerId(server_hostname, | 197 QuicServerId(server_hostname, |
192 server_address.port(), | 198 server_address.port(), |
193 secure, | 199 secure, |
194 PRIVACY_MODE_DISABLED), | 200 PRIVACY_MODE_DISABLED), |
195 config, | 201 config, |
196 supported_versions)) { | 202 supported_versions, |
| 203 &epoll_server_)) { |
197 Initialize(secure); | 204 Initialize(secure); |
198 } | 205 } |
199 | 206 |
200 QuicTestClient::QuicTestClient() { | 207 QuicTestClient::QuicTestClient() { |
201 } | 208 } |
202 | 209 |
203 QuicTestClient::~QuicTestClient() { | 210 QuicTestClient::~QuicTestClient() { |
204 if (stream_) { | 211 if (stream_) { |
205 stream_->set_visitor(NULL); | 212 stream_->set_visitor(NULL); |
206 } | 213 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 response_headers_complete_ = false; | 404 response_headers_complete_ = false; |
398 headers_.Clear(); | 405 headers_.Clear(); |
399 bytes_read_ = 0; | 406 bytes_read_ = 0; |
400 bytes_written_ = 0; | 407 bytes_written_ = 0; |
401 response_header_size_ = 0; | 408 response_header_size_ = 0; |
402 response_body_size_ = 0; | 409 response_body_size_ = 0; |
403 } | 410 } |
404 | 411 |
405 void QuicTestClient::WaitForResponseForMs(int timeout_ms) { | 412 void QuicTestClient::WaitForResponseForMs(int timeout_ms) { |
406 int64 timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; | 413 int64 timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; |
407 int64 old_timeout_us = client()->epoll_server()->timeout_in_us(); | 414 int64 old_timeout_us = epoll_server()->timeout_in_us(); |
408 if (timeout_us > 0) { | 415 if (timeout_us > 0) { |
409 client()->epoll_server()->set_timeout_in_us(timeout_us); | 416 epoll_server()->set_timeout_in_us(timeout_us); |
410 } | 417 } |
411 const QuicClock* clock = | 418 const QuicClock* clock = |
412 QuicConnectionPeer::GetHelper(client()->session()->connection())-> | 419 QuicConnectionPeer::GetHelper(client()->session()->connection())-> |
413 GetClock(); | 420 GetClock(); |
414 QuicTime end_waiting_time = clock->Now().Add( | 421 QuicTime end_waiting_time = clock->Now().Add( |
415 QuicTime::Delta::FromMicroseconds(timeout_us)); | 422 QuicTime::Delta::FromMicroseconds(timeout_us)); |
416 while (stream_ != NULL && | 423 while (stream_ != NULL && |
417 !client_->session()->IsClosedStream(stream_->id()) && | 424 !client_->session()->IsClosedStream(stream_->id()) && |
418 (timeout_us < 0 || clock->Now() < end_waiting_time)) { | 425 (timeout_us < 0 || clock->Now() < end_waiting_time)) { |
419 client_->WaitForEvents(); | 426 client_->WaitForEvents(); |
420 } | 427 } |
421 if (timeout_us > 0) { | 428 if (timeout_us > 0) { |
422 client()->epoll_server()->set_timeout_in_us(old_timeout_us); | 429 epoll_server()->set_timeout_in_us(old_timeout_us); |
423 } | 430 } |
424 } | 431 } |
425 | 432 |
426 void QuicTestClient::WaitForInitialResponseForMs(int timeout_ms) { | 433 void QuicTestClient::WaitForInitialResponseForMs(int timeout_ms) { |
427 int64 timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; | 434 int64 timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; |
428 int64 old_timeout_us = client()->epoll_server()->timeout_in_us(); | 435 int64 old_timeout_us = epoll_server()->timeout_in_us(); |
429 if (timeout_us > 0) { | 436 if (timeout_us > 0) { |
430 client()->epoll_server()->set_timeout_in_us(timeout_us); | 437 epoll_server()->set_timeout_in_us(timeout_us); |
431 } | 438 } |
432 const QuicClock* clock = | 439 const QuicClock* clock = |
433 QuicConnectionPeer::GetHelper(client()->session()->connection())-> | 440 QuicConnectionPeer::GetHelper(client()->session()->connection())-> |
434 GetClock(); | 441 GetClock(); |
435 QuicTime end_waiting_time = clock->Now().Add( | 442 QuicTime end_waiting_time = clock->Now().Add( |
436 QuicTime::Delta::FromMicroseconds(timeout_us)); | 443 QuicTime::Delta::FromMicroseconds(timeout_us)); |
437 while (stream_ != NULL && | 444 while (stream_ != NULL && |
438 !client_->session()->IsClosedStream(stream_->id()) && | 445 !client_->session()->IsClosedStream(stream_->id()) && |
439 stream_->stream_bytes_read() == 0 && | 446 stream_->stream_bytes_read() == 0 && |
440 (timeout_us < 0 || clock->Now() < end_waiting_time)) { | 447 (timeout_us < 0 || clock->Now() < end_waiting_time)) { |
441 client_->WaitForEvents(); | 448 client_->WaitForEvents(); |
442 } | 449 } |
443 if (timeout_us > 0) { | 450 if (timeout_us > 0) { |
444 client()->epoll_server()->set_timeout_in_us(old_timeout_us); | 451 epoll_server()->set_timeout_in_us(old_timeout_us); |
445 } | 452 } |
446 } | 453 } |
447 | 454 |
448 ssize_t QuicTestClient::Send(const void *buffer, size_t size) { | 455 ssize_t QuicTestClient::Send(const void *buffer, size_t size) { |
449 return SendData(string(static_cast<const char*>(buffer), size), false); | 456 return SendData(string(static_cast<const char*>(buffer), size), false); |
450 } | 457 } |
451 | 458 |
452 bool QuicTestClient::response_headers_complete() const { | 459 bool QuicTestClient::response_headers_complete() const { |
453 if (stream_ != NULL) { | 460 if (stream_ != NULL) { |
454 return stream_->headers_decompressed(); | 461 return stream_->headers_decompressed(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // Set policy for headers and crypto streams. | 557 // Set policy for headers and crypto streams. |
551 ReliableQuicStreamPeer::SetFecPolicy( | 558 ReliableQuicStreamPeer::SetFecPolicy( |
552 QuicSessionPeer::GetHeadersStream(client()->session()), fec_policy); | 559 QuicSessionPeer::GetHeadersStream(client()->session()), fec_policy); |
553 ReliableQuicStreamPeer::SetFecPolicy(client()->session()->GetCryptoStream(), | 560 ReliableQuicStreamPeer::SetFecPolicy(client()->session()->GetCryptoStream(), |
554 fec_policy); | 561 fec_policy); |
555 } | 562 } |
556 | 563 |
557 } // namespace test | 564 } // namespace test |
558 } // namespace tools | 565 } // namespace tools |
559 } // namespace net | 566 } // namespace net |
OLD | NEW |