| 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/core/spdy_frame_builder.h" | 5 #include "net/spdy/core/spdy_frame_builder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <new> | 10 #include <new> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "net/spdy/core/spdy_bug_tracker.h" | 13 #include "net/spdy/core/spdy_bug_tracker.h" |
| 14 #include "net/spdy/core/spdy_framer.h" | 14 #include "net/spdy/core/spdy_framer.h" |
| 15 #include "net/spdy/core/spdy_protocol.h" | 15 #include "net/spdy/core/spdy_protocol.h" |
| 16 #include "net/spdy/core/zero_copy_output_buffer.h" | 16 #include "net/spdy/core/zero_copy_output_buffer.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 SpdyFrameBuilder::SpdyFrameBuilder(size_t size) | 20 SpdyFrameBuilder::SpdyFrameBuilder(size_t size) |
| 21 : buffer_(new char[size]), capacity_(size), length_(0), offset_(0) {} | 21 : buffer_(new char[size]), capacity_(size), length_(0), offset_(0) {} |
| 22 | 22 |
| 23 SpdyFrameBuilder::SpdyFrameBuilder(size_t size, ZeroCopyOutputBuffer* output) | 23 SpdyFrameBuilder::SpdyFrameBuilder(size_t size, ZeroCopyOutputBuffer* output) |
| 24 : buffer_(output == nullptr ? new char[size] : nullptr), | 24 : buffer_(output == nullptr ? new char[size] : nullptr), |
| 25 output_(output), | 25 output_(output), |
| 26 capacity_(size), | 26 capacity_(size), |
| 27 length_(0), | 27 length_(0), |
| 28 offset_(0) {} | 28 offset_(0) {} |
| 29 | 29 |
| 30 SpdyFrameBuilder::~SpdyFrameBuilder() { | 30 SpdyFrameBuilder::~SpdyFrameBuilder() {} |
| 31 } | |
| 32 | 31 |
| 33 char* SpdyFrameBuilder::GetWritableBuffer(size_t length) { | 32 char* SpdyFrameBuilder::GetWritableBuffer(size_t length) { |
| 34 if (!CanWrite(length)) { | 33 if (!CanWrite(length)) { |
| 35 return nullptr; | 34 return nullptr; |
| 36 } | 35 } |
| 37 return buffer_.get() + offset_ + length_; | 36 return buffer_.get() + offset_ + length_; |
| 38 } | 37 } |
| 39 | 38 |
| 40 char* SpdyFrameBuilder::GetWritableOutput(size_t length, | 39 char* SpdyFrameBuilder::GetWritableOutput(size_t length, |
| 41 size_t* actual_length) { | 40 size_t* actual_length) { |
| 42 char* dest = nullptr; | 41 char* dest = nullptr; |
| 43 int size = 0; | 42 int size = 0; |
| 44 | 43 |
| 45 if (!CanWrite(length)) { | 44 if (!CanWrite(length)) { |
| 46 return nullptr; | 45 return nullptr; |
| 47 } | 46 } |
| 48 output_->Next(&dest, &size); | 47 output_->Next(&dest, &size); |
| 49 *actual_length = std::min(length, (size_t)size); | 48 *actual_length = std::min<size_t>(length, size); |
| 50 return dest; | 49 return dest; |
| 51 } | 50 } |
| 52 | 51 |
| 53 bool SpdyFrameBuilder::Seek(size_t length) { | 52 bool SpdyFrameBuilder::Seek(size_t length) { |
| 54 if (!CanWrite(length)) { | 53 if (!CanWrite(length)) { |
| 55 return false; | 54 return false; |
| 56 } | 55 } |
| 57 if (output_ == nullptr) { | 56 if (output_ == nullptr) { |
| 58 length_ += length; | 57 length_ += length; |
| 59 } else { | 58 } else { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } else { | 195 } else { |
| 197 if (length > output_->BytesFree()) { | 196 if (length > output_->BytesFree()) { |
| 198 return false; | 197 return false; |
| 199 } | 198 } |
| 200 } | 199 } |
| 201 | 200 |
| 202 return true; | 201 return true; |
| 203 } | 202 } |
| 204 | 203 |
| 205 } // namespace net | 204 } // namespace net |
| OLD | NEW |