| 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/epoll.h> | 10 #include <sys/epoll.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/quic/quic_protocol.h" | 22 #include "net/quic/quic_protocol.h" |
| 23 #include "net/quic/quic_server_id.h" | 23 #include "net/quic/quic_server_id.h" |
| 24 #include "net/tools/quic/quic_epoll_connection_helper.h" | 24 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 25 #include "net/tools/quic/quic_socket_utils.h" | 25 #include "net/tools/quic/quic_socket_utils.h" |
| 26 #include "net/tools/quic/spdy_balsa_utils.h" | 26 #include "net/tools/quic/spdy_balsa_utils.h" |
| 27 | 27 |
| 28 #ifndef SO_RXQ_OVFL | 28 #ifndef SO_RXQ_OVFL |
| 29 #define SO_RXQ_OVFL 40 | 29 #define SO_RXQ_OVFL 40 |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 // TODO(rtenneti): Add support for MMSG_MORE. |
| 33 #define MMSG_MORE 0 |
| 34 |
| 32 using std::string; | 35 using std::string; |
| 33 using std::vector; | 36 using std::vector; |
| 34 | 37 |
| 35 namespace net { | 38 namespace net { |
| 36 namespace tools { | 39 namespace tools { |
| 37 | 40 |
| 38 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; | 41 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; |
| 39 | 42 |
| 40 void QuicClient::ClientQuicDataToResend::Resend() { | 43 void QuicClient::ClientQuicDataToResend::Resend() { |
| 41 client_->SendRequest(*headers_, body_, fin_); | 44 client_->SendRequest(*headers_, body_, fin_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 66 config, | 69 config, |
| 67 new QuicEpollConnectionHelper(epoll_server), | 70 new QuicEpollConnectionHelper(epoll_server), |
| 68 proof_verifier), | 71 proof_verifier), |
| 69 server_address_(server_address), | 72 server_address_(server_address), |
| 70 local_port_(0), | 73 local_port_(0), |
| 71 epoll_server_(epoll_server), | 74 epoll_server_(epoll_server), |
| 72 initialized_(false), | 75 initialized_(false), |
| 73 packets_dropped_(0), | 76 packets_dropped_(0), |
| 74 overflow_supported_(false), | 77 overflow_supported_(false), |
| 75 store_response_(false), | 78 store_response_(false), |
| 76 latest_response_code_(-1) {} | 79 latest_response_code_(-1), |
| 80 packet_reader_(CreateQuicPacketReader()) {} |
| 77 | 81 |
| 78 QuicClient::~QuicClient() { | 82 QuicClient::~QuicClient() { |
| 79 if (connected()) { | 83 if (connected()) { |
| 80 session()->connection()->SendConnectionCloseWithDetails( | 84 session()->connection()->SendConnectionCloseWithDetails( |
| 81 QUIC_PEER_GOING_AWAY, "Client being torn down"); | 85 QUIC_PEER_GOING_AWAY, "Client being torn down"); |
| 82 } | 86 } |
| 83 | 87 |
| 84 STLDeleteElements(&data_to_resend_on_connect_); | 88 STLDeleteElements(&data_to_resend_on_connect_); |
| 85 STLDeleteElements(&data_sent_before_handshake_); | 89 STLDeleteElements(&data_sent_before_handshake_); |
| 86 | 90 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 set_writer(writer); | 389 set_writer(writer); |
| 386 session()->connection()->SetQuicPacketWriter(writer, false); | 390 session()->connection()->SetQuicPacketWriter(writer, false); |
| 387 | 391 |
| 388 return true; | 392 return true; |
| 389 } | 393 } |
| 390 | 394 |
| 391 void QuicClient::OnEvent(int fd, EpollEvent* event) { | 395 void QuicClient::OnEvent(int fd, EpollEvent* event) { |
| 392 DCHECK_EQ(fd, GetLatestFD()); | 396 DCHECK_EQ(fd, GetLatestFD()); |
| 393 | 397 |
| 394 if (event->in_events & EPOLLIN) { | 398 if (event->in_events & EPOLLIN) { |
| 395 while (connected() && ReadAndProcessPacket()) { | 399 while (connected()) { |
| 400 if ( |
| 401 #if MMSG_MORE |
| 402 !ReadAndProcessPackets() |
| 403 #else |
| 404 !ReadAndProcessPacket() |
| 405 #endif |
| 406 ) { |
| 407 break; |
| 408 } |
| 396 } | 409 } |
| 397 } | 410 } |
| 398 if (connected() && (event->in_events & EPOLLOUT)) { | 411 if (connected() && (event->in_events & EPOLLOUT)) { |
| 399 writer()->SetWritable(); | 412 writer()->SetWritable(); |
| 400 session()->connection()->OnCanWrite(); | 413 session()->connection()->OnCanWrite(); |
| 401 } | 414 } |
| 402 if (event->in_events & EPOLLERR) { | 415 if (event->in_events & EPOLLERR) { |
| 403 DVLOG(1) << "Epollerr"; | 416 DVLOG(1) << "Epollerr"; |
| 404 } | 417 } |
| 405 } | 418 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 456 |
| 444 const string& QuicClient::latest_response_trailers() const { | 457 const string& QuicClient::latest_response_trailers() const { |
| 445 QUIC_BUG_IF(!store_response_) << "Response not stored!"; | 458 QUIC_BUG_IF(!store_response_) << "Response not stored!"; |
| 446 return latest_response_trailers_; | 459 return latest_response_trailers_; |
| 447 } | 460 } |
| 448 | 461 |
| 449 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { | 462 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { |
| 450 return new QuicDefaultPacketWriter(GetLatestFD()); | 463 return new QuicDefaultPacketWriter(GetLatestFD()); |
| 451 } | 464 } |
| 452 | 465 |
| 466 QuicPacketReader* QuicClient::CreateQuicPacketReader() { |
| 467 return new QuicPacketReader(); |
| 468 } |
| 469 |
| 453 int QuicClient::ReadPacket(char* buffer, | 470 int QuicClient::ReadPacket(char* buffer, |
| 454 int buffer_len, | 471 int buffer_len, |
| 455 IPEndPoint* server_address, | 472 IPEndPoint* server_address, |
| 456 IPAddressNumber* client_ip) { | 473 IPAddressNumber* client_ip) { |
| 457 return QuicSocketUtils::ReadPacket( | 474 return QuicSocketUtils::ReadPacket( |
| 458 GetLatestFD(), buffer, buffer_len, | 475 GetLatestFD(), buffer, buffer_len, |
| 459 overflow_supported_ ? &packets_dropped_ : nullptr, client_ip, | 476 overflow_supported_ ? &packets_dropped_ : nullptr, client_ip, |
| 460 server_address); | 477 server_address); |
| 461 } | 478 } |
| 462 | 479 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 518 } |
| 502 | 519 |
| 503 int QuicClient::GetLatestFD() const { | 520 int QuicClient::GetLatestFD() const { |
| 504 if (fd_address_map_.empty()) { | 521 if (fd_address_map_.empty()) { |
| 505 return -1; | 522 return -1; |
| 506 } | 523 } |
| 507 | 524 |
| 508 return fd_address_map_.back().first; | 525 return fd_address_map_.back().first; |
| 509 } | 526 } |
| 510 | 527 |
| 528 void QuicClient::ProcessPacket(const IPEndPoint& self_address, |
| 529 const IPEndPoint& peer_address, |
| 530 const QuicEncryptedPacket& packet) { |
| 531 session()->connection()->ProcessUdpPacket(self_address, peer_address, packet); |
| 532 } |
| 533 |
| 511 } // namespace tools | 534 } // namespace tools |
| 512 } // namespace net | 535 } // namespace net |
| OLD | NEW |