| 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" | |
| 15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 16 #include "net/base/sockaddr_storage.h" | 15 #include "net/base/sockaddr_storage.h" |
| 17 #include "net/quic/core/crypto/quic_random.h" | 16 #include "net/quic/core/crypto/quic_random.h" |
| 18 #include "net/quic/core/quic_connection.h" | 17 #include "net/quic/core/quic_connection.h" |
| 19 #include "net/quic/core/quic_data_reader.h" | 18 #include "net/quic/core/quic_data_reader.h" |
| 20 #include "net/quic/core/quic_flags.h" | 19 #include "net/quic/core/quic_flags.h" |
| 21 #include "net/quic/core/quic_packets.h" | 20 #include "net/quic/core/quic_packets.h" |
| 22 #include "net/quic/core/quic_server_id.h" | 21 #include "net/quic/core/quic_server_id.h" |
| 23 #include "net/quic/core/spdy_utils.h" | 22 #include "net/quic/core/spdy_utils.h" |
| 24 #include "net/quic/platform/api/quic_bug_tracker.h" | 23 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 24 #include "net/quic/platform/api/quic_logging.h" |
| 25 #include "net/tools/quic/platform/impl/quic_socket_utils.h" | 25 #include "net/tools/quic/platform/impl/quic_socket_utils.h" |
| 26 #include "net/tools/quic/quic_epoll_alarm_factory.h" | 26 #include "net/tools/quic/quic_epoll_alarm_factory.h" |
| 27 #include "net/tools/quic/quic_epoll_connection_helper.h" | 27 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 28 | 28 |
| 29 #ifndef SO_RXQ_OVFL | 29 #ifndef SO_RXQ_OVFL |
| 30 #define SO_RXQ_OVFL 40 | 30 #define SO_RXQ_OVFL 40 |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 // TODO(rtenneti): Add support for MMSG_MORE. | 33 // TODO(rtenneti): Add support for MMSG_MORE. |
| 34 #define MMSG_MORE 0 | 34 #define MMSG_MORE 0 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 client_address = QuicSocketAddress(bind_to_address, local_port()); | 97 client_address = QuicSocketAddress(bind_to_address, local_port()); |
| 98 } else if (server_address.host().address_family() == IpAddressFamily::IP_V4) { | 98 } else if (server_address.host().address_family() == IpAddressFamily::IP_V4) { |
| 99 client_address = QuicSocketAddress(QuicIpAddress::Any4(), bind_to_port); | 99 client_address = QuicSocketAddress(QuicIpAddress::Any4(), bind_to_port); |
| 100 } else { | 100 } else { |
| 101 client_address = QuicSocketAddress(QuicIpAddress::Any6(), bind_to_port); | 101 client_address = QuicSocketAddress(QuicIpAddress::Any6(), bind_to_port); |
| 102 } | 102 } |
| 103 | 103 |
| 104 sockaddr_storage addr = client_address.generic_address(); | 104 sockaddr_storage addr = client_address.generic_address(); |
| 105 int rc = bind(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)); | 105 int rc = bind(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)); |
| 106 if (rc < 0) { | 106 if (rc < 0) { |
| 107 LOG(ERROR) << "Bind failed: " << strerror(errno); | 107 QUIC_LOG(ERROR) << "Bind failed: " << strerror(errno); |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 | 110 |
| 111 if (client_address.FromSocket(fd) != 0) { | 111 if (client_address.FromSocket(fd) != 0) { |
| 112 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); | 112 QUIC_LOG(ERROR) << "Unable to get self address. Error: " |
| 113 << strerror(errno); |
| 113 } | 114 } |
| 114 | 115 |
| 115 fd_address_map_[fd] = client_address; | 116 fd_address_map_[fd] = client_address; |
| 116 | 117 |
| 117 epoll_server_->RegisterFD(fd, this, kEpollFlags); | 118 epoll_server_->RegisterFD(fd, this, kEpollFlags); |
| 118 return true; | 119 return true; |
| 119 } | 120 } |
| 120 | 121 |
| 121 void QuicClient::CleanUpUDPSocket(int fd) { | 122 void QuicClient::CleanUpUDPSocket(int fd) { |
| 122 CleanUpUDPSocketImpl(fd); | 123 CleanUpUDPSocketImpl(fd); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 153 GetLatestFD(), QuicClient::GetLatestClientAddress().port(), | 154 GetLatestFD(), QuicClient::GetLatestClientAddress().port(), |
| 154 *helper()->GetClock(), this, | 155 *helper()->GetClock(), this, |
| 155 overflow_supported_ ? &packets_dropped_ : nullptr); | 156 overflow_supported_ ? &packets_dropped_ : nullptr); |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 if (connected() && (event->in_events & EPOLLOUT)) { | 159 if (connected() && (event->in_events & EPOLLOUT)) { |
| 159 writer()->SetWritable(); | 160 writer()->SetWritable(); |
| 160 session()->connection()->OnCanWrite(); | 161 session()->connection()->OnCanWrite(); |
| 161 } | 162 } |
| 162 if (event->in_events & EPOLLERR) { | 163 if (event->in_events & EPOLLERR) { |
| 163 DVLOG(1) << "Epollerr"; | 164 QUIC_DLOG(INFO) << "Epollerr"; |
| 164 } | 165 } |
| 165 } | 166 } |
| 166 | 167 |
| 167 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { | 168 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { |
| 168 return new QuicDefaultPacketWriter(GetLatestFD()); | 169 return new QuicDefaultPacketWriter(GetLatestFD()); |
| 169 } | 170 } |
| 170 | 171 |
| 171 QuicSocketAddress QuicClient::GetLatestClientAddress() const { | 172 QuicSocketAddress QuicClient::GetLatestClientAddress() const { |
| 172 if (fd_address_map_.empty()) { | 173 if (fd_address_map_.empty()) { |
| 173 return QuicSocketAddress(); | 174 return QuicSocketAddress(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 184 return fd_address_map_.back().first; | 185 return fd_address_map_.back().first; |
| 185 } | 186 } |
| 186 | 187 |
| 187 void QuicClient::ProcessPacket(const QuicSocketAddress& self_address, | 188 void QuicClient::ProcessPacket(const QuicSocketAddress& self_address, |
| 188 const QuicSocketAddress& peer_address, | 189 const QuicSocketAddress& peer_address, |
| 189 const QuicReceivedPacket& packet) { | 190 const QuicReceivedPacket& packet) { |
| 190 session()->ProcessUdpPacket(self_address, peer_address, packet); | 191 session()->ProcessUdpPacket(self_address, peer_address, packet); |
| 191 } | 192 } |
| 192 | 193 |
| 193 } // namespace net | 194 } // namespace net |
| OLD | NEW |