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

Side by Side Diff: net/base/io_buffer.h

Issue 6800009: Attn: Mike Belshe Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef NET_BASE_IO_BUFFER_H_ 5 #ifndef NET_BASE_IO_BUFFER_H_
6 #define NET_BASE_IO_BUFFER_H_ 6 #define NET_BASE_IO_BUFFER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/pickle.h" 13 #include "base/pickle.h"
14 14
15 namespace net { 15 namespace net {
16 16
17 // This is a simple wrapper around a buffer that provides ref counting for 17 // This is a simple wrapper around a buffer that provides ref counting for
18 // easier asynchronous IO handling. 18 // easier asynchronous IO handling.
19 class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { 19 class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> {
20 public: 20 public:
21 IOBuffer(); 21 IOBuffer();
22 explicit IOBuffer(int buffer_size); 22 explicit IOBuffer(int buffer_size);
23 23
24 char* data() { return data_; } 24 char* data() { return data_; }
25 25
26 virtual uint16 sctp_stream_id() { return sctp_stream_id_; }
27 virtual void set_sctp_stream_id(int sctp_stream_id) {
28 sctp_stream_id_ = sctp_stream_id;
Mike Belshe 2011/04/06 18:32:53 lets try to make a derived IOBuffer work instead.
29 }
30
26 protected: 31 protected:
27 friend class base::RefCountedThreadSafe<IOBuffer>; 32 friend class base::RefCountedThreadSafe<IOBuffer>;
28 33
29 // Only allow derived classes to specify data_. 34 // Only allow derived classes to specify data_.
30 // In all other cases, we own data_, and must delete it at destruction time. 35 // In all other cases, we own data_, and must delete it at destruction time.
31 explicit IOBuffer(char* data); 36 explicit IOBuffer(char* data);
32 37
33 virtual ~IOBuffer(); 38 virtual ~IOBuffer();
34 39
35 char* data_; 40 char* data_;
41 uint16 sctp_stream_id_;
36 }; 42 };
37 43
38 // This version stores the size of the buffer so that the creator of the object 44 // This version stores the size of the buffer so that the creator of the object
39 // doesn't have to keep track of that value. 45 // doesn't have to keep track of that value.
40 // NOTE: This doesn't mean that we want to stop sending the size as an explicit 46 // NOTE: This doesn't mean that we want to stop sending the size as an explicit
41 // argument to IO functions. Please keep using IOBuffer* for API declarations. 47 // argument to IO functions. Please keep using IOBuffer* for API declarations.
42 class IOBufferWithSize : public IOBuffer { 48 class IOBufferWithSize : public IOBuffer {
43 public: 49 public:
44 explicit IOBufferWithSize(int size); 50 explicit IOBufferWithSize(int size);
45 51
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 86
81 // Returns the number of consumed bytes. 87 // Returns the number of consumed bytes.
82 int BytesConsumed() const; 88 int BytesConsumed() const;
83 89
84 // Seeks to an arbitrary point in the buffer. The notion of bytes consumed 90 // Seeks to an arbitrary point in the buffer. The notion of bytes consumed
85 // and remaining are updated appropriately. 91 // and remaining are updated appropriately.
86 void SetOffset(int bytes); 92 void SetOffset(int bytes);
87 93
88 int size() const { return size_; } 94 int size() const { return size_; }
89 95
96 void set_sctp_stream_id(uint32 stream_id) {
97 base_->set_sctp_stream_id(stream_id);
98 }
99 uint16 sctp_stream_id() {
100 return base_->sctp_stream_id();
101 }
102
90 private: 103 private:
91 virtual ~DrainableIOBuffer(); 104 virtual ~DrainableIOBuffer();
92 105
93 scoped_refptr<IOBuffer> base_; 106 scoped_refptr<IOBuffer> base_;
94 int size_; 107 int size_;
95 int used_; 108 int used_;
96 }; 109 };
97 110
98 // This version provides a resizable buffer and a changeable offset. 111 // This version provides a resizable buffer and a changeable offset.
99 class GrowableIOBuffer : public IOBuffer { 112 class GrowableIOBuffer : public IOBuffer {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 public: 159 public:
147 explicit WrappedIOBuffer(const char* data); 160 explicit WrappedIOBuffer(const char* data);
148 161
149 protected: 162 protected:
150 virtual ~WrappedIOBuffer(); 163 virtual ~WrappedIOBuffer();
151 }; 164 };
152 165
153 } // namespace net 166 } // namespace net
154 167
155 #endif // NET_BASE_IO_BUFFER_H_ 168 #endif // NET_BASE_IO_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698