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/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; | |
31 | 30 |
32 namespace net { | 31 namespace net { |
33 namespace tools { | 32 namespace tools { |
34 | 33 |
35 const PollBits kEpollFlags = PollBits(NET_POLLIN | NET_POLLOUT | NET_POLLET); | 34 const PollBits kEpollFlags = PollBits(NET_POLLIN | NET_POLLOUT | NET_POLLET); |
36 | 35 |
37 QuicClient::QuicClient(IPEndPoint server_address, | 36 QuicClient::QuicClient(IPEndPoint server_address, |
38 const QuicServerId& server_id, | 37 const QuicServerId& server_id, |
39 const QuicVersionVector& supported_versions, | 38 const QuicVersionVector& supported_versions, |
40 EpollServer* epoll_server) | 39 EpollServer* epoll_server) |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 bool fin) { | 245 bool fin) { |
247 QuicSpdyClientStream* stream = CreateReliableClientStream(); | 246 QuicSpdyClientStream* stream = CreateReliableClientStream(); |
248 if (stream == nullptr) { | 247 if (stream == nullptr) { |
249 LOG(DFATAL) << "stream creation failed!"; | 248 LOG(DFATAL) << "stream creation failed!"; |
250 return; | 249 return; |
251 } | 250 } |
252 stream->SendRequest(headers, body, fin); | 251 stream->SendRequest(headers, body, fin); |
253 stream->set_visitor(this); | 252 stream->set_visitor(this); |
254 } | 253 } |
255 | 254 |
256 void QuicClient::SendRequestAndWaitForResponse( | 255 void QuicClient::SendRequestAndWaitForResponse(const BalsaHeaders& headers, |
257 const BalsaHeaders& headers, | 256 StringPiece body, |
258 StringPiece body, | 257 bool fin) { |
259 bool fin) { | 258 SendRequest(headers, "", true); |
260 SendRequest(headers, body, fin); | 259 while (WaitForEvents()) { |
261 while (WaitForEvents()) {} | 260 } |
262 } | 261 } |
263 | 262 |
264 void QuicClient::SendRequestsAndWaitForResponse( | 263 void QuicClient::SendRequestsAndWaitForResponse( |
265 const vector<string>& url_list) { | 264 const base::CommandLine::StringVector& args) { |
266 for (size_t i = 0; i < url_list.size(); ++i) { | 265 for (size_t i = 0; i < args.size(); ++i) { |
267 BalsaHeaders headers; | 266 BalsaHeaders headers; |
268 headers.SetRequestFirstlineFromStringPieces("GET", url_list[i], "HTTP/1.1"); | 267 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); |
269 SendRequest(headers, "", true); | 268 SendRequest(headers, "", true); |
270 } | 269 } |
271 while (WaitForEvents()) {} | 270 while (WaitForEvents()) {} |
272 } | 271 } |
273 | 272 |
274 QuicSpdyClientStream* QuicClient::CreateReliableClientStream() { | 273 QuicSpdyClientStream* QuicClient::CreateReliableClientStream() { |
275 if (!connected()) { | 274 if (!connected()) { |
276 return nullptr; | 275 return nullptr; |
277 } | 276 } |
278 | 277 |
279 return session_->CreateOutgoingDataStream(); | 278 return session_->CreateOutgoingDataStream(); |
280 } | 279 } |
281 | 280 |
282 void QuicClient::WaitForStreamToClose(QuicStreamId id) { | 281 void QuicClient::WaitForStreamToClose(QuicStreamId id) { |
283 DCHECK(connected()); | 282 DCHECK(connected()); |
284 | 283 |
285 while (connected() && !session_->IsClosedStream(id)) { | 284 while (connected() && !session_->IsClosedStream(id)) { |
286 WaitForEvents(); | 285 epoll_server_->WaitForEventsAndExecuteCallbacks(); |
287 } | 286 } |
288 } | 287 } |
289 | 288 |
290 void QuicClient::WaitForCryptoHandshakeConfirmed() { | 289 void QuicClient::WaitForCryptoHandshakeConfirmed() { |
291 DCHECK(connected()); | 290 DCHECK(connected()); |
292 | 291 |
293 while (connected() && !session_->IsCryptoHandshakeConfirmed()) { | 292 while (connected() && !session_->IsCryptoHandshakeConfirmed()) { |
294 WaitForEvents(); | 293 epoll_server_->WaitForEventsAndExecuteCallbacks(); |
295 } | 294 } |
296 } | 295 } |
297 | 296 |
298 bool QuicClient::WaitForEvents() { | 297 bool QuicClient::WaitForEvents() { |
299 DCHECK(connected()); | 298 DCHECK(connected()); |
300 | 299 |
301 epoll_server_->WaitForEventsAndExecuteCallbacks(); | 300 epoll_server_->WaitForEventsAndExecuteCallbacks(); |
302 return session_->num_active_requests() != 0; | 301 return session_->num_active_requests() != 0; |
303 } | 302 } |
304 | 303 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 QuicEncryptedPacket packet(buf, bytes_read, false); | 396 QuicEncryptedPacket packet(buf, bytes_read, false); |
398 | 397 |
399 IPEndPoint client_address(client_ip, client_address_.port()); | 398 IPEndPoint client_address(client_ip, client_address_.port()); |
400 session_->connection()->ProcessUdpPacket( | 399 session_->connection()->ProcessUdpPacket( |
401 client_address, server_address, packet); | 400 client_address, server_address, packet); |
402 return true; | 401 return true; |
403 } | 402 } |
404 | 403 |
405 } // namespace tools | 404 } // namespace tools |
406 } // namespace net | 405 } // namespace net |
OLD | NEW |