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_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> |
11 #include <sys/epoll.h> | 11 #include <sys/epoll.h> |
12 #include <sys/socket.h> | 12 #include <sys/socket.h> |
13 | 13 |
14 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
15 #include "net/base/sockaddr_storage.h" | 15 #include "net/base/sockaddr_storage.h" |
16 #include "net/quic/crypto/crypto_handshake.h" | 16 #include "net/quic/crypto/crypto_handshake.h" |
17 #include "net/quic/crypto/quic_random.h" | 17 #include "net/quic/crypto/quic_random.h" |
18 #include "net/quic/quic_clock.h" | 18 #include "net/quic/quic_clock.h" |
19 #include "net/quic/quic_crypto_stream.h" | 19 #include "net/quic/quic_crypto_stream.h" |
20 #include "net/quic/quic_data_reader.h" | 20 #include "net/quic/quic_data_reader.h" |
21 #include "net/quic/quic_protocol.h" | 21 #include "net/quic/quic_protocol.h" |
22 #include "net/tools/quic/quic_dispatcher.h" | 22 #include "net/tools/quic/quic_dispatcher.h" |
23 #include "net/tools/quic/quic_epoll_clock.h" | 23 #include "net/tools/quic/quic_epoll_clock.h" |
24 #include "net/tools/quic/quic_epoll_connection_helper.h" | 24 #include "net/tools/quic/quic_epoll_connection_helper.h" |
25 #include "net/tools/quic/quic_in_memory_cache.h" | 25 #include "net/tools/quic/quic_in_memory_cache.h" |
26 #include "net/tools/quic/quic_packet_reader.h" | 26 #include "net/tools/quic/quic_packet_reader.h" |
27 #include "net/tools/quic/quic_socket_utils.h" | 27 #include "net/tools/quic/quic_socket_utils.h" |
28 | 28 |
29 // TODO(rtenneti): Add support for MMSG_MORE. | |
30 #define MMSG_MORE 0 | |
31 | |
32 #ifndef SO_RXQ_OVFL | 29 #ifndef SO_RXQ_OVFL |
33 #define SO_RXQ_OVFL 40 | 30 #define SO_RXQ_OVFL 40 |
34 #endif | 31 #endif |
35 | 32 |
36 namespace net { | 33 namespace net { |
37 namespace { | 34 namespace { |
38 | 35 |
39 // Specifies the directory used during QuicInMemoryCache | 36 // Specifies the directory used during QuicInMemoryCache |
40 // construction to seed the cache. Cache directory can be | 37 // construction to seed the cache. Cache directory can be |
41 // generated using `wget -p --save-headers <url>` | 38 // generated using `wget -p --save-headers <url>` |
(...skipping 12 matching lines...) Expand all Loading... |
54 | 51 |
55 QuicServer::QuicServer( | 52 QuicServer::QuicServer( |
56 ProofSource* proof_source, | 53 ProofSource* proof_source, |
57 const QuicConfig& config, | 54 const QuicConfig& config, |
58 const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, | 55 const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, |
59 const QuicVersionVector& supported_versions) | 56 const QuicVersionVector& supported_versions) |
60 : port_(0), | 57 : port_(0), |
61 fd_(-1), | 58 fd_(-1), |
62 packets_dropped_(0), | 59 packets_dropped_(0), |
63 overflow_supported_(false), | 60 overflow_supported_(false), |
64 use_recvmmsg_(false), | |
65 config_(config), | 61 config_(config), |
66 crypto_config_(kSourceAddressTokenSecret, | 62 crypto_config_(kSourceAddressTokenSecret, |
67 QuicRandom::GetInstance(), | 63 QuicRandom::GetInstance(), |
68 proof_source), | 64 proof_source), |
69 crypto_config_options_(crypto_config_options), | 65 crypto_config_options_(crypto_config_options), |
70 supported_versions_(supported_versions), | 66 supported_versions_(supported_versions), |
71 packet_reader_(new QuicPacketReader()) { | 67 packet_reader_(new QuicPacketReader()) { |
72 Initialize(); | 68 Initialize(); |
73 } | 69 } |
74 | 70 |
75 void QuicServer::Initialize() { | 71 void QuicServer::Initialize() { |
76 #if MMSG_MORE | |
77 use_recvmmsg_ = true; | |
78 #endif | |
79 | |
80 // If an initial flow control window has not explicitly been set, then use a | 72 // If an initial flow control window has not explicitly been set, then use a |
81 // sensible value for a server: 1 MB for session, 64 KB for each stream. | 73 // sensible value for a server: 1 MB for session, 64 KB for each stream. |
82 const uint32_t kInitialSessionFlowControlWindow = 1 * 1024 * 1024; // 1 MB | 74 const uint32_t kInitialSessionFlowControlWindow = 1 * 1024 * 1024; // 1 MB |
83 const uint32_t kInitialStreamFlowControlWindow = 64 * 1024; // 64 KB | 75 const uint32_t kInitialStreamFlowControlWindow = 64 * 1024; // 64 KB |
84 if (config_.GetInitialStreamFlowControlWindowToSend() == | 76 if (config_.GetInitialStreamFlowControlWindowToSend() == |
85 kMinimumFlowControlSendWindow) { | 77 kMinimumFlowControlSendWindow) { |
86 config_.SetInitialStreamFlowControlWindowToSend( | 78 config_.SetInitialStreamFlowControlWindowToSend( |
87 kInitialStreamFlowControlWindow); | 79 kInitialStreamFlowControlWindow); |
88 } | 80 } |
89 if (config_.GetInitialSessionFlowControlWindowToSend() == | 81 if (config_.GetInitialSessionFlowControlWindowToSend() == |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 160 } |
169 | 161 |
170 void QuicServer::OnEvent(int fd, EpollEvent* event) { | 162 void QuicServer::OnEvent(int fd, EpollEvent* event) { |
171 DCHECK_EQ(fd, fd_); | 163 DCHECK_EQ(fd, fd_); |
172 event->out_ready_mask = 0; | 164 event->out_ready_mask = 0; |
173 | 165 |
174 if (event->in_events & EPOLLIN) { | 166 if (event->in_events & EPOLLIN) { |
175 DVLOG(1) << "EPOLLIN"; | 167 DVLOG(1) << "EPOLLIN"; |
176 bool more_to_read = true; | 168 bool more_to_read = true; |
177 while (more_to_read) { | 169 while (more_to_read) { |
178 if (use_recvmmsg_) { | 170 more_to_read = packet_reader_->ReadAndDispatchPackets( |
179 more_to_read = packet_reader_->ReadAndDispatchPackets( | 171 fd_, port_, dispatcher_.get(), |
180 fd_, port_, dispatcher_.get(), | 172 overflow_supported_ ? &packets_dropped_ : nullptr); |
181 overflow_supported_ ? &packets_dropped_ : nullptr); | |
182 } else { | |
183 more_to_read = QuicPacketReader::ReadAndDispatchSinglePacket( | |
184 fd_, port_, dispatcher_.get(), | |
185 overflow_supported_ ? &packets_dropped_ : nullptr); | |
186 } | |
187 } | 173 } |
188 } | 174 } |
189 if (event->in_events & EPOLLOUT) { | 175 if (event->in_events & EPOLLOUT) { |
190 dispatcher_->OnCanWrite(); | 176 dispatcher_->OnCanWrite(); |
191 if (dispatcher_->HasPendingWrites()) { | 177 if (dispatcher_->HasPendingWrites()) { |
192 event->out_ready_mask |= EPOLLOUT; | 178 event->out_ready_mask |= EPOLLOUT; |
193 } | 179 } |
194 } | 180 } |
195 if (event->in_events & EPOLLERR) { | 181 if (event->in_events & EPOLLERR) { |
196 } | 182 } |
197 } | 183 } |
198 | 184 |
199 } // namespace net | 185 } // namespace net |
OLD | NEW |