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

Side by Side Diff: net/spdy/spdy_frame_builder.cc

Issue 202403002: Land recent SPDY changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase. Back out commits included for trybot benefit, but separately landed upstream. Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_frame_builder.h ('k') | net/spdy/spdy_frame_builder_test.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/spdy/spdy_frame_builder.h" 5 #include "net/spdy/spdy_frame_builder.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "net/spdy/spdy_framer.h" 10 #include "net/spdy/spdy_framer.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 return false; 53 return false;
54 } 54 }
55 55
56 length_ += length; 56 length_ += length;
57 return true; 57 return true;
58 } 58 }
59 59
60 bool SpdyFrameBuilder::WriteControlFrameHeader(const SpdyFramer& framer, 60 bool SpdyFrameBuilder::WriteControlFrameHeader(const SpdyFramer& framer,
61 SpdyFrameType type, 61 SpdyFrameType type,
62 uint8 flags) { 62 uint8 flags) {
63 DCHECK_GE(type, FIRST_CONTROL_TYPE);
64 DCHECK_LE(type, LAST_CONTROL_TYPE);
65 DCHECK_GT(4, framer.protocol_version()); 63 DCHECK_GT(4, framer.protocol_version());
64 DCHECK_NE(-1,
65 SpdyConstants::SerializeFrameType(framer.protocol_version(), type));
66 bool success = true; 66 bool success = true;
67 FlagsAndLength flags_length = CreateFlagsAndLength( 67 FlagsAndLength flags_length = CreateFlagsAndLength(
68 flags, capacity_ - framer.GetControlFrameHeaderSize()); 68 flags, capacity_ - framer.GetControlFrameHeaderSize());
69 success &= WriteUInt16(kControlFlagMask | framer.protocol_version()); 69 success &= WriteUInt16(kControlFlagMask | framer.protocol_version());
70 success &= WriteUInt16(type); 70 success &= WriteUInt16(
71 SpdyConstants::SerializeFrameType(framer.protocol_version(), type));
71 success &= WriteBytes(&flags_length, sizeof(flags_length)); 72 success &= WriteBytes(&flags_length, sizeof(flags_length));
72 DCHECK_EQ(framer.GetControlFrameHeaderSize(), length()); 73 DCHECK_EQ(framer.GetControlFrameHeaderSize(), length());
73 return success; 74 return success;
74 } 75 }
75 76
76 bool SpdyFrameBuilder::WriteDataFrameHeader(const SpdyFramer& framer, 77 bool SpdyFrameBuilder::WriteDataFrameHeader(const SpdyFramer& framer,
77 SpdyStreamId stream_id, 78 SpdyStreamId stream_id,
78 SpdyDataFlags flags) { 79 uint8 flags) {
79 if (framer.protocol_version() >= 4) { 80 if (framer.protocol_version() >= 4) {
80 return WriteFramePrefix(framer, DATA, flags, stream_id); 81 return WriteFramePrefix(framer, DATA, flags, stream_id);
81 } 82 }
82 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); 83 DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
83 bool success = true; 84 bool success = true;
84 success &= WriteUInt32(stream_id); 85 success &= WriteUInt32(stream_id);
85 size_t length_field = capacity_ - framer.GetDataFrameMinimumSize(); 86 size_t length_field = capacity_ - framer.GetDataFrameMinimumSize();
86 DCHECK_EQ(0u, length_field & ~static_cast<size_t>(kLengthMask)); 87 DCHECK_EQ(0u, length_field & ~static_cast<size_t>(kLengthMask));
87 FlagsAndLength flags_length; 88 FlagsAndLength flags_length;
88 flags_length.length_ = htonl(length_field); 89 flags_length.length_ = htonl(length_field);
89 DCHECK_EQ(0, flags & ~kDataFlagsMask); 90 DCHECK_EQ(0, flags & ~kDataFlagsMask);
90 flags_length.flags_[0] = flags; 91 flags_length.flags_[0] = flags;
91 success &= WriteBytes(&flags_length, sizeof(flags_length)); 92 success &= WriteBytes(&flags_length, sizeof(flags_length));
92 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length()); 93 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length());
93 return success; 94 return success;
94 } 95 }
95 96
96 bool SpdyFrameBuilder::WriteFramePrefix(const SpdyFramer& framer, 97 bool SpdyFrameBuilder::WriteFramePrefix(const SpdyFramer& framer,
97 SpdyFrameType type, 98 SpdyFrameType type,
98 uint8 flags, 99 uint8 flags,
99 SpdyStreamId stream_id) { 100 SpdyStreamId stream_id) {
100 DCHECK_LE(DATA, type); 101 DCHECK_NE(-1,
101 DCHECK_GE(LAST_CONTROL_TYPE, type); 102 SpdyConstants::SerializeFrameType(framer.protocol_version(), type));
102 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); 103 DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
103 DCHECK_LE(4, framer.protocol_version()); 104 DCHECK_LE(4, framer.protocol_version());
104 bool success = true; 105 bool success = true;
105 // Upstream DCHECK's that capacity_ is under the maximum frame size at this 106 // Upstream DCHECK's that capacity_ is under the maximum frame size at this
106 // point. Chromium does not, because of the large additional zlib inflation 107 // point. Chromium does not, because of the large additional zlib inflation
107 // factor we use. (Frame size is is still checked by OverwriteLength() below). 108 // factor we use. (Frame size is is still checked by OverwriteLength() below).
108 success &= WriteUInt16(capacity_); 109 if (type != DATA) {
109 success &= WriteUInt8(type); 110 success &= WriteUInt16(capacity_ - framer.GetControlFrameHeaderSize());
111 } else {
112 success &= WriteUInt16(capacity_ - framer.GetDataFrameMinimumSize());
113 }
114 success &= WriteUInt8(
115 SpdyConstants::SerializeFrameType(framer.protocol_version(), type));
110 success &= WriteUInt8(flags); 116 success &= WriteUInt8(flags);
111 success &= WriteUInt32(stream_id); 117 success &= WriteUInt32(stream_id);
112 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length()); 118 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length());
113 return success; 119 return success;
114 } 120 }
115 121
116 bool SpdyFrameBuilder::WriteString(const std::string& value) { 122 bool SpdyFrameBuilder::WriteString(const std::string& value) {
117 if (value.size() > 0xffff) { 123 if (value.size() > 0xffff) {
118 DCHECK(false) << "Tried to write string with length > 16bit."; 124 DCHECK(false) << "Tried to write string with length > 16bit.";
119 return false; 125 return false;
(...skipping 18 matching lines...) Expand all
138 return false; 144 return false;
139 } 145 }
140 146
141 char* dest = GetWritableBuffer(data_len); 147 char* dest = GetWritableBuffer(data_len);
142 memcpy(dest, data, data_len); 148 memcpy(dest, data, data_len);
143 Seek(data_len); 149 Seek(data_len);
144 return true; 150 return true;
145 } 151 }
146 152
147 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { 153 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) {
148 if (framer.protocol_version() < 4) { 154 return OverwriteLength(framer,
149 return OverwriteLength(framer, 155 length_ - framer.GetControlFrameHeaderSize());
150 length_ - framer.GetControlFrameHeaderSize());
151 } else {
152 return OverwriteLength(framer, length_);
153 }
154 } 156 }
155 157
156 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, 158 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer,
157 size_t length) { 159 size_t length) {
158 if (framer.protocol_version() < 4) { 160 if (framer.protocol_version() < 4) {
159 DCHECK_GT(framer.GetFrameMaximumSize() - framer.GetFrameMinimumSize(), 161 DCHECK_GT(framer.GetFrameMaximumSize() - framer.GetFrameMinimumSize(),
160 length); 162 length);
161 } else { 163 } else {
162 DCHECK_GE(framer.GetFrameMaximumSize(), length); 164 DCHECK_GE(framer.GetFrameMaximumSize(), length);
163 } 165 }
(...skipping 11 matching lines...) Expand all
175 sizeof(flags_length) - 1); 177 sizeof(flags_length) - 1);
176 } else { 178 } else {
177 length_ = 0; 179 length_ = 0;
178 success = WriteUInt16(length); 180 success = WriteUInt16(length);
179 } 181 }
180 182
181 length_ = old_length; 183 length_ = old_length;
182 return success; 184 return success;
183 } 185 }
184 186
187 bool SpdyFrameBuilder::OverwriteFlags(const SpdyFramer& framer,
188 uint8 flags) {
189 DCHECK_LE(SPDY4, framer.protocol_version());
190 bool success = false;
191 const size_t old_length = length_;
192 // Flags are the fourth octet in the frame prefix.
193 length_ = 3;
194 success = WriteUInt8(flags);
195 length_ = old_length;
196 return success;
197 }
198
185 bool SpdyFrameBuilder::CanWrite(size_t length) const { 199 bool SpdyFrameBuilder::CanWrite(size_t length) const {
186 if (length > kLengthMask) { 200 if (length > kLengthMask) {
187 DCHECK(false); 201 DCHECK(false);
188 return false; 202 return false;
189 } 203 }
190 204
191 if (length_ + length > capacity_) { 205 if (length_ + length > capacity_) {
192 DCHECK(false); 206 DCHECK(false);
193 return false; 207 return false;
194 } 208 }
195 209
196 return true; 210 return true;
197 } 211 }
198 212
199 } // namespace net 213 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_frame_builder.h ('k') | net/spdy/spdy_frame_builder_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698