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

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

Issue 995423003: Add a chromium based simple QUIC client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix iOS Created 5 years, 9 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_client.h ('k') | net/tools/quic/quic_simple_client.h » ('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_client.h" 5 #include "net/tools/quic/quic_client.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <netinet/in.h> 8 #include <netinet/in.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "net/quic/crypto/quic_random.h" 14 #include "net/quic/crypto/quic_random.h"
15 #include "net/quic/quic_connection.h" 15 #include "net/quic/quic_connection.h"
16 #include "net/quic/quic_data_reader.h" 16 #include "net/quic/quic_data_reader.h"
17 #include "net/quic/quic_protocol.h" 17 #include "net/quic/quic_protocol.h"
18 #include "net/quic/quic_server_id.h" 18 #include "net/quic/quic_server_id.h"
19 #include "net/tools/balsa/balsa_headers.h" 19 #include "net/tools/balsa/balsa_headers.h"
20 #include "net/tools/epoll_server/epoll_server.h" 20 #include "net/tools/epoll_server/epoll_server.h"
21 #include "net/tools/quic/quic_epoll_connection_helper.h" 21 #include "net/tools/quic/quic_epoll_connection_helper.h"
22 #include "net/tools/quic/quic_socket_utils.h" 22 #include "net/tools/quic/quic_socket_utils.h"
23 #include "net/tools/quic/quic_spdy_client_stream.h" 23 #include "net/tools/quic/quic_spdy_client_stream.h"
24 24
25 #ifndef SO_RXQ_OVFL 25 #ifndef SO_RXQ_OVFL
26 #define SO_RXQ_OVFL 40 26 #define SO_RXQ_OVFL 40
27 #endif 27 #endif
28 28
29 using std::string; 29 using std::string;
30 using std::vector;
30 31
31 namespace net { 32 namespace net {
32 namespace tools { 33 namespace tools {
33 34
34 const PollBits kEpollFlags = PollBits(NET_POLLIN | NET_POLLOUT | NET_POLLET); 35 const PollBits kEpollFlags = PollBits(NET_POLLIN | NET_POLLOUT | NET_POLLET);
35 36
36 QuicClient::QuicClient(IPEndPoint server_address, 37 QuicClient::QuicClient(IPEndPoint server_address,
37 const QuicServerId& server_id, 38 const QuicServerId& server_id,
38 const QuicVersionVector& supported_versions, 39 const QuicVersionVector& supported_versions,
39 EpollServer* epoll_server) 40 EpollServer* epoll_server)
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 bool fin) { 246 bool fin) {
246 QuicSpdyClientStream* stream = CreateReliableClientStream(); 247 QuicSpdyClientStream* stream = CreateReliableClientStream();
247 if (stream == nullptr) { 248 if (stream == nullptr) {
248 LOG(DFATAL) << "stream creation failed!"; 249 LOG(DFATAL) << "stream creation failed!";
249 return; 250 return;
250 } 251 }
251 stream->SendRequest(headers, body, fin); 252 stream->SendRequest(headers, body, fin);
252 stream->set_visitor(this); 253 stream->set_visitor(this);
253 } 254 }
254 255
255 void QuicClient::SendRequestAndWaitForResponse(const BalsaHeaders& headers, 256 void QuicClient::SendRequestAndWaitForResponse(
256 StringPiece body, 257 const BalsaHeaders& headers,
257 bool fin) { 258 StringPiece body,
258 SendRequest(headers, "", true); 259 bool fin) {
259 while (WaitForEvents()) { 260 SendRequest(headers, body, fin);
260 } 261 while (WaitForEvents()) {}
261 } 262 }
262 263
263 void QuicClient::SendRequestsAndWaitForResponse( 264 void QuicClient::SendRequestsAndWaitForResponse(
264 const base::CommandLine::StringVector& args) { 265 const vector<string>& url_list) {
265 for (size_t i = 0; i < args.size(); ++i) { 266 for (size_t i = 0; i < url_list.size(); ++i) {
266 BalsaHeaders headers; 267 BalsaHeaders headers;
267 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); 268 headers.SetRequestFirstlineFromStringPieces("GET", url_list[i], "HTTP/1.1");
268 SendRequest(headers, "", true); 269 SendRequest(headers, "", true);
269 } 270 }
270 while (WaitForEvents()) {} 271 while (WaitForEvents()) {}
271 } 272 }
272 273
273 QuicSpdyClientStream* QuicClient::CreateReliableClientStream() { 274 QuicSpdyClientStream* QuicClient::CreateReliableClientStream() {
274 if (!connected()) { 275 if (!connected()) {
275 return nullptr; 276 return nullptr;
276 } 277 }
277 278
278 return session_->CreateOutgoingDataStream(); 279 return session_->CreateOutgoingDataStream();
279 } 280 }
280 281
281 void QuicClient::WaitForStreamToClose(QuicStreamId id) { 282 void QuicClient::WaitForStreamToClose(QuicStreamId id) {
282 DCHECK(connected()); 283 DCHECK(connected());
283 284
284 while (connected() && !session_->IsClosedStream(id)) { 285 while (connected() && !session_->IsClosedStream(id)) {
285 epoll_server_->WaitForEventsAndExecuteCallbacks(); 286 WaitForEvents();
286 } 287 }
287 } 288 }
288 289
289 void QuicClient::WaitForCryptoHandshakeConfirmed() { 290 void QuicClient::WaitForCryptoHandshakeConfirmed() {
290 DCHECK(connected()); 291 DCHECK(connected());
291 292
292 while (connected() && !session_->IsCryptoHandshakeConfirmed()) { 293 while (connected() && !session_->IsCryptoHandshakeConfirmed()) {
293 epoll_server_->WaitForEventsAndExecuteCallbacks(); 294 WaitForEvents();
294 } 295 }
295 } 296 }
296 297
297 bool QuicClient::WaitForEvents() { 298 bool QuicClient::WaitForEvents() {
298 DCHECK(connected()); 299 DCHECK(connected());
299 300
300 epoll_server_->WaitForEventsAndExecuteCallbacks(); 301 epoll_server_->WaitForEventsAndExecuteCallbacks();
301 return session_->num_active_requests() != 0; 302 return session_->num_active_requests() != 0;
302 } 303 }
303 304
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 QuicEncryptedPacket packet(buf, bytes_read, false); 397 QuicEncryptedPacket packet(buf, bytes_read, false);
397 398
398 IPEndPoint client_address(client_ip, client_address_.port()); 399 IPEndPoint client_address(client_ip, client_address_.port());
399 session_->connection()->ProcessUdpPacket( 400 session_->connection()->ProcessUdpPacket(
400 client_address, server_address, packet); 401 client_address, server_address, packet);
401 return true; 402 return true;
402 } 403 }
403 404
404 } // namespace tools 405 } // namespace tools
405 } // namespace net 406 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_client.h ('k') | net/tools/quic/quic_simple_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698