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

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

Issue 485833002: HTTP2 draft 14 support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ignore_result(). Created 6 years, 4 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/spdy/spdy_frame_builder.h ('k') | net/spdy/spdy_framer.h » ('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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 << " is longer than the maximum allowed length."; 114 << " is longer than the maximum allowed length.";
115 } 115 }
116 116
117 offset_ += length_; 117 offset_ += length_;
118 length_ = 0; 118 length_ = 0;
119 119
120 // Assume all remaining capacity will be used for this frame. If not, 120 // Assume all remaining capacity will be used for this frame. If not,
121 // the length will get overwritten when we begin the next frame. 121 // the length will get overwritten when we begin the next frame.
122 // Don't check for length limits here because this may be larger than the 122 // Don't check for length limits here because this may be larger than the
123 // actual frame length. 123 // actual frame length.
124 success &= WriteUInt16(capacity_ - offset_ - framer.GetPrefixLength(type)); 124 success &= WriteUInt24(capacity_ - offset_ - framer.GetPrefixLength(type));
125 success &= WriteUInt8( 125 success &= WriteUInt8(
126 SpdyConstants::SerializeFrameType(version_, type)); 126 SpdyConstants::SerializeFrameType(version_, type));
127 success &= WriteUInt8(flags); 127 success &= WriteUInt8(flags);
128 success &= WriteUInt32(stream_id); 128 success &= WriteUInt32(stream_id);
129 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length_); 129 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length_);
130 return success; 130 return success;
131 } 131 }
132 132
133 bool SpdyFrameBuilder::WriteString(const std::string& value) { 133 bool SpdyFrameBuilder::WriteString(const std::string& value) {
134 if (value.size() > 0xffff) { 134 if (value.size() > 0xffff) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 FlagsAndLength flags_length = CreateFlagsAndLength( 182 FlagsAndLength flags_length = CreateFlagsAndLength(
183 0, // We're not writing over the flags value anyway. 183 0, // We're not writing over the flags value anyway.
184 length); 184 length);
185 185
186 // Write into the correct location by temporarily faking the offset. 186 // Write into the correct location by temporarily faking the offset.
187 length_ = 5; // Offset at which the length field occurs. 187 length_ = 5; // Offset at which the length field occurs.
188 success = WriteBytes(reinterpret_cast<char*>(&flags_length) + 1, 188 success = WriteBytes(reinterpret_cast<char*>(&flags_length) + 1,
189 sizeof(flags_length) - 1); 189 sizeof(flags_length) - 1);
190 } else { 190 } else {
191 length_ = 0; 191 length_ = 0;
192 success = WriteUInt16(length); 192 success = WriteUInt24(length);
193 } 193 }
194 194
195 length_ = old_length; 195 length_ = old_length;
196 return success; 196 return success;
197 } 197 }
198 198
199 bool SpdyFrameBuilder::OverwriteFlags(const SpdyFramer& framer, 199 bool SpdyFrameBuilder::OverwriteFlags(const SpdyFramer& framer,
200 uint8 flags) { 200 uint8 flags) {
201 DCHECK_LT(SPDY3, framer.protocol_version()); 201 DCHECK_LT(SPDY3, framer.protocol_version());
202 bool success = false; 202 bool success = false;
203 const size_t old_length = length_; 203 const size_t old_length = length_;
204 // Flags are the fourth octet in the frame prefix. 204 // Flags are the fifth octet in the frame prefix.
205 length_ = 3; 205 length_ = 4;
206 success = WriteUInt8(flags); 206 success = WriteUInt8(flags);
207 length_ = old_length; 207 length_ = old_length;
208 return success; 208 return success;
209 } 209 }
210 210
211 bool SpdyFrameBuilder::CanWrite(size_t length) const { 211 bool SpdyFrameBuilder::CanWrite(size_t length) const {
212 if (length > kLengthMask) { 212 if (length > kLengthMask) {
213 DCHECK(false); 213 DCHECK(false);
214 return false; 214 return false;
215 } 215 }
216 216
217 if (offset_ + length_ + length > capacity_) { 217 if (offset_ + length_ + length > capacity_) {
218 DCHECK(false); 218 DCHECK(false);
219 return false; 219 return false;
220 } 220 }
221 221
222 return true; 222 return true;
223 } 223 }
224 224
225 } // namespace net 225 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_frame_builder.h ('k') | net/spdy/spdy_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698