OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // A class to read incoming QUIC packets from the UDP socket. | 5 // A class to read incoming QUIC packets from the UDP socket. |
6 | 6 |
7 #ifndef NET_TOOLS_QUIC_QUIC_PACKET_READER_H_ | 7 #ifndef NET_TOOLS_QUIC_QUIC_PACKET_READER_H_ |
8 #define NET_TOOLS_QUIC_QUIC_PACKET_READER_H_ | 8 #define NET_TOOLS_QUIC_QUIC_PACKET_READER_H_ |
9 | 9 |
10 #include <netinet/in.h> | 10 #include <netinet/in.h> |
11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "net/quic/quic_protocol.h" | 14 #include "net/quic/quic_protocol.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 namespace tools { | 18 namespace tools { |
19 | 19 |
20 // Read in larger batches to minimize recvmmsg overhead. | 20 // Read in larger batches to minimize recvmmsg overhead. |
21 const int kNumPacketsPerReadMmsgCall = 16; | 21 const int kNumPacketsPerReadMmsgCall = 16; |
22 // Allocate space for in6_pktinfo as it's larger than in_pktinfo | 22 // Allocate space for in6_pktinfo as it's larger than in_pktinfo |
23 const int kSpaceForOverflowAndIp = | 23 const int kSpaceForOverflowAndIp = |
24 CMSG_SPACE(sizeof(int)) + CMSG_SPACE(sizeof(in6_pktinfo)); | 24 CMSG_SPACE(sizeof(int)) + CMSG_SPACE(sizeof(in6_pktinfo)); |
25 | 25 |
26 namespace test { | 26 namespace test { |
27 class QuicServerPeer; | 27 class QuicServerPeer; |
28 } // namespace test | 28 } // namespace test |
29 | 29 |
30 class ProcessPacketInterface; | |
31 class QuicDispatcher; | 30 class QuicDispatcher; |
32 | 31 |
| 32 class ProcessPacketInterface { |
| 33 public: |
| 34 virtual ~ProcessPacketInterface() {} |
| 35 virtual void ProcessPacket(const IPEndPoint& server_address, |
| 36 const IPEndPoint& client_address, |
| 37 const QuicEncryptedPacket& packet) = 0; |
| 38 }; |
| 39 |
33 class QuicPacketReader { | 40 class QuicPacketReader { |
34 public: | 41 public: |
35 QuicPacketReader(); | 42 QuicPacketReader(); |
36 | 43 |
37 virtual ~QuicPacketReader(); | 44 virtual ~QuicPacketReader(); |
38 | 45 |
39 // Reads a number of packets from the given fd, and then passes them off to | 46 // Reads a number of packets from the given fd, and then passes them off to |
40 // the PacketProcessInterface. Returns true if at least 1 packet is read, | 47 // the PacketProcessInterface. Returns true if at least 1 packet is read, |
41 // false otherwise. | 48 // false otherwise. |
42 // Populates |packets_dropped| if it is non-null and the socket is configured | 49 // Populates |packets_dropped| if it is non-null and the socket is configured |
(...skipping 11 matching lines...) Expand all Loading... |
54 | 61 |
55 private: | 62 private: |
56 // Initialize the internal state of the reader. | 63 // Initialize the internal state of the reader. |
57 void Initialize(); | 64 void Initialize(); |
58 | 65 |
59 // Storage only used when recvmmsg is available. | 66 // Storage only used when recvmmsg is available. |
60 | 67 |
61 // cbuf_ is used for ancillary data from the kernel on recvmmsg. | 68 // cbuf_ is used for ancillary data from the kernel on recvmmsg. |
62 char cbuf_[kSpaceForOverflowAndIp * kNumPacketsPerReadMmsgCall]; | 69 char cbuf_[kSpaceForOverflowAndIp * kNumPacketsPerReadMmsgCall]; |
63 // buf_ is used for the data read from the kernel on recvmmsg. | 70 // buf_ is used for the data read from the kernel on recvmmsg. |
| 71 // TODO(danzh): change it to be a pointer to avoid the allocation on the stack |
| 72 // from exceeding maximum allowed frame size. |
64 char buf_[2 * kMaxPacketSize * kNumPacketsPerReadMmsgCall]; | 73 char buf_[2 * kMaxPacketSize * kNumPacketsPerReadMmsgCall]; |
65 // iov_ and mmsg_hdr_ are used to supply cbuf and buf to the recvmmsg call. | 74 // iov_ and mmsg_hdr_ are used to supply cbuf and buf to the recvmmsg call. |
66 iovec iov_[kNumPacketsPerReadMmsgCall]; | 75 iovec iov_[kNumPacketsPerReadMmsgCall]; |
67 mmsghdr mmsg_hdr_[kNumPacketsPerReadMmsgCall]; | 76 mmsghdr mmsg_hdr_[kNumPacketsPerReadMmsgCall]; |
68 // raw_address_ is used for address information provided by the recvmmsg | 77 // raw_address_ is used for address information provided by the recvmmsg |
69 // call on the packets. | 78 // call on the packets. |
70 struct sockaddr_storage raw_address_[kNumPacketsPerReadMmsgCall]; | 79 struct sockaddr_storage raw_address_[kNumPacketsPerReadMmsgCall]; |
71 | 80 |
72 DISALLOW_COPY_AND_ASSIGN(QuicPacketReader); | 81 DISALLOW_COPY_AND_ASSIGN(QuicPacketReader); |
73 }; | 82 }; |
74 | 83 |
75 } // namespace tools | 84 } // namespace tools |
76 } // namespace net | 85 } // namespace net |
77 | 86 |
78 #endif // NET_TOOLS_QUIC_QUIC_PACKET_READER_H_ | 87 #endif // NET_TOOLS_QUIC_QUIC_PACKET_READER_H_ |
OLD | NEW |