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 #include <features.h> | 8 #include <features.h> |
9 #include <netinet/in.h> | 9 #include <netinet/in.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 bool can_write_more = dispatcher_->OnCanWrite(); | 184 bool can_write_more = dispatcher_->OnCanWrite(); |
185 if (can_write_more) { | 185 if (can_write_more) { |
186 event->out_ready_mask |= EPOLLOUT; | 186 event->out_ready_mask |= EPOLLOUT; |
187 } | 187 } |
188 } | 188 } |
189 if (event->in_events & EPOLLERR) { | 189 if (event->in_events & EPOLLERR) { |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 /* static */ | 193 /* static */ |
194 void QuicServer::MaybeDispatchPacket(QuicDispatcher* dispatcher, | |
195 const QuicEncryptedPacket& packet, | |
196 const IPEndPoint& server_address, | |
197 const IPEndPoint& client_address) { | |
198 QuicGuid guid; | |
199 if (!QuicFramer::ReadGuidFromPacket(packet, &guid)) { | |
200 return; | |
201 } | |
202 | |
203 bool has_version_flag = QuicFramer::HasVersionFlag(packet); | |
204 | |
205 dispatcher->ProcessPacket( | |
206 server_address, client_address, guid, has_version_flag, packet); | |
207 } | |
208 | |
209 bool QuicServer::ReadAndDispatchSinglePacket(int fd, | 194 bool QuicServer::ReadAndDispatchSinglePacket(int fd, |
210 int port, | 195 int port, |
211 QuicDispatcher* dispatcher, | 196 QuicDispatcher* dispatcher, |
212 int* packets_dropped) { | 197 int* packets_dropped) { |
213 // Allocate some extra space so we can send an error if the client goes over | 198 // Allocate some extra space so we can send an error if the client goes over |
214 // the limit. | 199 // the limit. |
215 char buf[2 * kMaxPacketSize]; | 200 char buf[2 * kMaxPacketSize]; |
216 | 201 |
217 IPEndPoint client_address; | 202 IPEndPoint client_address; |
218 IPAddressNumber server_ip; | 203 IPAddressNumber server_ip; |
219 int bytes_read = | 204 int bytes_read = |
220 QuicSocketUtils::ReadPacket(fd, buf, arraysize(buf), | 205 QuicSocketUtils::ReadPacket(fd, buf, arraysize(buf), |
221 packets_dropped, | 206 packets_dropped, |
222 &server_ip, &client_address); | 207 &server_ip, &client_address); |
223 | 208 |
224 if (bytes_read < 0) { | 209 if (bytes_read < 0) { |
225 return false; // We failed to read. | 210 return false; // We failed to read. |
226 } | 211 } |
227 | 212 |
228 QuicEncryptedPacket packet(buf, bytes_read, false); | 213 QuicEncryptedPacket packet(buf, bytes_read, false); |
229 | 214 |
230 IPEndPoint server_address(server_ip, port); | 215 IPEndPoint server_address(server_ip, port); |
231 MaybeDispatchPacket(dispatcher, packet, server_address, client_address); | 216 dispatcher->ProcessPacket(server_address, client_address, packet); |
232 | 217 |
233 return true; | 218 return true; |
234 } | 219 } |
235 | 220 |
236 } // namespace tools | 221 } // namespace tools |
237 } // namespace net | 222 } // namespace net |
OLD | NEW |