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

Side by Side Diff: net/tools/quic/quic_simple_client.cc

Issue 2363393004: Remove usage of BalsaHeaders from QuicClient. Also move QuicDataToResend from QuicClient to QuicCli… (Closed)
Patch Set: Fix win Created 4 years, 2 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
« no previous file with comments | « net/tools/quic/quic_simple_client.h ('k') | net/tools/quic/quic_simple_client_bin.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/quic_simple_client.h" 5 #include "net/tools/quic/quic_simple_client.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 10 matching lines...) Expand all
21 #include "net/quic/core/quic_flags.h" 21 #include "net/quic/core/quic_flags.h"
22 #include "net/quic/core/quic_protocol.h" 22 #include "net/quic/core/quic_protocol.h"
23 #include "net/quic/core/quic_server_id.h" 23 #include "net/quic/core/quic_server_id.h"
24 #include "net/quic/core/spdy_utils.h" 24 #include "net/quic/core/spdy_utils.h"
25 #include "net/spdy/spdy_header_block.h" 25 #include "net/spdy/spdy_header_block.h"
26 #include "net/spdy/spdy_http_utils.h" 26 #include "net/spdy/spdy_http_utils.h"
27 #include "net/udp/udp_client_socket.h" 27 #include "net/udp/udp_client_socket.h"
28 28
29 using std::string; 29 using std::string;
30 using std::vector; 30 using std::vector;
31 using base::StringPiece;
31 32
32 namespace net { 33 namespace net {
33 34
34 void QuicSimpleClient::ClientQuicDataToResend::Resend() { 35 void QuicSimpleClient::ClientQuicDataToResend::Resend() {
35 client_->SendRequest(*headers_, body_, fin_); 36 client_->SendRequest(*headers_, body_, fin_);
36 delete headers_;
37 headers_ = nullptr; 37 headers_ = nullptr;
38 } 38 }
39 39
40 QuicSimpleClient::QuicSimpleClient( 40 QuicSimpleClient::QuicSimpleClient(
41 IPEndPoint server_address, 41 IPEndPoint server_address,
42 const QuicServerId& server_id, 42 const QuicServerId& server_id,
43 const QuicVersionVector& supported_versions, 43 const QuicVersionVector& supported_versions,
44 std::unique_ptr<ProofVerifier> proof_verifier) 44 std::unique_ptr<ProofVerifier> proof_verifier)
45 : QuicClientBase(server_id, 45 : QuicClientBase(server_id,
46 supported_versions, 46 supported_versions,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 QuicClientBase::Initialize(); 86 QuicClientBase::Initialize();
87 87
88 if (!CreateUDPSocket()) { 88 if (!CreateUDPSocket()) {
89 return false; 89 return false;
90 } 90 }
91 91
92 initialized_ = true; 92 initialized_ = true;
93 return true; 93 return true;
94 } 94 }
95 95
96 QuicSimpleClient::QuicDataToResend::QuicDataToResend(HttpRequestInfo* headers,
97 base::StringPiece body,
98 bool fin)
99 : headers_(headers), body_(body), fin_(fin) {}
100
101 QuicSimpleClient::QuicDataToResend::~QuicDataToResend() {
102 if (headers_) {
103 delete headers_;
104 }
105 }
106
107 bool QuicSimpleClient::CreateUDPSocket() { 96 bool QuicSimpleClient::CreateUDPSocket() {
108 std::unique_ptr<UDPClientSocket> socket( 97 std::unique_ptr<UDPClientSocket> socket(
109 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), 98 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(),
110 &net_log_, NetLog::Source())); 99 &net_log_, NetLog::Source()));
111 100
112 int address_family = server_address_.GetSockAddrFamily(); 101 int address_family = server_address_.GetSockAddrFamily();
113 if (bind_to_address_.size() != 0) { 102 if (bind_to_address_.size() != 0) {
114 client_address_ = IPEndPoint(bind_to_address_, local_port_); 103 client_address_ = IPEndPoint(bind_to_address_, local_port_);
115 } else if (address_family == AF_INET) { 104 } else if (address_family == AF_INET) {
116 client_address_ = IPEndPoint(IPAddress::IPv4AllZeros(), local_port_); 105 client_address_ = IPEndPoint(IPAddress::IPv4AllZeros(), local_port_);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 226 }
238 data_to_resend_on_connect_.clear(); 227 data_to_resend_on_connect_.clear();
239 228
240 reset_writer(); 229 reset_writer();
241 packet_reader_.reset(); 230 packet_reader_.reset();
242 packet_reader_started_ = false; 231 packet_reader_started_ = false;
243 232
244 initialized_ = false; 233 initialized_ = false;
245 } 234 }
246 235
247 void QuicSimpleClient::SendRequest(const HttpRequestInfo& headers, 236 void QuicSimpleClient::SendRequest(const SpdyHeaderBlock& headers,
248 base::StringPiece body, 237 StringPiece body,
249 bool fin) { 238 bool fin) {
250 QuicSpdyClientStream* stream = CreateReliableClientStream(); 239 QuicSpdyClientStream* stream = CreateReliableClientStream();
251 if (stream == nullptr) { 240 if (stream == nullptr) {
252 LOG(DFATAL) << "stream creation failed!"; 241 LOG(DFATAL) << "stream creation failed!";
253 return; 242 return;
254 } 243 }
255 SpdyHeaderBlock header_block;
256 CreateSpdyHeadersFromHttpRequest(headers, headers.extra_headers, true,
257 &header_block);
258 stream->set_visitor(this); 244 stream->set_visitor(this);
259 stream->SendRequest(std::move(header_block), body, fin); 245 stream->SendRequest(headers.Clone(), body, fin);
260 if (FLAGS_enable_quic_stateless_reject_support) { 246 if (FLAGS_enable_quic_stateless_reject_support) {
261 // Record this in case we need to resend. 247 // Record this in case we need to resend.
262 auto* new_headers = new HttpRequestInfo; 248 std::unique_ptr<SpdyHeaderBlock> new_headers(
263 *new_headers = headers; 249 new SpdyHeaderBlock(headers.Clone()));
264 auto* data_to_resend = 250 auto data_to_resend =
265 new ClientQuicDataToResend(new_headers, body, fin, this); 251 new ClientQuicDataToResend(std::move(new_headers), body, fin, this);
266 MaybeAddQuicDataToResend(std::unique_ptr<QuicDataToResend>(data_to_resend)); 252 MaybeAddQuicDataToResend(std::unique_ptr<QuicDataToResend>(data_to_resend));
267 } 253 }
268 } 254 }
269 255
270 void QuicSimpleClient::MaybeAddQuicDataToResend( 256 void QuicSimpleClient::MaybeAddQuicDataToResend(
271 std::unique_ptr<QuicDataToResend> data_to_resend) { 257 std::unique_ptr<QuicDataToResend> data_to_resend) {
272 DCHECK(FLAGS_enable_quic_stateless_reject_support); 258 DCHECK(FLAGS_enable_quic_stateless_reject_support);
273 if (session()->IsCryptoHandshakeConfirmed()) { 259 if (session()->IsCryptoHandshakeConfirmed()) {
274 // The handshake is confirmed. No need to continue saving requests to 260 // The handshake is confirmed. No need to continue saving requests to
275 // resend. 261 // resend.
276 data_to_resend_on_connect_.clear(); 262 data_to_resend_on_connect_.clear();
277 return; 263 return;
278 } 264 }
279 265
280 // The handshake is not confirmed. Push the data onto the queue of data to 266 // The handshake is not confirmed. Push the data onto the queue of data to
281 // resend if statelessly rejected. 267 // resend if statelessly rejected.
282 data_to_resend_on_connect_.push_back(std::move(data_to_resend)); 268 data_to_resend_on_connect_.push_back(std::move(data_to_resend));
283 } 269 }
284 270
285 void QuicSimpleClient::SendRequestAndWaitForResponse( 271 void QuicSimpleClient::SendRequestAndWaitForResponse(
286 const HttpRequestInfo& request, 272 const SpdyHeaderBlock& headers,
287 base::StringPiece body, 273 base::StringPiece body,
288 bool fin) { 274 bool fin) {
289 SendRequest(request, body, fin); 275 SendRequest(headers, body, fin);
290 while (WaitForEvents()) { 276 while (WaitForEvents()) {
291 } 277 }
292 } 278 }
293 279
294 void QuicSimpleClient::SendRequestsAndWaitForResponse( 280 void QuicSimpleClient::SendRequestsAndWaitForResponse(
295 const base::CommandLine::StringVector& url_list) { 281 const base::CommandLine::StringVector& url_list) {
296 for (size_t i = 0; i < url_list.size(); ++i) { 282 for (size_t i = 0; i < url_list.size(); ++i) {
297 HttpRequestInfo request; 283 string url = GURL(url_list[i]).spec();
298 request.method = "GET"; 284 SpdyHeaderBlock headers;
299 request.url = GURL(url_list[i]); 285 if (!SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers)) {
300 SendRequest(request, "", true); 286 QUIC_BUG << "Unable to create request";
287 continue;
288 }
289 SendRequest(headers, "", true);
301 } 290 }
302 291
303 while (WaitForEvents()) { 292 while (WaitForEvents()) {
304 } 293 }
305 } 294 }
306 295
307 bool QuicSimpleClient::WaitForEvents() { 296 bool QuicSimpleClient::WaitForEvents() {
308 DCHECK(connected()); 297 DCHECK(connected());
309 298
310 base::RunLoop().RunUntilIdle(); 299 base::RunLoop().RunUntilIdle();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 session()->connection()->ProcessUdpPacket(local_address, peer_address, 392 session()->connection()->ProcessUdpPacket(local_address, peer_address,
404 packet); 393 packet);
405 if (!session()->connection()->connected()) { 394 if (!session()->connection()->connected()) {
406 return false; 395 return false;
407 } 396 }
408 397
409 return true; 398 return true;
410 } 399 }
411 400
412 } // namespace net 401 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_client.h ('k') | net/tools/quic/quic_simple_client_bin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698