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

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

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 years, 8 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_prefixed_buffer_reader.h ('k') | net/spdy/spdy_prefixed_buffer_reader_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/spdy/spdy_prefixed_buffer_reader.h"
6
7 #include "base/logging.h"
8
9 namespace net {
10
11 SpdyPrefixedBufferReader::SpdyPrefixedBufferReader(
12 const char* prefix,
13 size_t prefix_length,
14 const char* suffix,
15 size_t suffix_length)
16 : prefix_(prefix),
17 suffix_(suffix),
18 prefix_length_(prefix_length),
19 suffix_length_(suffix_length) {}
20
21 size_t SpdyPrefixedBufferReader::Available() {
22 return prefix_length_ + suffix_length_;
23 }
24
25 bool SpdyPrefixedBufferReader::ReadN(size_t count, char* out) {
26 if (Available() < count) {
27 return false;
28 }
29
30 if (prefix_length_ >= count) {
31 // Read is fully satisfied by the prefix.
32 std::copy(prefix_, prefix_ + count, out);
33 prefix_ += count;
34 prefix_length_ -= count;
35 return true;
36 } else if (prefix_length_ != 0) {
37 // Read is partially satisfied by the prefix.
38 out = std::copy(prefix_, prefix_ + prefix_length_, out);
39 count -= prefix_length_;
40 prefix_length_ = 0;
41 // Fallthrough to suffix read.
42 }
43 DCHECK(suffix_length_ >= count);
44 // Read is satisfied by the suffix.
45 std::copy(suffix_, suffix_ + count, out);
46 suffix_ += count;
47 suffix_length_ -= count;
48 return true;
49 }
50
51 bool SpdyPrefixedBufferReader::ReadN(size_t count,
52 SpdyPinnableBufferPiece* out) {
53 if (Available() < count) {
54 return false;
55 }
56
57 out->storage_.reset();
58 out->length_ = count;
59
60 if (prefix_length_ >= count) {
61 // Read is fully satisfied by the prefix.
62 out->buffer_ = prefix_;
63 prefix_ += count;
64 prefix_length_ -= count;
65 return true;
66 } else if (prefix_length_ != 0) {
67 // Read is only partially satisfied by the prefix. We need to allocate
68 // contiguous storage as the read spans the prefix & suffix.
69 out->storage_.reset(new char[count]);
70 out->buffer_ = out->storage_.get();
71 ReadN(count, out->storage_.get());
72 return true;
73 } else {
74 DCHECK(suffix_length_ >= count);
75 // Read is fully satisfied by the suffix.
76 out->buffer_ = suffix_;
77 suffix_ += count;
78 suffix_length_ -= count;
79 return true;
80 }
81 }
82
83 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_prefixed_buffer_reader.h ('k') | net/spdy/spdy_prefixed_buffer_reader_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698