| QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // A class to read incoming QUIC packets from the UDP socket. |
| 6 | |
| 7 | #ifndef QUICHE_QUIC_CORE_QUIC_PACKET_READER_H_ |
| 8 | #define QUICHE_QUIC_CORE_QUIC_PACKET_READER_H_ |
| 9 | |
| vasilvv | 89713d0 | 2020-02-11 14:33:26 -0800 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/core/quic_clock.h" |
| QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 12 | #include "net/third_party/quiche/src/quic/core/quic_process_packet_interface.h" |
| wub | 1dc01cf | 2020-01-27 13:04:14 -0800 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/core/quic_udp_socket.h" |
| 14 | #include "net/third_party/quiche/src/quic/platform/api/quic_aligned.h" |
| wub | 1dc01cf | 2020-01-27 13:04:14 -0800 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" |
| QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | |
| 18 | namespace quic { |
| 19 | |
| QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 20 | // Read in larger batches to minimize recvmmsg overhead. |
| 21 | const int kNumPacketsPerReadMmsgCall = 16; |
| QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 22 | |
| dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 23 | class QUIC_EXPORT_PRIVATE QuicPacketReader { |
| QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | public: |
| 25 | QuicPacketReader(); |
| 26 | QuicPacketReader(const QuicPacketReader&) = delete; |
| 27 | QuicPacketReader& operator=(const QuicPacketReader&) = delete; |
| 28 | |
| 29 | virtual ~QuicPacketReader(); |
| 30 | |
| 31 | // Reads a number of packets from the given fd, and then passes them off to |
| 32 | // the PacketProcessInterface. Returns true if there may be additional |
| 33 | // packets available on the socket. |
| 34 | // Populates |packets_dropped| if it is non-null and the socket is configured |
| 35 | // to track dropped packets and some packets are read. |
| 36 | // If the socket has timestamping enabled, the per packet timestamps will be |
| 37 | // passed to the processor. Otherwise, |clock| will be used. |
| 38 | virtual bool ReadAndDispatchPackets(int fd, |
| 39 | int port, |
| 40 | const QuicClock& clock, |
| 41 | ProcessPacketInterface* processor, |
| 42 | QuicPacketCount* packets_dropped); |
| 43 | |
| 44 | private: |
| wub | 1dc01cf | 2020-01-27 13:04:14 -0800 | [diff] [blame] | 45 | // Return the self ip from |packet_info|. |
| 46 | // For dual stack sockets, |packet_info| may contain both a v4 and a v6 ip, in |
| 47 | // that case, |prefer_v6_ip| is used to determine which one is used as the |
| 48 | // return value. If neither v4 nor v6 ip exists, return an uninitialized ip. |
| 49 | static QuicIpAddress GetSelfIpFromPacketInfo( |
| 50 | const QuicUdpPacketInfo& packet_info, |
| 51 | bool prefer_v6_ip); |
| 52 | |
| wub | 1dc01cf | 2020-01-27 13:04:14 -0800 | [diff] [blame] | 53 | struct QUIC_EXPORT_PRIVATE ReadBuffer { |
| 54 | QUIC_CACHELINE_ALIGNED char |
| wub | a27a3c9 | 2020-01-28 08:43:21 -0800 | [diff] [blame] | 55 | control_buffer[kDefaultUdpPacketControlBufferSize]; // For ancillary |
| 56 | // data. |
| wub | 1dc01cf | 2020-01-27 13:04:14 -0800 | [diff] [blame] | 57 | QUIC_CACHELINE_ALIGNED char packet_buffer[kMaxIncomingPacketSize]; |
| 58 | }; |
| wub | 5dcf028 | 2020-02-28 06:56:00 -0800 | [diff] [blame] | 59 | |
| wub | 1dc01cf | 2020-01-27 13:04:14 -0800 | [diff] [blame] | 60 | QuicUdpSocketApi socket_api_; |
| 61 | std::vector<ReadBuffer> read_buffers_; |
| 62 | QuicUdpSocketApi::ReadPacketResults read_results_; |
| QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace quic |
| 66 | |
| 67 | #endif // QUICHE_QUIC_CORE_QUIC_PACKET_READER_H_ |