| 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_socket_utils.h" | 5 #include "net/tools/quic/quic_socket_utils.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> |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 int rc = sendmsg(fd, &hdr, 0); | 216 int rc = sendmsg(fd, &hdr, 0); |
| 217 if (rc >= 0) { | 217 if (rc >= 0) { |
| 218 return WriteResult(WRITE_STATUS_OK, rc); | 218 return WriteResult(WRITE_STATUS_OK, rc); |
| 219 } | 219 } |
| 220 return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) | 220 return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) |
| 221 ? WRITE_STATUS_BLOCKED | 221 ? WRITE_STATUS_BLOCKED |
| 222 : WRITE_STATUS_ERROR, | 222 : WRITE_STATUS_ERROR, |
| 223 errno); | 223 errno); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // static |
| 227 int QuicSocketUtils::CreateUDPSocket(const IPEndPoint& address, |
| 228 bool* overflow_supported) { |
| 229 int address_family = address.GetSockAddrFamily(); |
| 230 int fd = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); |
| 231 if (fd < 0) { |
| 232 LOG(ERROR) << "socket() failed: " << strerror(errno); |
| 233 return -1; |
| 234 } |
| 235 |
| 236 int get_overflow = 1; |
| 237 int rc = setsockopt(fd, SOL_SOCKET, SO_RXQ_OVFL, &get_overflow, |
| 238 sizeof(get_overflow)); |
| 239 if (rc < 0) { |
| 240 DLOG(WARNING) << "Socket overflow detection not supported"; |
| 241 } else { |
| 242 *overflow_supported = true; |
| 243 } |
| 244 |
| 245 if (!QuicSocketUtils::SetReceiveBufferSize(fd, kDefaultSocketReceiveBuffer)) { |
| 246 return -1; |
| 247 } |
| 248 |
| 249 if (!QuicSocketUtils::SetSendBufferSize(fd, kDefaultSocketReceiveBuffer)) { |
| 250 return -1; |
| 251 } |
| 252 |
| 253 rc = QuicSocketUtils::SetGetAddressInfo(fd, address_family); |
| 254 if (rc < 0) { |
| 255 LOG(ERROR) << "IP detection not supported" << strerror(errno); |
| 256 return -1; |
| 257 } |
| 258 return fd; |
| 259 } |
| 260 |
| 226 } // namespace net | 261 } // namespace net |
| OLD | NEW |