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

Unified Diff: net/base/io_buffer.h

Issue 9293029: net: Introduce SeekableIOBuffer and clean up HttpStreamParser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comments Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/http/http_stream_parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/io_buffer.h
diff --git a/net/base/io_buffer.h b/net/base/io_buffer.h
index 3a04b6a969cfe3f5ee6da2aad1f15fff0514c4e1..41393091d6b9c7849530576b1086d21d77c72f27 100644
--- a/net/base/io_buffer.h
+++ b/net/base/io_buffer.h
@@ -126,6 +126,21 @@ class NET_EXPORT StringIOBuffer : public IOBuffer {
// This version wraps an existing IOBuffer and provides convenient functions
// to progressively read all the data.
+//
+// DrainableIOBuffer is useful when you have an IOBuffer that contains data
+// to be written progressively, and Write() function takes an IOBuffer rather
+// than char*. DrainableIOBuffer can be used as follows:
+//
+// // payload is the IOBuffer containing the data to be written.
+// buf = new DrainableIOBuffer(payload, payload_size);
+//
+// while (buf->BytesRemaining() > 0) {
+// // Write() takes an IOBuffer. If it takes char*, we could
+// // simply use the regular IOBuffer like payload->data() + offset.
+// int bytes_written = Write(buf, buf->BytesRemaining());
+// buf->DidConsume(bytes_written);
+// }
+//
class NET_EXPORT DrainableIOBuffer : public IOBuffer {
public:
DrainableIOBuffer(IOBuffer* base, int size);
@@ -155,6 +170,22 @@ class NET_EXPORT DrainableIOBuffer : public IOBuffer {
};
// This version provides a resizable buffer and a changeable offset.
+//
+// GrowableIOBuffer is useful when you read data progressively without
+// knowing the total size in advance. GrowableIOBuffer can be used as
+// follows:
+//
+// buf = new GrowableIOBuffer;
+// buf->SetCapacity(1024); // Initial capacity.
+//
+// while (!some_stream->IsEOF()) {
+// // Double the capacity if the remaining capacity is empty.
+// if (buf->RemainingCapacity() == 0)
+// buf->SetCapacity(buf->capacity() * 2);
+// int bytes_read = some_stream->Read(buf, buf->RemainingCapacity());
+// buf->set_offset(buf->offset() + bytes_read);
+// }
+//
class NET_EXPORT GrowableIOBuffer : public IOBuffer {
public:
GrowableIOBuffer();
« no previous file with comments | « no previous file | net/http/http_stream_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698