| 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 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't | 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't |
| 6 // constantly adding and subtracting header sizes; this is ugly and error- | 6 // constantly adding and subtracting header sizes; this is ugly and error- |
| 7 // prone. | 7 // prone. |
| 8 | 8 |
| 9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
| 10 | 10 |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 uint32 length_field = 0; | 656 uint32 length_field = 0; |
| 657 successful_read = reader->ReadUInt24(&length_field); | 657 successful_read = reader->ReadUInt24(&length_field); |
| 658 DCHECK(successful_read); | 658 DCHECK(successful_read); |
| 659 remaining_data_length_ = length_field; | 659 remaining_data_length_ = length_field; |
| 660 current_frame_length_ = remaining_data_length_ + reader->GetBytesConsumed(); | 660 current_frame_length_ = remaining_data_length_ + reader->GetBytesConsumed(); |
| 661 } else { | 661 } else { |
| 662 version = protocol_version(); | 662 version = protocol_version(); |
| 663 uint16 length_field = 0; | 663 uint16 length_field = 0; |
| 664 bool successful_read = reader->ReadUInt16(&length_field); | 664 bool successful_read = reader->ReadUInt16(&length_field); |
| 665 DCHECK(successful_read); | 665 DCHECK(successful_read); |
| 666 current_frame_length_ = length_field; | |
| 667 | 666 |
| 668 uint8 control_frame_type_field_uint8 = DATA; | 667 uint8 control_frame_type_field_uint8 = DATA; |
| 669 successful_read = reader->ReadUInt8(&control_frame_type_field_uint8); | 668 successful_read = reader->ReadUInt8(&control_frame_type_field_uint8); |
| 670 DCHECK(successful_read); | 669 DCHECK(successful_read); |
| 671 // We check control_frame_type_field's validity in | 670 // We check control_frame_type_field's validity in |
| 672 // ProcessControlFrameHeader(). | 671 // ProcessControlFrameHeader(). |
| 673 control_frame_type_field = control_frame_type_field_uint8; | 672 control_frame_type_field = control_frame_type_field_uint8; |
| 674 is_control_frame = (control_frame_type_field != DATA); | 673 is_control_frame = (control_frame_type_field != DATA); |
| 675 | 674 |
| 675 if (is_control_frame) { |
| 676 current_frame_length_ = length_field + GetControlFrameHeaderSize(); |
| 677 } else { |
| 678 current_frame_length_ = length_field + GetDataFrameMinimumSize(); |
| 679 } |
| 680 |
| 676 successful_read = reader->ReadUInt8(¤t_frame_flags_); | 681 successful_read = reader->ReadUInt8(¤t_frame_flags_); |
| 677 DCHECK(successful_read); | 682 DCHECK(successful_read); |
| 678 | 683 |
| 679 successful_read = reader->ReadUInt31(¤t_frame_stream_id_); | 684 successful_read = reader->ReadUInt31(¤t_frame_stream_id_); |
| 680 DCHECK(successful_read); | 685 DCHECK(successful_read); |
| 681 | 686 |
| 682 remaining_data_length_ = current_frame_length_ - reader->GetBytesConsumed(); | 687 remaining_data_length_ = current_frame_length_ - reader->GetBytesConsumed(); |
| 683 | 688 |
| 684 // Before we accept a DATA frame, we need to make sure we're not in the | 689 // Before we accept a DATA frame, we need to make sure we're not in the |
| 685 // middle of processing a header block. | 690 // middle of processing a header block. |
| (...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 if (data.pad_low()) { | 2066 if (data.pad_low()) { |
| 2062 flags |= DATA_FLAG_PAD_LOW; | 2067 flags |= DATA_FLAG_PAD_LOW; |
| 2063 } | 2068 } |
| 2064 if (data.pad_high()) { | 2069 if (data.pad_high()) { |
| 2065 flags |= DATA_FLAG_PAD_HIGH; | 2070 flags |= DATA_FLAG_PAD_HIGH; |
| 2066 } | 2071 } |
| 2067 } | 2072 } |
| 2068 | 2073 |
| 2069 SpdyFrameBuilder builder(kSize); | 2074 SpdyFrameBuilder builder(kSize); |
| 2070 builder.WriteDataFrameHeader(*this, data.stream_id(), flags); | 2075 builder.WriteDataFrameHeader(*this, data.stream_id(), flags); |
| 2071 if (protocol_version() >= 4) { | 2076 builder.OverwriteLength(*this, data.data().length()); |
| 2072 builder.OverwriteLength(*this, data.data().length() + kSize); | |
| 2073 } else { | |
| 2074 builder.OverwriteLength(*this, data.data().length()); | |
| 2075 } | |
| 2076 DCHECK_EQ(kSize, builder.length()); | 2077 DCHECK_EQ(kSize, builder.length()); |
| 2077 return builder.take(); | 2078 return builder.take(); |
| 2078 } | 2079 } |
| 2079 | 2080 |
| 2080 SpdySerializedFrame* SpdyFramer::SerializeSynStream( | 2081 SpdySerializedFrame* SpdyFramer::SerializeSynStream( |
| 2081 const SpdySynStreamIR& syn_stream) { | 2082 const SpdySynStreamIR& syn_stream) { |
| 2082 uint8 flags = 0; | 2083 uint8 flags = 0; |
| 2083 if (syn_stream.fin()) { | 2084 if (syn_stream.fin()) { |
| 2084 flags |= CONTROL_FLAG_FIN; | 2085 flags |= CONTROL_FLAG_FIN; |
| 2085 } | 2086 } |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2834 builder->Seek(compressed_size); | 2835 builder->Seek(compressed_size); |
| 2835 builder->RewriteLength(*this); | 2836 builder->RewriteLength(*this); |
| 2836 | 2837 |
| 2837 pre_compress_bytes.Add(uncompressed_len); | 2838 pre_compress_bytes.Add(uncompressed_len); |
| 2838 post_compress_bytes.Add(compressed_size); | 2839 post_compress_bytes.Add(compressed_size); |
| 2839 | 2840 |
| 2840 compressed_frames.Increment(); | 2841 compressed_frames.Increment(); |
| 2841 } | 2842 } |
| 2842 | 2843 |
| 2843 } // namespace net | 2844 } // namespace net |
| OLD | NEW |