| 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> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // Reads a number of packets from the given fd, and then passes them off to | 41 // Reads a number of packets from the given fd, and then passes them off to |
| 42 // the PacketProcessInterface. Returns true if there may be additional | 42 // the PacketProcessInterface. Returns true if there may be additional |
| 43 // packets available on the socket. | 43 // packets available on the socket. |
| 44 // Populates |packets_dropped| if it is non-null and the socket is configured | 44 // Populates |packets_dropped| if it is non-null and the socket is configured |
| 45 // to track dropped packets and some packets are read. | 45 // to track dropped packets and some packets are read. |
| 46 virtual bool ReadAndDispatchPackets(int fd, | 46 virtual bool ReadAndDispatchPackets(int fd, |
| 47 int port, | 47 int port, |
| 48 ProcessPacketInterface* processor, | 48 ProcessPacketInterface* processor, |
| 49 QuicPacketCount* packets_dropped); | 49 QuicPacketCount* packets_dropped); |
| 50 | 50 |
| 51 // Same as ReadAndDispatchPackets, only does one packet at a time. | 51 private: |
| 52 // Initialize the internal state of the reader. |
| 53 void Initialize(); |
| 54 |
| 55 // Reads and dispatches many packets using recvmmsg. |
| 56 bool ReadAndDispatchManyPackets(int fd, |
| 57 int port, |
| 58 ProcessPacketInterface* processor, |
| 59 QuicPacketCount* packets_dropped); |
| 60 |
| 61 // Reads and dispatches a single packet using recvmsg. |
| 52 static bool ReadAndDispatchSinglePacket(int fd, | 62 static bool ReadAndDispatchSinglePacket(int fd, |
| 53 int port, | 63 int port, |
| 54 ProcessPacketInterface* processor, | 64 ProcessPacketInterface* processor, |
| 55 QuicPacketCount* packets_dropped); | 65 QuicPacketCount* packets_dropped); |
| 56 | 66 |
| 57 private: | |
| 58 // Initialize the internal state of the reader. | |
| 59 void Initialize(); | |
| 60 | |
| 61 // Storage only used when recvmmsg is available. | 67 // Storage only used when recvmmsg is available. |
| 62 | 68 |
| 63 #if MMSG_MORE | 69 #if MMSG_MORE |
| 64 // TODO(danzh): change it to be a pointer to avoid the allocation on the stack | 70 // TODO(danzh): change it to be a pointer to avoid the allocation on the stack |
| 65 // from exceeding maximum allowed frame size. | 71 // from exceeding maximum allowed frame size. |
| 66 // packets_ and mmsg_hdr_ are used to supply cbuf and buf to the recvmmsg | 72 // packets_ and mmsg_hdr_ are used to supply cbuf and buf to the recvmmsg |
| 67 // call. | 73 // call. |
| 68 | 74 |
| 69 struct PacketData { | 75 struct PacketData { |
| 70 iovec iov; | 76 iovec iov; |
| 71 // raw_address is used for address information provided by the recvmmsg | 77 // raw_address is used for address information provided by the recvmmsg |
| 72 // call on the packets. | 78 // call on the packets. |
| 73 struct sockaddr_storage raw_address; | 79 struct sockaddr_storage raw_address; |
| 74 // cbuf is used for ancillary data from the kernel on recvmmsg. | 80 // cbuf is used for ancillary data from the kernel on recvmmsg. |
| 75 char cbuf[kSpaceForOverflowAndIp]; | 81 char cbuf[kSpaceForOverflowAndIp]; |
| 76 // buf is used for the data read from the kernel on recvmmsg. | 82 // buf is used for the data read from the kernel on recvmmsg. |
| 77 char buf[kMaxPacketSize]; | 83 char buf[kMaxPacketSize]; |
| 78 }; | 84 }; |
| 79 PacketData packets_[kNumPacketsPerReadMmsgCall]; | 85 PacketData packets_[kNumPacketsPerReadMmsgCall]; |
| 80 mmsghdr mmsg_hdr_[kNumPacketsPerReadMmsgCall]; | 86 mmsghdr mmsg_hdr_[kNumPacketsPerReadMmsgCall]; |
| 81 #endif | 87 #endif |
| 82 | 88 |
| 83 DISALLOW_COPY_AND_ASSIGN(QuicPacketReader); | 89 DISALLOW_COPY_AND_ASSIGN(QuicPacketReader); |
| 84 }; | 90 }; |
| 85 | 91 |
| 86 } // namespace net | 92 } // namespace net |
| 87 | 93 |
| 88 #endif // NET_TOOLS_QUIC_QUIC_PACKET_READER_H_ | 94 #endif // NET_TOOLS_QUIC_QUIC_PACKET_READER_H_ |
| OLD | NEW |