OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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 #ifndef NET_SPDY_SPDY_BUFFER_H_ | |
6 #define NET_SPDY_SPDY_BUFFER_H_ | |
7 | |
8 #include <cstddef> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "net/base/net_export.h" | |
13 | |
14 namespace net { | |
15 | |
16 class IOBuffer; | |
17 class SpdyFrame; | |
18 | |
19 // SpdyBuffer is a class to hold data read from or to be written to a | |
20 // SPDY connection. It is similar to a DrainableIOBuffer but is not | |
21 // ref-counted and will include a way to get notified when Consume() | |
22 // is called. | |
23 // | |
24 // NOTE(akalin): This explicitly does not inherit from IOBuffer to | |
25 // avoid the needless ref-counting and to avoid working around the | |
26 // fact that IOBuffer member functions are not virtual. | |
27 class NET_EXPORT_PRIVATE SpdyBuffer { | |
28 public: | |
29 // Construct with the data in the given frame. Assumes that data is | |
30 // owned by |frame| or outlives it. | |
31 explicit SpdyBuffer(scoped_ptr<SpdyFrame> frame); | |
32 | |
33 // Construct with a copy of the given raw data. |data| must be | |
34 // non-NULL and |size| must be non-zero. | |
35 SpdyBuffer(const char* data, size_t size); | |
36 | |
37 ~SpdyBuffer(); | |
38 | |
39 // Returns the remaining (unconsumed) data. | |
40 const char* GetRemainingData() const; | |
41 | |
42 // Returns the number of remaining (unconsumed) bytes. | |
43 size_t GetRemainingSize() const; | |
44 | |
45 // Consume the given number of bytes, which must be positive but not | |
46 // greater than GetRemainingSize(). | |
47 // | |
48 // TODO(akalin): Add a way to get notified when Consume() is called. | |
49 void Consume(size_t consume_size); | |
50 | |
51 // Returns an IOBuffer pointing to the data starting at | |
52 // GetRemainingData(). Use with care; the returned IOBuffer must not | |
53 // be used past the lifetime of this object, and it is not updated | |
54 // when Consume() is called. | |
55 IOBuffer* GetIOBufferForRemainingData(); | |
56 | |
57 private: | |
58 const scoped_ptr<SpdyFrame> frame_; | |
59 size_t offset_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(SpdyBuffer); | |
62 }; | |
63 | |
64 } // namespace net | |
65 | |
66 #endif // NET_SPDY_SPDY_BUFFER_H_ | |
OLD | NEW |