| 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> |
| 11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 16 #include "net/quic/crypto/quic_random.h" | 16 #include "net/quic/crypto/quic_random.h" |
| 17 #include "net/quic/quic_connection.h" | 17 #include "net/quic/quic_connection.h" |
| 18 #include "net/quic/quic_data_reader.h" | 18 #include "net/quic/quic_data_reader.h" |
| 19 #include "net/quic/quic_flags.h" | 19 #include "net/quic/quic_flags.h" |
| 20 #include "net/quic/quic_protocol.h" | 20 #include "net/quic/quic_protocol.h" |
| 21 #include "net/quic/quic_server_id.h" | 21 #include "net/quic/quic_server_id.h" |
| 22 #include "net/tools/quic/quic_epoll_connection_helper.h" | 22 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 23 #include "net/tools/quic/quic_socket_utils.h" | 23 #include "net/tools/quic/quic_socket_utils.h" |
| 24 #include "net/tools/quic/spdy_balsa_utils.h" | 24 #include "net/tools/quic/spdy_balsa_utils.h" |
| 25 | 25 |
| 26 #ifndef SO_RXQ_OVFL | 26 #ifndef SO_RXQ_OVFL |
| 27 #define SO_RXQ_OVFL 40 | 27 #define SO_RXQ_OVFL 40 |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 // TODO(rtenneti): Add support for MMSG_MORE. |
| 31 #define MMSG_MORE 0 |
| 32 |
| 30 using std::string; | 33 using std::string; |
| 31 using std::vector; | 34 using std::vector; |
| 32 | 35 |
| 33 namespace net { | 36 namespace net { |
| 34 namespace tools { | 37 namespace tools { |
| 35 | 38 |
| 36 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; | 39 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; |
| 37 | 40 |
| 38 void QuicClient::ClientQuicDataToResend::Resend() { | 41 void QuicClient::ClientQuicDataToResend::Resend() { |
| 39 client_->SendRequest(*headers_, body_, fin_); | 42 client_->SendRequest(*headers_, body_, fin_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 59 : QuicClientBase(server_id, supported_versions, config), | 62 : QuicClientBase(server_id, supported_versions, config), |
| 60 server_address_(server_address), | 63 server_address_(server_address), |
| 61 local_port_(0), | 64 local_port_(0), |
| 62 epoll_server_(epoll_server), | 65 epoll_server_(epoll_server), |
| 63 fd_(-1), | 66 fd_(-1), |
| 64 helper_(CreateQuicConnectionHelper()), | 67 helper_(CreateQuicConnectionHelper()), |
| 65 initialized_(false), | 68 initialized_(false), |
| 66 packets_dropped_(0), | 69 packets_dropped_(0), |
| 67 overflow_supported_(false), | 70 overflow_supported_(false), |
| 68 store_response_(false), | 71 store_response_(false), |
| 69 latest_response_code_(-1) {} | 72 latest_response_code_(-1), |
| 73 packet_reader_(CreateQuicPacketReader()) {} |
| 70 | 74 |
| 71 QuicClient::~QuicClient() { | 75 QuicClient::~QuicClient() { |
| 72 if (connected()) { | 76 if (connected()) { |
| 73 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); | 77 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); |
| 74 } | 78 } |
| 75 | 79 |
| 76 STLDeleteElements(&data_to_resend_on_connect_); | 80 STLDeleteElements(&data_to_resend_on_connect_); |
| 77 STLDeleteElements(&data_sent_before_handshake_); | 81 STLDeleteElements(&data_sent_before_handshake_); |
| 78 | 82 |
| 79 CleanUpUDPSocketImpl(); | 83 CleanUpUDPSocketImpl(); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 set_writer(writer); | 376 set_writer(writer); |
| 373 session()->connection()->SetQuicPacketWriter(writer, false); | 377 session()->connection()->SetQuicPacketWriter(writer, false); |
| 374 | 378 |
| 375 return true; | 379 return true; |
| 376 } | 380 } |
| 377 | 381 |
| 378 void QuicClient::OnEvent(int fd, EpollEvent* event) { | 382 void QuicClient::OnEvent(int fd, EpollEvent* event) { |
| 379 DCHECK_EQ(fd, fd_); | 383 DCHECK_EQ(fd, fd_); |
| 380 | 384 |
| 381 if (event->in_events & EPOLLIN) { | 385 if (event->in_events & EPOLLIN) { |
| 382 while (connected() && ReadAndProcessPacket()) { | 386 while (connected()) { |
| 387 if ( |
| 388 #if MMSG_MORE |
| 389 !ReadAndProcessPackets() |
| 390 #else |
| 391 !ReadAndProcessPacket() |
| 392 #endif |
| 393 ) { |
| 394 break; |
| 395 } |
| 383 } | 396 } |
| 384 } | 397 } |
| 385 if (connected() && (event->in_events & EPOLLOUT)) { | 398 if (connected() && (event->in_events & EPOLLOUT)) { |
| 386 writer()->SetWritable(); | 399 writer()->SetWritable(); |
| 387 session()->connection()->OnCanWrite(); | 400 session()->connection()->OnCanWrite(); |
| 388 } | 401 } |
| 389 if (event->in_events & EPOLLERR) { | 402 if (event->in_events & EPOLLERR) { |
| 390 DVLOG(1) << "Epollerr"; | 403 DVLOG(1) << "Epollerr"; |
| 391 } | 404 } |
| 392 } | 405 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 441 } |
| 429 | 442 |
| 430 QuicEpollConnectionHelper* QuicClient::CreateQuicConnectionHelper() { | 443 QuicEpollConnectionHelper* QuicClient::CreateQuicConnectionHelper() { |
| 431 return new QuicEpollConnectionHelper(epoll_server_); | 444 return new QuicEpollConnectionHelper(epoll_server_); |
| 432 } | 445 } |
| 433 | 446 |
| 434 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { | 447 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { |
| 435 return new QuicDefaultPacketWriter(fd_); | 448 return new QuicDefaultPacketWriter(fd_); |
| 436 } | 449 } |
| 437 | 450 |
| 451 QuicPacketReader* QuicClient::CreateQuicPacketReader() { |
| 452 return new QuicPacketReader(); |
| 453 } |
| 454 |
| 438 int QuicClient::ReadPacket(char* buffer, | 455 int QuicClient::ReadPacket(char* buffer, |
| 439 int buffer_len, | 456 int buffer_len, |
| 440 IPEndPoint* server_address, | 457 IPEndPoint* server_address, |
| 441 IPAddressNumber* client_ip) { | 458 IPAddressNumber* client_ip) { |
| 442 return QuicSocketUtils::ReadPacket( | 459 return QuicSocketUtils::ReadPacket( |
| 443 fd_, buffer, buffer_len, | 460 fd_, buffer, buffer_len, |
| 444 overflow_supported_ ? &packets_dropped_ : nullptr, client_ip, | 461 overflow_supported_ ? &packets_dropped_ : nullptr, client_ip, |
| 445 server_address); | 462 server_address); |
| 446 } | 463 } |
| 447 | 464 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 460 } | 477 } |
| 461 | 478 |
| 462 QuicEncryptedPacket packet(buf, bytes_read, false); | 479 QuicEncryptedPacket packet(buf, bytes_read, false); |
| 463 | 480 |
| 464 IPEndPoint client_address(client_ip, client_address_.port()); | 481 IPEndPoint client_address(client_ip, client_address_.port()); |
| 465 session()->connection()->ProcessUdpPacket(client_address, server_address, | 482 session()->connection()->ProcessUdpPacket(client_address, server_address, |
| 466 packet); | 483 packet); |
| 467 return true; | 484 return true; |
| 468 } | 485 } |
| 469 | 486 |
| 487 bool QuicClient::ReadAndProcessPackets() { |
| 488 return packet_reader_->ReadAndDispatchPackets( |
| 489 fd_, client_address_.port(), this, |
| 490 overflow_supported_ ? &packets_dropped_ : nullptr); |
| 491 } |
| 492 |
| 493 void QuicClient::ProcessPacket(const IPEndPoint& self_address, |
| 494 const IPEndPoint& peer_address, |
| 495 const QuicEncryptedPacket& packet) { |
| 496 session()->connection()->ProcessUdpPacket(self_address, peer_address, packet); |
| 497 } |
| 498 |
| 470 } // namespace tools | 499 } // namespace tools |
| 471 } // namespace net | 500 } // namespace net |
| OLD | NEW |