Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Side by Side Diff: net/tools/quic/quic_server.cc

Issue 397793004: Replace setsockopt(IP_PKTINFO) and setsockopt(IPV6_RECVPKTINFO) calls by (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/tools/quic/quic_client.cc ('k') | net/tools/quic/quic_socket_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_server.h" 5 #include "net/tools/quic/quic_server.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <features.h> 8 #include <features.h>
9 #include <netinet/in.h> 9 #include <netinet/in.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 10 matching lines...) Expand all
21 #include "net/quic/quic_protocol.h" 21 #include "net/quic/quic_protocol.h"
22 #include "net/tools/quic/quic_in_memory_cache.h" 22 #include "net/tools/quic/quic_in_memory_cache.h"
23 #include "net/tools/quic/quic_socket_utils.h" 23 #include "net/tools/quic/quic_socket_utils.h"
24 24
25 #define MMSG_MORE 0 25 #define MMSG_MORE 0
26 26
27 #ifndef SO_RXQ_OVFL 27 #ifndef SO_RXQ_OVFL
28 #define SO_RXQ_OVFL 40 28 #define SO_RXQ_OVFL 40
29 #endif 29 #endif
30 30
31 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET;
32 static const char kSourceAddressTokenSecret[] = "secret";
33 const uint32 kServerInitialFlowControlWindow = 100 * net::kMaxPacketSize;
34
35 namespace net { 31 namespace net {
36 namespace tools { 32 namespace tools {
37 33
34 namespace {
35
36 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET;
37 const char kSourceAddressTokenSecret[] = "secret";
38 const uint32 kServerInitialFlowControlWindow = 100 * net::kMaxPacketSize;
39
40 } // namespace
41
38 QuicServer::QuicServer() 42 QuicServer::QuicServer()
39 : port_(0), 43 : port_(0),
40 fd_(-1), 44 fd_(-1),
41 packets_dropped_(0), 45 packets_dropped_(0),
42 overflow_supported_(false), 46 overflow_supported_(false),
43 use_recvmmsg_(false), 47 use_recvmmsg_(false),
44 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), 48 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()),
45 supported_versions_(QuicSupportedVersions()) { 49 supported_versions_(QuicSupportedVersions()) {
46 // Use hardcoded crypto parameters for now. 50 // Use hardcoded crypto parameters for now.
47 config_.SetDefaults(); 51 config_.SetDefaults();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 89
86 bool QuicServer::Listen(const IPEndPoint& address) { 90 bool QuicServer::Listen(const IPEndPoint& address) {
87 port_ = address.port(); 91 port_ = address.port();
88 int address_family = address.GetSockAddrFamily(); 92 int address_family = address.GetSockAddrFamily();
89 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); 93 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
90 if (fd_ < 0) { 94 if (fd_ < 0) {
91 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno); 95 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno);
92 return false; 96 return false;
93 } 97 }
94 98
99 // Enable the socket option that allows the local address to be
100 // returned if the socket is bound to more than one address.
95 int rc = QuicSocketUtils::SetGetAddressInfo(fd_, address_family); 101 int rc = QuicSocketUtils::SetGetAddressInfo(fd_, address_family);
ramant (doing other things) 2014/07/15 23:02:39 nit: do we need to call SetReceiveBufferSize and S
wtc 2014/07/16 01:09:22 I don't think these socket options depend on each
96 102
97 if (rc < 0) { 103 if (rc < 0) {
98 LOG(ERROR) << "IP detection not supported" << strerror(errno); 104 LOG(ERROR) << "IP detection not supported" << strerror(errno);
99 return false; 105 return false;
100 } 106 }
101 107
102 int get_overflow = 1; 108 int get_overflow = 1;
103 rc = setsockopt( 109 rc = setsockopt(
104 fd_, SOL_SOCKET, SO_RXQ_OVFL, &get_overflow, sizeof(get_overflow)); 110 fd_, SOL_SOCKET, SO_RXQ_OVFL, &get_overflow, sizeof(get_overflow));
105 111
106 if (rc < 0) { 112 if (rc < 0) {
107 DLOG(WARNING) << "Socket overflow detection not supported"; 113 DLOG(WARNING) << "Socket overflow detection not supported";
108 } else { 114 } else {
109 overflow_supported_ = true; 115 overflow_supported_ = true;
110 } 116 }
111 117
112 // These send and receive buffer sizes are sized for a single connection, 118 // These send and receive buffer sizes are sized for a single connection,
113 // because the default usage of QuicServer is as a test server with one or 119 // because the default usage of QuicServer is as a test server with one or
114 // two clients. Adjust higher for use with many clients. 120 // two clients. Adjust higher for use with many clients.
115 if (!QuicSocketUtils::SetReceiveBufferSize(fd_, 121 if (!QuicSocketUtils::SetReceiveBufferSize(fd_,
116 TcpReceiver::kReceiveWindowTCP)) { 122 TcpReceiver::kReceiveWindowTCP)) {
117 return false; 123 return false;
118 } 124 }
119 125
120 if (!QuicSocketUtils::SetSendBufferSize(fd_, 126 if (!QuicSocketUtils::SetSendBufferSize(fd_,
121 TcpReceiver::kReceiveWindowTCP)) { 127 TcpReceiver::kReceiveWindowTCP)) {
122 return false; 128 return false;
123 } 129 }
124 130
125 // Enable the socket option that allows the local address to be
126 // returned if the socket is bound to more than on address.
127 int get_local_ip = 1;
128 rc = setsockopt(fd_, IPPROTO_IP, IP_PKTINFO,
129 &get_local_ip, sizeof(get_local_ip));
130 if (rc == 0 && address_family == AF_INET6) {
131 rc = setsockopt(fd_, IPPROTO_IPV6, IPV6_RECVPKTINFO,
132 &get_local_ip, sizeof(get_local_ip));
133 }
134 if (rc != 0) {
135 LOG(ERROR) << "Failed to set required socket options";
136 return false;
137 }
138
139 sockaddr_storage raw_addr; 131 sockaddr_storage raw_addr;
140 socklen_t raw_addr_len = sizeof(raw_addr); 132 socklen_t raw_addr_len = sizeof(raw_addr);
141 CHECK(address.ToSockAddr(reinterpret_cast<sockaddr*>(&raw_addr), 133 CHECK(address.ToSockAddr(reinterpret_cast<sockaddr*>(&raw_addr),
142 &raw_addr_len)); 134 &raw_addr_len));
143 rc = bind(fd_, 135 rc = bind(fd_,
144 reinterpret_cast<const sockaddr*>(&raw_addr), 136 reinterpret_cast<const sockaddr*>(&raw_addr),
145 sizeof(raw_addr)); 137 sizeof(raw_addr));
146 if (rc < 0) { 138 if (rc < 0) {
147 LOG(ERROR) << "Bind failed: " << strerror(errno); 139 LOG(ERROR) << "Bind failed: " << strerror(errno);
148 return false; 140 return false;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 QuicEncryptedPacket packet(buf, bytes_read, false); 227 QuicEncryptedPacket packet(buf, bytes_read, false);
236 228
237 IPEndPoint server_address(server_ip, port); 229 IPEndPoint server_address(server_ip, port);
238 processor->ProcessPacket(server_address, client_address, packet); 230 processor->ProcessPacket(server_address, client_address, packet);
239 231
240 return true; 232 return true;
241 } 233 }
242 234
243 } // namespace tools 235 } // namespace tools
244 } // namespace net 236 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_client.cc ('k') | net/tools/quic/quic_socket_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698