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 #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_packet_reader.h" |
25 #include "net/tools/quic/quic_socket_utils.h" | 26 #include "net/tools/quic/quic_socket_utils.h" |
26 | 27 |
| 28 // TODO(rtenneti): Add support for MMSG_MORE. |
27 #define MMSG_MORE 0 | 29 #define MMSG_MORE 0 |
| 30 // If true, QuicListener uses the QuicPacketReader to read packets instead of |
| 31 // QuicServer. |
| 32 // TODO(rtenneti): Enable this flag after MMSG_MORE is set to 1. |
| 33 #define FLAGS_quic_use_optimized_packet_reader false |
28 | 34 |
29 #ifndef SO_RXQ_OVFL | 35 #ifndef SO_RXQ_OVFL |
30 #define SO_RXQ_OVFL 40 | 36 #define SO_RXQ_OVFL 40 |
31 #endif | 37 #endif |
32 | 38 |
33 namespace net { | 39 namespace net { |
34 namespace tools { | 40 namespace tools { |
35 | 41 |
36 namespace { | 42 namespace { |
37 | 43 |
38 const PollBits kEpollFlags = PollBits(NET_POLLIN | NET_POLLOUT | NET_POLLET); | 44 const PollBits kEpollFlags = PollBits(NET_POLLIN | NET_POLLOUT | NET_POLLET); |
39 const char kSourceAddressTokenSecret[] = "secret"; | 45 const char kSourceAddressTokenSecret[] = "secret"; |
40 | 46 |
41 } // namespace | 47 } // namespace |
42 | 48 |
43 QuicServer::QuicServer() | 49 QuicServer::QuicServer() |
44 : port_(0), | 50 : port_(0), |
45 fd_(-1), | 51 fd_(-1), |
46 packets_dropped_(0), | 52 packets_dropped_(0), |
47 overflow_supported_(false), | 53 overflow_supported_(false), |
48 use_recvmmsg_(false), | 54 use_recvmmsg_(false), |
49 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), | 55 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), |
50 supported_versions_(QuicSupportedVersions()) { | 56 supported_versions_(QuicSupportedVersions()), |
| 57 packet_reader_(new QuicPacketReader()) { |
51 Initialize(); | 58 Initialize(); |
52 } | 59 } |
53 | 60 |
54 QuicServer::QuicServer(const QuicConfig& config, | 61 QuicServer::QuicServer(const QuicConfig& config, |
55 const QuicVersionVector& supported_versions) | 62 const QuicVersionVector& supported_versions) |
56 : port_(0), | 63 : port_(0), |
57 fd_(-1), | 64 fd_(-1), |
58 packets_dropped_(0), | 65 packets_dropped_(0), |
59 overflow_supported_(false), | 66 overflow_supported_(false), |
60 use_recvmmsg_(false), | 67 use_recvmmsg_(false), |
61 config_(config), | 68 config_(config), |
62 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), | 69 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), |
63 supported_versions_(supported_versions) { | 70 supported_versions_(supported_versions), |
| 71 packet_reader_(new QuicPacketReader()) { |
64 Initialize(); | 72 Initialize(); |
65 } | 73 } |
66 | 74 |
67 void QuicServer::Initialize() { | 75 void QuicServer::Initialize() { |
68 #if MMSG_MORE | 76 #if MMSG_MORE |
69 use_recvmmsg_ = true; | 77 use_recvmmsg_ = true; |
70 #endif | 78 #endif |
71 | 79 |
72 // If an initial flow control window has not explicitly been set, then use a | 80 // 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. | 81 // 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 Loading... |
194 } | 202 } |
195 | 203 |
196 void QuicServer::OnEvent(int fd, EpollEvent* event) { | 204 void QuicServer::OnEvent(int fd, EpollEvent* event) { |
197 DCHECK_EQ(fd, fd_); | 205 DCHECK_EQ(fd, fd_); |
198 event->out_ready_mask = 0; | 206 event->out_ready_mask = 0; |
199 | 207 |
200 if (event->in_events & NET_POLLIN) { | 208 if (event->in_events & NET_POLLIN) { |
201 DVLOG(1) << "NET_POLLIN"; | 209 DVLOG(1) << "NET_POLLIN"; |
202 bool read = true; | 210 bool read = true; |
203 while (read) { | 211 while (read) { |
204 read = ReadAndDispatchSinglePacket( | 212 if (use_recvmmsg_) { |
205 fd_, port_, dispatcher_.get(), | 213 if (FLAGS_quic_use_optimized_packet_reader) { |
206 overflow_supported_ ? &packets_dropped_ : nullptr); | 214 read = packet_reader_->ReadAndDispatchPackets( |
| 215 fd_, port_, dispatcher_.get(), |
| 216 overflow_supported_ ? &packets_dropped_ : nullptr); |
| 217 } else { |
| 218 // TODO(rtenneti): Add support for ReadAndDispatchPackets. |
| 219 #if 0 |
| 220 read = ReadAndDispatchPackets( |
| 221 fd_, port_, dispatcher_.get(), |
| 222 overflow_supported_ ? &packets_dropped_ : nullptr); |
| 223 #else |
| 224 read = ReadAndDispatchSinglePacket( |
| 225 fd_, port_, dispatcher_.get(), |
| 226 overflow_supported_ ? &packets_dropped_ : nullptr); |
| 227 #endif |
| 228 } |
| 229 } else { |
| 230 if (FLAGS_quic_use_optimized_packet_reader) { |
| 231 read = QuicPacketReader::ReadAndDispatchSinglePacket( |
| 232 fd_, port_, dispatcher_.get(), |
| 233 overflow_supported_ ? &packets_dropped_ : nullptr); |
| 234 } else { |
| 235 read = ReadAndDispatchSinglePacket( |
| 236 fd_, port_, dispatcher_.get(), |
| 237 overflow_supported_ ? &packets_dropped_ : nullptr); |
| 238 } |
| 239 } |
207 } | 240 } |
208 } | 241 } |
209 if (event->in_events & NET_POLLOUT) { | 242 if (event->in_events & NET_POLLOUT) { |
210 dispatcher_->OnCanWrite(); | 243 dispatcher_->OnCanWrite(); |
211 if (dispatcher_->HasPendingWrites()) { | 244 if (dispatcher_->HasPendingWrites()) { |
212 event->out_ready_mask |= NET_POLLOUT; | 245 event->out_ready_mask |= NET_POLLOUT; |
213 } | 246 } |
214 } | 247 } |
215 if (event->in_events & NET_POLLERR) { | 248 if (event->in_events & NET_POLLERR) { |
216 } | 249 } |
(...skipping 22 matching lines...) Expand all Loading... |
239 QuicEncryptedPacket packet(buf, bytes_read, false); | 272 QuicEncryptedPacket packet(buf, bytes_read, false); |
240 | 273 |
241 IPEndPoint server_address(server_ip, port); | 274 IPEndPoint server_address(server_ip, port); |
242 processor->ProcessPacket(server_address, client_address, packet); | 275 processor->ProcessPacket(server_address, client_address, packet); |
243 | 276 |
244 return true; | 277 return true; |
245 } | 278 } |
246 | 279 |
247 } // namespace tools | 280 } // namespace tools |
248 } // namespace net | 281 } // namespace net |
OLD | NEW |