| 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/platform/impl/quic_socket_utils.h" | 5 #include "net/tools/quic/platform/impl/quic_socket_utils.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <linux/net_tstamp.h> | 8 #include <linux/net_tstamp.h> |
| 9 #include <netinet/in.h> | 9 #include <netinet/in.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 12 #include <sys/uio.h> | 12 #include <sys/uio.h> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/logging.h" | |
| 16 #include "net/quic/core/quic_flags.h" | 15 #include "net/quic/core/quic_flags.h" |
| 17 #include "net/quic/core/quic_packets.h" | 16 #include "net/quic/core/quic_packets.h" |
| 18 #include "net/quic/platform/api/quic_bug_tracker.h" | 17 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 18 #include "net/quic/platform/api/quic_logging.h" |
| 19 #include "net/quic/platform/api/quic_socket_address.h" | 19 #include "net/quic/platform/api/quic_socket_address.h" |
| 20 | 20 |
| 21 #ifndef SO_RXQ_OVFL | 21 #ifndef SO_RXQ_OVFL |
| 22 #define SO_RXQ_OVFL 40 | 22 #define SO_RXQ_OVFL 40 |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 using std::string; | 25 using std::string; |
| 26 | 26 |
| 27 namespace net { | 27 namespace net { |
| 28 | 28 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 : WRITE_STATUS_ERROR, | 270 : WRITE_STATUS_ERROR, |
| 271 errno); | 271 errno); |
| 272 } | 272 } |
| 273 | 273 |
| 274 // static | 274 // static |
| 275 int QuicSocketUtils::CreateUDPSocket(const QuicSocketAddress& address, | 275 int QuicSocketUtils::CreateUDPSocket(const QuicSocketAddress& address, |
| 276 bool* overflow_supported) { | 276 bool* overflow_supported) { |
| 277 int address_family = address.host().AddressFamilyToInt(); | 277 int address_family = address.host().AddressFamilyToInt(); |
| 278 int fd = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); | 278 int fd = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); |
| 279 if (fd < 0) { | 279 if (fd < 0) { |
| 280 LOG(ERROR) << "socket() failed: " << strerror(errno); | 280 QUIC_LOG(ERROR) << "socket() failed: " << strerror(errno); |
| 281 return -1; | 281 return -1; |
| 282 } | 282 } |
| 283 | 283 |
| 284 int get_overflow = 1; | 284 int get_overflow = 1; |
| 285 int rc = setsockopt(fd, SOL_SOCKET, SO_RXQ_OVFL, &get_overflow, | 285 int rc = setsockopt(fd, SOL_SOCKET, SO_RXQ_OVFL, &get_overflow, |
| 286 sizeof(get_overflow)); | 286 sizeof(get_overflow)); |
| 287 if (rc < 0) { | 287 if (rc < 0) { |
| 288 DLOG(WARNING) << "Socket overflow detection not supported"; | 288 QUIC_DLOG(WARNING) << "Socket overflow detection not supported"; |
| 289 } else { | 289 } else { |
| 290 *overflow_supported = true; | 290 *overflow_supported = true; |
| 291 } | 291 } |
| 292 | 292 |
| 293 if (!SetReceiveBufferSize(fd, kDefaultSocketReceiveBuffer)) { | 293 if (!SetReceiveBufferSize(fd, kDefaultSocketReceiveBuffer)) { |
| 294 return -1; | 294 return -1; |
| 295 } | 295 } |
| 296 | 296 |
| 297 if (!SetSendBufferSize(fd, kDefaultSocketReceiveBuffer)) { | 297 if (!SetSendBufferSize(fd, kDefaultSocketReceiveBuffer)) { |
| 298 return -1; | 298 return -1; |
| 299 } | 299 } |
| 300 | 300 |
| 301 rc = SetGetAddressInfo(fd, address_family); | 301 rc = SetGetAddressInfo(fd, address_family); |
| 302 if (rc < 0) { | 302 if (rc < 0) { |
| 303 LOG(ERROR) << "IP detection not supported" << strerror(errno); | 303 LOG(ERROR) << "IP detection not supported" << strerror(errno); |
| 304 return -1; | 304 return -1; |
| 305 } | 305 } |
| 306 | 306 |
| 307 rc = SetGetSoftwareReceiveTimestamp(fd); | 307 rc = SetGetSoftwareReceiveTimestamp(fd); |
| 308 if (rc < 0) { | 308 if (rc < 0) { |
| 309 LOG(WARNING) << "SO_TIMESTAMPING not supported; using fallback: " | 309 QUIC_LOG(WARNING) << "SO_TIMESTAMPING not supported; using fallback: " |
| 310 << strerror(errno); | 310 << strerror(errno); |
| 311 } | 311 } |
| 312 | 312 |
| 313 return fd; | 313 return fd; |
| 314 } | 314 } |
| 315 | 315 |
| 316 } // namespace net | 316 } // namespace net |
| OLD | NEW |