Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: net/quic/quic_framer.cc

Issue 1421593004: Change QuicFramer::BuildDataPacket to return a length instead of QuicPacket* in order to reduce mem… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@105596142
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_framer.h ('k') | net/quic/quic_packet_creator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/quic/quic_framer.h" 5 #include "net/quic/quic_framer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 QuicFramer::AckFrameInfo::AckFrameInfo() : max_delta(0) {} 314 QuicFramer::AckFrameInfo::AckFrameInfo() : max_delta(0) {}
315 315
316 QuicFramer::AckFrameInfo::~AckFrameInfo() {} 316 QuicFramer::AckFrameInfo::~AckFrameInfo() {}
317 317
318 // static 318 // static
319 QuicPacketEntropyHash QuicFramer::GetPacketEntropyHash( 319 QuicPacketEntropyHash QuicFramer::GetPacketEntropyHash(
320 const QuicPacketHeader& header) { 320 const QuicPacketHeader& header) {
321 return header.entropy_flag << (header.packet_number % 8); 321 return header.entropy_flag << (header.packet_number % 8);
322 } 322 }
323 323
324 QuicPacket* QuicFramer::BuildDataPacket(const QuicPacketHeader& header, 324 size_t QuicFramer::BuildDataPacket(const QuicPacketHeader& header,
325 const QuicFrames& frames, 325 const QuicFrames& frames,
326 char* buffer, 326 char* buffer,
327 size_t packet_length) { 327 size_t packet_length) {
328 QuicDataWriter writer(packet_length, buffer); 328 QuicDataWriter writer(packet_length, buffer);
329 if (!AppendPacketHeader(header, &writer)) { 329 if (!AppendPacketHeader(header, &writer)) {
330 LOG(DFATAL) << "AppendPacketHeader failed"; 330 LOG(DFATAL) << "AppendPacketHeader failed";
331 return nullptr; 331 return 0;
332 } 332 }
333 333
334 size_t i = 0; 334 size_t i = 0;
335 for (const QuicFrame& frame : frames) { 335 for (const QuicFrame& frame : frames) {
336 // Determine if we should write stream frame length in header. 336 // Determine if we should write stream frame length in header.
337 const bool no_stream_frame_length = 337 const bool no_stream_frame_length =
338 (header.is_in_fec_group == NOT_IN_FEC_GROUP) && 338 (header.is_in_fec_group == NOT_IN_FEC_GROUP) &&
339 (i == frames.size() - 1); 339 (i == frames.size() - 1);
340 if (!AppendTypeByte(frame, no_stream_frame_length, &writer)) { 340 if (!AppendTypeByte(frame, no_stream_frame_length, &writer)) {
341 LOG(DFATAL) << "AppendTypeByte failed"; 341 LOG(DFATAL) << "AppendTypeByte failed";
342 return nullptr; 342 return 0;
343 } 343 }
344 344
345 switch (frame.type) { 345 switch (frame.type) {
346 case PADDING_FRAME: 346 case PADDING_FRAME:
347 writer.WritePadding(); 347 writer.WritePadding();
348 break; 348 break;
349 case STREAM_FRAME: 349 case STREAM_FRAME:
350 if (!AppendStreamFrame( 350 if (!AppendStreamFrame(
351 *frame.stream_frame, no_stream_frame_length, &writer)) { 351 *frame.stream_frame, no_stream_frame_length, &writer)) {
352 LOG(DFATAL) << "AppendStreamFrame failed"; 352 LOG(DFATAL) << "AppendStreamFrame failed";
353 return nullptr; 353 return 0;
354 } 354 }
355 break; 355 break;
356 case ACK_FRAME: 356 case ACK_FRAME:
357 if (!AppendAckFrameAndTypeByte( 357 if (!AppendAckFrameAndTypeByte(
358 header, *frame.ack_frame, &writer)) { 358 header, *frame.ack_frame, &writer)) {
359 LOG(DFATAL) << "AppendAckFrameAndTypeByte failed"; 359 LOG(DFATAL) << "AppendAckFrameAndTypeByte failed";
360 return nullptr; 360 return 0;
361 } 361 }
362 break; 362 break;
363 case STOP_WAITING_FRAME: 363 case STOP_WAITING_FRAME:
364 if (!AppendStopWaitingFrame( 364 if (!AppendStopWaitingFrame(
365 header, *frame.stop_waiting_frame, &writer)) { 365 header, *frame.stop_waiting_frame, &writer)) {
366 LOG(DFATAL) << "AppendStopWaitingFrame failed"; 366 LOG(DFATAL) << "AppendStopWaitingFrame failed";
367 return nullptr; 367 return 0;
368 } 368 }
369 break; 369 break;
370 case MTU_DISCOVERY_FRAME: 370 case MTU_DISCOVERY_FRAME:
371 // MTU discovery frames are serialized as ping frames. 371 // MTU discovery frames are serialized as ping frames.
372 case PING_FRAME: 372 case PING_FRAME:
373 // Ping has no payload. 373 // Ping has no payload.
374 break; 374 break;
375 case RST_STREAM_FRAME: 375 case RST_STREAM_FRAME:
376 if (!AppendRstStreamFrame(*frame.rst_stream_frame, &writer)) { 376 if (!AppendRstStreamFrame(*frame.rst_stream_frame, &writer)) {
377 LOG(DFATAL) << "AppendRstStreamFrame failed"; 377 LOG(DFATAL) << "AppendRstStreamFrame failed";
378 return nullptr; 378 return 0;
379 } 379 }
380 break; 380 break;
381 case CONNECTION_CLOSE_FRAME: 381 case CONNECTION_CLOSE_FRAME:
382 if (!AppendConnectionCloseFrame( 382 if (!AppendConnectionCloseFrame(
383 *frame.connection_close_frame, &writer)) { 383 *frame.connection_close_frame, &writer)) {
384 LOG(DFATAL) << "AppendConnectionCloseFrame failed"; 384 LOG(DFATAL) << "AppendConnectionCloseFrame failed";
385 return nullptr; 385 return 0;
386 } 386 }
387 break; 387 break;
388 case GOAWAY_FRAME: 388 case GOAWAY_FRAME:
389 if (!AppendGoAwayFrame(*frame.goaway_frame, &writer)) { 389 if (!AppendGoAwayFrame(*frame.goaway_frame, &writer)) {
390 LOG(DFATAL) << "AppendGoAwayFrame failed"; 390 LOG(DFATAL) << "AppendGoAwayFrame failed";
391 return nullptr; 391 return 0;
392 } 392 }
393 break; 393 break;
394 case WINDOW_UPDATE_FRAME: 394 case WINDOW_UPDATE_FRAME:
395 if (!AppendWindowUpdateFrame(*frame.window_update_frame, &writer)) { 395 if (!AppendWindowUpdateFrame(*frame.window_update_frame, &writer)) {
396 LOG(DFATAL) << "AppendWindowUpdateFrame failed"; 396 LOG(DFATAL) << "AppendWindowUpdateFrame failed";
397 return nullptr; 397 return 0;
398 } 398 }
399 break; 399 break;
400 case BLOCKED_FRAME: 400 case BLOCKED_FRAME:
401 if (!AppendBlockedFrame(*frame.blocked_frame, &writer)) { 401 if (!AppendBlockedFrame(*frame.blocked_frame, &writer)) {
402 LOG(DFATAL) << "AppendBlockedFrame failed"; 402 LOG(DFATAL) << "AppendBlockedFrame failed";
403 return nullptr; 403 return 0;
404 } 404 }
405 break; 405 break;
406 default: 406 default:
407 RaiseError(QUIC_INVALID_FRAME_DATA); 407 RaiseError(QUIC_INVALID_FRAME_DATA);
408 LOG(DFATAL) << "QUIC_INVALID_FRAME_DATA"; 408 LOG(DFATAL) << "QUIC_INVALID_FRAME_DATA";
409 return nullptr; 409 return 0;
410 } 410 }
411 ++i; 411 ++i;
412 } 412 }
413 413
414 QuicPacket* packet = 414 return writer.length();
415 new QuicPacket(writer.data(), writer.length(), false,
416 header.public_header.connection_id_length,
417 header.public_header.version_flag,
418 header.public_header.packet_number_length);
419
420 return packet;
421 } 415 }
422 416
423 QuicPacket* QuicFramer::BuildFecPacket(const QuicPacketHeader& header, 417 QuicPacket* QuicFramer::BuildFecPacket(const QuicPacketHeader& header,
424 StringPiece redundancy) { 418 StringPiece redundancy) {
425 DCHECK_EQ(IN_FEC_GROUP, header.is_in_fec_group); 419 DCHECK_EQ(IN_FEC_GROUP, header.is_in_fec_group);
426 DCHECK_NE(0u, header.fec_group); 420 DCHECK_NE(0u, header.fec_group);
427 size_t len = GetPacketHeaderSize(header); 421 size_t len = GetPacketHeaderSize(header);
428 len += redundancy.length(); 422 len += redundancy.length();
429 423
430 scoped_ptr<char[]> buffer(new char[len]); 424 scoped_ptr<char[]> buffer(new char[len]);
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 2212
2219 bool QuicFramer::RaiseError(QuicErrorCode error) { 2213 bool QuicFramer::RaiseError(QuicErrorCode error) {
2220 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) 2214 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error)
2221 << " detail: " << detailed_error_; 2215 << " detail: " << detailed_error_;
2222 set_error(error); 2216 set_error(error);
2223 visitor_->OnError(this); 2217 visitor_->OnError(this);
2224 return false; 2218 return false;
2225 } 2219 }
2226 2220
2227 } // namespace net 2221 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.h ('k') | net/quic/quic_packet_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698