| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Upstream DCHECK's that capacity_ is under the maximum frame size at this | 105 // 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 | 106 // point. Chromium does not, because of the large additional zlib inflation |
| 107 // factor we use. (Frame size is is still checked by OverwriteLength() below). | 107 // factor we use. (Frame size is is still checked by OverwriteLength() below). |
| 108 success &= WriteUInt16(capacity_); | 108 if (type != DATA) { |
| 109 success &= WriteUInt16(capacity_ - framer.GetControlFrameHeaderSize()); |
| 110 } else { |
| 111 success &= WriteUInt16(capacity_ - framer.GetDataFrameMinimumSize()); |
| 112 } |
| 109 success &= WriteUInt8(type); | 113 success &= WriteUInt8(type); |
| 110 success &= WriteUInt8(flags); | 114 success &= WriteUInt8(flags); |
| 111 success &= WriteUInt32(stream_id); | 115 success &= WriteUInt32(stream_id); |
| 112 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length()); | 116 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length()); |
| 113 return success; | 117 return success; |
| 114 } | 118 } |
| 115 | 119 |
| 116 bool SpdyFrameBuilder::WriteString(const std::string& value) { | 120 bool SpdyFrameBuilder::WriteString(const std::string& value) { |
| 117 if (value.size() > 0xffff) { | 121 if (value.size() > 0xffff) { |
| 118 DCHECK(false) << "Tried to write string with length > 16bit."; | 122 DCHECK(false) << "Tried to write string with length > 16bit."; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 138 return false; | 142 return false; |
| 139 } | 143 } |
| 140 | 144 |
| 141 char* dest = GetWritableBuffer(data_len); | 145 char* dest = GetWritableBuffer(data_len); |
| 142 memcpy(dest, data, data_len); | 146 memcpy(dest, data, data_len); |
| 143 Seek(data_len); | 147 Seek(data_len); |
| 144 return true; | 148 return true; |
| 145 } | 149 } |
| 146 | 150 |
| 147 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { | 151 bool SpdyFrameBuilder::RewriteLength(const SpdyFramer& framer) { |
| 148 if (framer.protocol_version() < 4) { | 152 return OverwriteLength(framer, |
| 149 return OverwriteLength(framer, | 153 length_ - framer.GetControlFrameHeaderSize()); |
| 150 length_ - framer.GetControlFrameHeaderSize()); | |
| 151 } else { | |
| 152 return OverwriteLength(framer, length_); | |
| 153 } | |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, | 156 bool SpdyFrameBuilder::OverwriteLength(const SpdyFramer& framer, |
| 157 size_t length) { | 157 size_t length) { |
| 158 if (framer.protocol_version() < 4) { | 158 if (framer.protocol_version() < 4) { |
| 159 DCHECK_GT(framer.GetFrameMaximumSize() - framer.GetFrameMinimumSize(), | 159 DCHECK_GT(framer.GetFrameMaximumSize() - framer.GetFrameMinimumSize(), |
| 160 length); | 160 length); |
| 161 } else { | 161 } else { |
| 162 DCHECK_GE(framer.GetFrameMaximumSize(), length); | 162 DCHECK_GE(framer.GetFrameMaximumSize(), length); |
| 163 } | 163 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 190 | 190 |
| 191 if (length_ + length > capacity_) { | 191 if (length_ + length > capacity_) { |
| 192 DCHECK(false); | 192 DCHECK(false); |
| 193 return false; | 193 return false; |
| 194 } | 194 } |
| 195 | 195 |
| 196 return true; | 196 return true; |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace net | 199 } // namespace net |
| OLD | NEW |