| 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 #include "net/tools/quic/quic_packet_reader.h" | 5 #include "net/tools/quic/quic_packet_reader.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> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 hdr->msg_iovlen = 1; | 53 hdr->msg_iovlen = 1; |
| 54 | 54 |
| 55 hdr->msg_control = packets_[i].cbuf; | 55 hdr->msg_control = packets_[i].cbuf; |
| 56 hdr->msg_controllen = kSpaceForOverflowAndIp; | 56 hdr->msg_controllen = kSpaceForOverflowAndIp; |
| 57 } | 57 } |
| 58 #endif | 58 #endif |
| 59 } | 59 } |
| 60 | 60 |
| 61 QuicPacketReader::~QuicPacketReader() {} | 61 QuicPacketReader::~QuicPacketReader() {} |
| 62 | 62 |
| 63 // TODO(danzh): write a public method to wrap ReadAndDispatchPackets() and | |
| 64 // ReadAndDispatchSinglePacket() based on MMSG_MORE. | |
| 65 bool QuicPacketReader::ReadAndDispatchPackets( | 63 bool QuicPacketReader::ReadAndDispatchPackets( |
| 66 int fd, | 64 int fd, |
| 67 int port, | 65 int port, |
| 68 ProcessPacketInterface* processor, | 66 ProcessPacketInterface* processor, |
| 69 QuicPacketCount* packets_dropped) { | 67 QuicPacketCount* packets_dropped) { |
| 70 #if MMSG_MORE | 68 #if MMSG_MORE |
| 69 return ReadAndDispatchManyPackets(fd, port, processor, packets_dropped); |
| 70 #else |
| 71 return ReadAndDispatchSinglePacket(fd, port, processor, packets_dropped); |
| 72 #endif |
| 73 } |
| 74 |
| 75 bool QuicPacketReader::ReadAndDispatchManyPackets( |
| 76 int fd, |
| 77 int port, |
| 78 ProcessPacketInterface* processor, |
| 79 QuicPacketCount* packets_dropped) { |
| 80 #if MMSG_MORE |
| 71 // Re-set the length fields in case recvmmsg has changed them. | 81 // Re-set the length fields in case recvmmsg has changed them. |
| 72 for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { | 82 for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { |
| 73 DCHECK_EQ(kMaxPacketSize, packets_[i].iov.iov_len); | 83 DCHECK_EQ(kMaxPacketSize, packets_[i].iov.iov_len); |
| 74 msghdr* hdr = &mmsg_hdr_[i].msg_hdr; | 84 msghdr* hdr = &mmsg_hdr_[i].msg_hdr; |
| 75 hdr->msg_namelen = sizeof(sockaddr_storage); | 85 hdr->msg_namelen = sizeof(sockaddr_storage); |
| 76 DCHECK_EQ(1, hdr->msg_iovlen); | 86 DCHECK_EQ(1, hdr->msg_iovlen); |
| 77 hdr->msg_controllen = kSpaceForOverflowAndIp; | 87 hdr->msg_controllen = kSpaceForOverflowAndIp; |
| 78 } | 88 } |
| 79 | 89 |
| 80 int packets_read = | 90 int packets_read = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 IPEndPoint server_address(server_ip, port); | 148 IPEndPoint server_address(server_ip, port); |
| 139 processor->ProcessPacket(server_address, client_address, packet); | 149 processor->ProcessPacket(server_address, client_address, packet); |
| 140 | 150 |
| 141 // The socket read was successful, so return true even if packet dispatch | 151 // The socket read was successful, so return true even if packet dispatch |
| 142 // failed. | 152 // failed. |
| 143 return true; | 153 return true; |
| 144 } | 154 } |
| 145 | 155 |
| 146 | 156 |
| 147 } // namespace net | 157 } // namespace net |
| OLD | NEW |