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 #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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 bool SpdyFrameBuilder::WriteFramePrefix(const SpdyFramer& framer, | 96 bool SpdyFrameBuilder::WriteFramePrefix(const SpdyFramer& framer, |
97 SpdyFrameType type, | 97 SpdyFrameType type, |
98 uint8 flags, | 98 uint8 flags, |
99 SpdyStreamId stream_id) { | 99 SpdyStreamId stream_id) { |
100 DCHECK_LE(DATA, type); | 100 DCHECK_LE(DATA, type); |
101 DCHECK_GE(LAST_CONTROL_TYPE, type); | 101 DCHECK_GE(LAST_CONTROL_TYPE, type); |
102 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); | 102 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); |
103 DCHECK_LE(4, framer.protocol_version()); | 103 DCHECK_LE(4, framer.protocol_version()); |
104 bool success = true; | 104 bool success = true; |
105 DCHECK_GT(1u<<16, capacity_); // Make sure length fits in 2B. | 105 size_t length_field = capacity_ - 8; |
106 success &= WriteUInt16(capacity_); | 106 DCHECK_GT(1u<<16, length_field); // Make sure length fits in 16. |
| 107 success &= WriteUInt16(length_field); |
107 success &= WriteUInt8(type); | 108 success &= WriteUInt8(type); |
108 success &= WriteUInt8(flags); | 109 success &= WriteUInt8(flags); |
109 success &= WriteUInt32(stream_id); | 110 success &= WriteUInt32(stream_id); |
110 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length()); | 111 DCHECK_EQ(length(), 8u); |
111 return success; | 112 return success; |
112 } | 113 } |
113 | 114 |
114 bool SpdyFrameBuilder::WriteString(const std::string& value) { | 115 bool SpdyFrameBuilder::WriteString(const std::string& value) { |
115 if (value.size() > 0xffff) { | 116 if (value.size() > 0xffff) { |
116 DCHECK(false) << "Tried to write string with length > 16bit."; | 117 DCHECK(false) << "Tried to write string with length > 16bit."; |
117 return false; | 118 return false; |
118 } | 119 } |
119 | 120 |
120 if (!WriteUInt16(static_cast<int>(value.size()))) | 121 if (!WriteUInt16(static_cast<int>(value.size()))) |
(...skipping 19 matching lines...) Expand all Loading... |
140 memcpy(dest, data, data_len); | 141 memcpy(dest, data, data_len); |
141 Seek(data_len); | 142 Seek(data_len); |
142 return true; | 143 return true; |
143 } | 144 } |
144 | 145 |
145 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { | 146 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { |
146 if (framer.protocol_version() < 4) { | 147 if (framer.protocol_version() < 4) { |
147 return OverwriteLength(framer, | 148 return OverwriteLength(framer, |
148 length_ - framer.GetControlFrameHeaderSize()); | 149 length_ - framer.GetControlFrameHeaderSize()); |
149 } else { | 150 } else { |
150 return OverwriteLength(framer, length_); | 151 return OverwriteLength(framer, length_ - 8); |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, | 155 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, |
155 size_t length) { | 156 size_t length) { |
156 bool success = false; | 157 bool success = false; |
157 const size_t old_length = length_; | 158 const size_t old_length = length_; |
158 | 159 |
159 if (framer.protocol_version() < 4) { | 160 if (framer.protocol_version() < 4) { |
160 FlagsAndLength flags_length = CreateFlagsAndLength( | 161 FlagsAndLength flags_length = CreateFlagsAndLength( |
(...skipping 21 matching lines...) Expand all Loading... |
182 | 183 |
183 if (length_ + length > capacity_) { | 184 if (length_ + length > capacity_) { |
184 DCHECK(false); | 185 DCHECK(false); |
185 return false; | 186 return false; |
186 } | 187 } |
187 | 188 |
188 return true; | 189 return true; |
189 } | 190 } |
190 | 191 |
191 } // namespace net | 192 } // namespace net |
OLD | NEW |