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

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

Issue 1008313002: Move QUIC reads to a more optimized reader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rollback_of_changelist_87346681_88545044
Patch Set: Minor TODO comment fix Created 5 years, 9 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
« no previous file with comments | « net/tools/quic/quic_server.h ('k') | no next file » | 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 #ifndef __APPLE__ 8 #ifndef __APPLE__
9 // This is a GNU header that is not present in /usr/include on MacOS 9 // This is a GNU header that is not present in /usr/include on MacOS
10 #include <features.h> 10 #include <features.h>
11 #endif 11 #endif
12 #include <netinet/in.h> 12 #include <netinet/in.h>
13 #include <string.h> 13 #include <string.h>
14 #include <sys/socket.h> 14 #include <sys/socket.h>
15 15
16 #include "net/base/ip_endpoint.h" 16 #include "net/base/ip_endpoint.h"
17 #include "net/quic/crypto/crypto_handshake.h" 17 #include "net/quic/crypto/crypto_handshake.h"
18 #include "net/quic/crypto/quic_random.h" 18 #include "net/quic/crypto/quic_random.h"
19 #include "net/quic/quic_clock.h" 19 #include "net/quic/quic_clock.h"
20 #include "net/quic/quic_crypto_stream.h" 20 #include "net/quic/quic_crypto_stream.h"
21 #include "net/quic/quic_data_reader.h" 21 #include "net/quic/quic_data_reader.h"
22 #include "net/quic/quic_protocol.h" 22 #include "net/quic/quic_protocol.h"
23 #include "net/tools/quic/quic_dispatcher.h" 23 #include "net/tools/quic/quic_dispatcher.h"
24 #include "net/tools/quic/quic_in_memory_cache.h" 24 #include "net/tools/quic/quic_in_memory_cache.h"
25 #include "net/tools/quic/quic_socket_utils.h" 25 #include "net/tools/quic/quic_socket_utils.h"
26 26
27 // TODO(rtenneti): Add support for MMSG_MORE.
27 #define MMSG_MORE 0 28 #define MMSG_MORE 0
29 // If true, QuicListener uses the QuicPacketReader to read packets instead of
30 // QuicServer.
31 // TODO(rtenneti): Enable this flag after MMSG_MORE is set to 1.
32 #define FLAGS_quic_use_optimized_packet_reader false
28 33
29 #ifndef SO_RXQ_OVFL 34 #ifndef SO_RXQ_OVFL
30 #define SO_RXQ_OVFL 40 35 #define SO_RXQ_OVFL 40
31 #endif 36 #endif
32 37
33 namespace net { 38 namespace net {
34 namespace tools { 39 namespace tools {
35 40
36 namespace { 41 namespace {
37 42
38 const PollBits kEpollFlags = PollBits(NET_POLLIN | NET_POLLOUT | NET_POLLET); 43 const PollBits kEpollFlags = PollBits(NET_POLLIN | NET_POLLOUT | NET_POLLET);
39 const char kSourceAddressTokenSecret[] = "secret"; 44 const char kSourceAddressTokenSecret[] = "secret";
40 45
41 } // namespace 46 } // namespace
42 47
43 QuicServer::QuicServer() 48 QuicServer::QuicServer()
44 : port_(0), 49 : port_(0),
45 fd_(-1), 50 fd_(-1),
46 packets_dropped_(0), 51 packets_dropped_(0),
47 overflow_supported_(false), 52 overflow_supported_(false),
48 use_recvmmsg_(false), 53 use_recvmmsg_(false),
49 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), 54 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()),
50 supported_versions_(QuicSupportedVersions()) { 55 supported_versions_(QuicSupportedVersions()),
56 packet_reader_(new QuicPacketReader()) {
51 Initialize(); 57 Initialize();
52 } 58 }
53 59
54 QuicServer::QuicServer(const QuicConfig& config, 60 QuicServer::QuicServer(const QuicConfig& config,
55 const QuicVersionVector& supported_versions) 61 const QuicVersionVector& supported_versions)
56 : port_(0), 62 : port_(0),
57 fd_(-1), 63 fd_(-1),
58 packets_dropped_(0), 64 packets_dropped_(0),
59 overflow_supported_(false), 65 overflow_supported_(false),
60 use_recvmmsg_(false), 66 use_recvmmsg_(false),
61 config_(config), 67 config_(config),
62 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), 68 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()),
63 supported_versions_(supported_versions) { 69 supported_versions_(supported_versions),
70 packet_reader_(new QuicPacketReader()) {
64 Initialize(); 71 Initialize();
65 } 72 }
66 73
67 void QuicServer::Initialize() { 74 void QuicServer::Initialize() {
68 #if MMSG_MORE 75 #if MMSG_MORE
69 use_recvmmsg_ = true; 76 use_recvmmsg_ = true;
70 #endif 77 #endif
71 78
72 // If an initial flow control window has not explicitly been set, then use a 79 // If an initial flow control window has not explicitly been set, then use a
73 // sensible value for a server: 1 MB for session, 64 KB for each stream. 80 // sensible value for a server: 1 MB for session, 64 KB for each stream.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 201 }
195 202
196 void QuicServer::OnEvent(int fd, EpollEvent* event) { 203 void QuicServer::OnEvent(int fd, EpollEvent* event) {
197 DCHECK_EQ(fd, fd_); 204 DCHECK_EQ(fd, fd_);
198 event->out_ready_mask = 0; 205 event->out_ready_mask = 0;
199 206
200 if (event->in_events & NET_POLLIN) { 207 if (event->in_events & NET_POLLIN) {
201 DVLOG(1) << "NET_POLLIN"; 208 DVLOG(1) << "NET_POLLIN";
202 bool read = true; 209 bool read = true;
203 while (read) { 210 while (read) {
204 read = ReadAndDispatchSinglePacket( 211 if (use_recvmmsg_) {
205 fd_, port_, dispatcher_.get(), 212 if (FLAGS_quic_use_optimized_packet_reader) {
206 overflow_supported_ ? &packets_dropped_ : nullptr); 213 read = packet_reader_->ReadAndDispatchPackets(
214 fd_, port_, dispatcher_.get(),
215 overflow_supported_ ? &packets_dropped_ : nullptr);
216 } else {
217 // TODO(rtenneti): Add support for ReadAndDispatchPackets.
218 #if 0
219 read = ReadAndDispatchPackets(
220 fd_, port_, dispatcher_.get(),
221 overflow_supported_ ? &packets_dropped_ : nullptr);
222 #else
223 read = ReadAndDispatchSinglePacket(
224 fd_, port_, dispatcher_.get(),
225 overflow_supported_ ? &packets_dropped_ : nullptr);
226 #endif
227 }
228 } else {
229 if (FLAGS_quic_use_optimized_packet_reader) {
230 read = QuicPacketReader::ReadAndDispatchSinglePacket(
231 fd_, port_, dispatcher_.get(),
232 overflow_supported_ ? &packets_dropped_ : nullptr);
233 } else {
234 read = ReadAndDispatchSinglePacket(
235 fd_, port_, dispatcher_.get(),
236 overflow_supported_ ? &packets_dropped_ : nullptr);
237 }
238 }
207 } 239 }
208 } 240 }
209 if (event->in_events & NET_POLLOUT) { 241 if (event->in_events & NET_POLLOUT) {
210 dispatcher_->OnCanWrite(); 242 dispatcher_->OnCanWrite();
211 if (dispatcher_->HasPendingWrites()) { 243 if (dispatcher_->HasPendingWrites()) {
212 event->out_ready_mask |= NET_POLLOUT; 244 event->out_ready_mask |= NET_POLLOUT;
213 } 245 }
214 } 246 }
215 if (event->in_events & NET_POLLERR) { 247 if (event->in_events & NET_POLLERR) {
216 } 248 }
(...skipping 22 matching lines...) Expand all
239 QuicEncryptedPacket packet(buf, bytes_read, false); 271 QuicEncryptedPacket packet(buf, bytes_read, false);
240 272
241 IPEndPoint server_address(server_ip, port); 273 IPEndPoint server_address(server_ip, port);
242 processor->ProcessPacket(server_address, client_address, packet); 274 processor->ProcessPacket(server_address, client_address, packet);
243 275
244 return true; 276 return true;
245 } 277 }
246 278
247 } // namespace tools 279 } // namespace tools
248 } // namespace net 280 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698