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

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

Issue 103973007: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for android compile error Created 7 years 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
OLDNEW
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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 stream_ = NULL; // Always force creation of a stream for SendMessage. 208 stream_ = NULL; // Always force creation of a stream for SendMessage.
209 209
210 // If we're not connected, try to find an sni hostname. 210 // If we're not connected, try to find an sni hostname.
211 if (!connected()) { 211 if (!connected()) {
212 GURL url(message.headers()->request_uri().as_string()); 212 GURL url(message.headers()->request_uri().as_string());
213 if (!url.host().empty()) { 213 if (!url.host().empty()) {
214 client_->set_server_hostname(url.host()); 214 client_->set_server_hostname(url.host());
215 } 215 }
216 } 216 }
217 217
218 QuicReliableClientStream* stream = GetOrCreateStream(); 218 QuicSpdyClientStream* stream = GetOrCreateStream();
219 if (!stream) { return 0; } 219 if (!stream) { return 0; }
220 220
221 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), 221 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(),
222 secure_)); 222 secure_));
223 ssize_t ret = GetOrCreateStream()->SendRequest( 223 ssize_t ret = GetOrCreateStream()->SendRequest(
224 munged_headers.get() ? *munged_headers.get() : *message.headers(), 224 munged_headers.get() ? *munged_headers.get() : *message.headers(),
225 message.body(), 225 message.body(),
226 message.has_complete_message()); 226 message.has_complete_message());
227 WaitForWriteToFlush(); 227 WaitForWriteToFlush();
228 return ret; 228 return ret;
229 } 229 }
230 230
231 ssize_t QuicTestClient::SendData(string data, bool last_data) { 231 ssize_t QuicTestClient::SendData(string data, bool last_data) {
232 QuicReliableClientStream* stream = GetOrCreateStream(); 232 QuicSpdyClientStream* stream = GetOrCreateStream();
233 if (!stream) { return 0; } 233 if (!stream) { return 0; }
234 GetOrCreateStream()->SendBody(data, last_data); 234 GetOrCreateStream()->SendBody(data, last_data);
235 WaitForWriteToFlush(); 235 WaitForWriteToFlush();
236 return data.length(); 236 return data.length();
237 } 237 }
238 238
239 string QuicTestClient::SendCustomSynchronousRequest( 239 string QuicTestClient::SendCustomSynchronousRequest(
240 const HTTPMessage& message) { 240 const HTTPMessage& message) {
241 SendMessage(message); 241 SendMessage(message);
242 WaitForResponse(); 242 WaitForResponse();
243 return response_; 243 return response_;
244 } 244 }
245 245
246 string QuicTestClient::SendSynchronousRequest(const string& uri) { 246 string QuicTestClient::SendSynchronousRequest(const string& uri) {
247 if (SendRequest(uri) == 0) { 247 if (SendRequest(uri) == 0) {
248 DLOG(ERROR) << "Failed the request for uri:" << uri; 248 DLOG(ERROR) << "Failed the request for uri:" << uri;
249 return ""; 249 return "";
250 } 250 }
251 WaitForResponse(); 251 WaitForResponse();
252 return response_; 252 return response_;
253 } 253 }
254 254
255 QuicReliableClientStream* QuicTestClient::GetOrCreateStream() { 255 QuicSpdyClientStream* QuicTestClient::GetOrCreateStream() {
256 if (!connect_attempted_ || auto_reconnect_) { 256 if (!connect_attempted_ || auto_reconnect_) {
257 if (!connected()) { 257 if (!connected()) {
258 Connect(); 258 Connect();
259 } 259 }
260 if (!connected()) { 260 if (!connected()) {
261 return NULL; 261 return NULL;
262 } 262 }
263 } 263 }
264 if (!stream_) { 264 if (!stream_) {
265 stream_ = client_->CreateReliableClientStream(); 265 stream_ = client_->CreateReliableClientStream();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 } 394 }
395 395
396 size_t QuicTestClient::bytes_read() const { 396 size_t QuicTestClient::bytes_read() const {
397 return bytes_read_; 397 return bytes_read_;
398 } 398 }
399 399
400 size_t QuicTestClient::bytes_written() const { 400 size_t QuicTestClient::bytes_written() const {
401 return bytes_written_; 401 return bytes_written_;
402 } 402 }
403 403
404 void QuicTestClient::OnClose(ReliableQuicStream* stream) { 404 void QuicTestClient::OnClose(QuicDataStream* stream) {
405 if (stream_ != stream) { 405 if (stream_ != stream) {
406 return; 406 return;
407 } 407 }
408 if (buffer_body()) { 408 if (buffer_body()) {
409 // TODO(fnk): The stream still buffers the whole thing. Fix that. 409 // TODO(fnk): The stream still buffers the whole thing. Fix that.
410 response_ = stream_->data(); 410 response_ = stream_->data();
411 } 411 }
412 response_complete_ = true; 412 response_complete_ = true;
413 response_headers_complete_ = stream_->headers_decompressed(); 413 response_headers_complete_ = stream_->headers_decompressed();
414 headers_.CopyFrom(stream_->headers()); 414 headers_.CopyFrom(stream_->headers());
(...skipping 16 matching lines...) Expand all
431 431
432 void QuicTestClient::WaitForWriteToFlush() { 432 void QuicTestClient::WaitForWriteToFlush() {
433 while (connected() && client()->session()->HasQueuedData()) { 433 while (connected() && client()->session()->HasQueuedData()) {
434 client_->WaitForEvents(); 434 client_->WaitForEvents();
435 } 435 }
436 } 436 }
437 437
438 } // namespace test 438 } // namespace test
439 } // namespace tools 439 } // namespace tools
440 } // namespace net 440 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/quic_test_client.h ('k') | net/tools/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698