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

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

Issue 358493002: Land recent SPDY changes (through 70021377) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on code-review-feedback updates. Created 6 years, 6 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/mock_spdy_framer_visitor.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"
11 #include "net/spdy/spdy_protocol.h" 11 #include "net/spdy/spdy_protocol.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 namespace { 15 namespace {
16 16
17 // A special structure for the 8 bit flags and 24 bit length fields. 17 // A special structure for the 8 bit flags and 24 bit length fields.
18 union FlagsAndLength { 18 union FlagsAndLength {
19 uint8 flags_[4]; // 8 bits 19 uint8 flags[4]; // 8 bits
20 uint32 length_; // 24 bits 20 uint32 length; // 24 bits
21 }; 21 };
22 22
23 // Creates a FlagsAndLength. 23 // Creates a FlagsAndLength.
24 FlagsAndLength CreateFlagsAndLength(uint8 flags, size_t length) { 24 FlagsAndLength CreateFlagsAndLength(uint8 flags, size_t length) {
25 DCHECK_EQ(0u, length & ~static_cast<size_t>(kLengthMask)); 25 DCHECK_EQ(0u, length & ~static_cast<size_t>(kLengthMask));
26 FlagsAndLength flags_length; 26 FlagsAndLength flags_length;
27 flags_length.length_ = htonl(static_cast<uint32>(length)); 27 flags_length.length = htonl(static_cast<uint32>(length));
28 DCHECK_EQ(0, flags & ~kControlFlagsMask); 28 DCHECK_EQ(0, flags & ~kControlFlagsMask);
29 flags_length.flags_[0] = flags; 29 flags_length.flags[0] = flags;
30 return flags_length; 30 return flags_length;
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 SpdyFrameBuilder::SpdyFrameBuilder(size_t size, SpdyMajorVersion version) 35 SpdyFrameBuilder::SpdyFrameBuilder(size_t size, SpdyMajorVersion version)
36 : buffer_(new char[size]), 36 : buffer_(new char[size]),
37 capacity_(size), 37 capacity_(size),
38 length_(0), 38 length_(0),
39 offset_(0), 39 offset_(0),
40 version_(version) { 40 version_(version) {
41 } 41 }
42 42
43 SpdyFrameBuilder::~SpdyFrameBuilder() { 43 SpdyFrameBuilder::~SpdyFrameBuilder() {
44 } 44 }
45 45
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 uint8 flags) { 82 uint8 flags) {
83 if (version_ > SPDY3) { 83 if (version_ > SPDY3) {
84 return BeginNewFrame(framer, DATA, flags, stream_id); 84 return BeginNewFrame(framer, DATA, flags, stream_id);
85 } 85 }
86 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); 86 DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
87 bool success = true; 87 bool success = true;
88 success &= WriteUInt32(stream_id); 88 success &= WriteUInt32(stream_id);
89 size_t length_field = capacity_ - framer.GetDataFrameMinimumSize(); 89 size_t length_field = capacity_ - framer.GetDataFrameMinimumSize();
90 DCHECK_EQ(0u, length_field & ~static_cast<size_t>(kLengthMask)); 90 DCHECK_EQ(0u, length_field & ~static_cast<size_t>(kLengthMask));
91 FlagsAndLength flags_length; 91 FlagsAndLength flags_length;
92 flags_length.length_ = htonl(length_field); 92 flags_length.length = htonl(length_field);
93 DCHECK_EQ(0, flags & ~kDataFlagsMask); 93 DCHECK_EQ(0, flags & ~kDataFlagsMask);
94 flags_length.flags_[0] = flags; 94 flags_length.flags[0] = flags;
95 success &= WriteBytes(&flags_length, sizeof(flags_length)); 95 success &= WriteBytes(&flags_length, sizeof(flags_length));
96 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length()); 96 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length());
97 return success; 97 return success;
98 } 98 }
99 99
100 bool SpdyFrameBuilder::BeginNewFrame(const SpdyFramer& framer, 100 bool SpdyFrameBuilder::BeginNewFrame(const SpdyFramer& framer,
101 SpdyFrameType type, 101 SpdyFrameType type,
102 uint8 flags, 102 uint8 flags,
103 SpdyStreamId stream_id) { 103 SpdyStreamId stream_id) {
104 DCHECK(SpdyConstants::IsValidFrameType(version_, 104 DCHECK(SpdyConstants::IsValidFrameType(version_,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/mock_spdy_framer_visitor.h ('k') | net/spdy/spdy_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698