summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 23:31:08 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 23:31:08 +0000
commit8c66f1b4a7164a2f7cb61bae3288cd3dc50c2b18 (patch)
tree9396e85fcbc44f3a443bca9623b9933ca885d969 /net
parent83df216dbfd197f90b087f74c0a268c1e0db988b (diff)
downloadchromium_src-8c66f1b4a7164a2f7cb61bae3288cd3dc50c2b18.zip
chromium_src-8c66f1b4a7164a2f7cb61bae3288cd3dc50c2b18.tar.gz
chromium_src-8c66f1b4a7164a2f7cb61bae3288cd3dc50c2b18.tar.bz2
Use IOBuffers on UploadDataStream.
This is some cleanup of cl 14998. R=wtc BUG=9258 TEST=none Review URL: http://codereview.chromium.org/115157 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/upload_data_stream.cc8
-rw-r--r--net/base/upload_data_stream.h5
-rw-r--r--net/http/http_network_transaction.cc10
-rw-r--r--net/http/http_network_transaction.h1
4 files changed, 10 insertions, 14 deletions
diff --git a/net/base/upload_data_stream.cc b/net/base/upload_data_stream.cc
index 0a41a13..468ef6b 100644
--- a/net/base/upload_data_stream.cc
+++ b/net/base/upload_data_stream.cc
@@ -11,6 +11,7 @@ namespace net {
UploadDataStream::UploadDataStream(const UploadData* data)
: data_(data),
+ buf_(new IOBuffer(kBufSize)),
buf_len_(0),
next_element_(data->elements().begin()),
next_element_offset_(0),
@@ -28,7 +29,7 @@ void UploadDataStream::DidConsume(size_t num_bytes) {
buf_len_ -= num_bytes;
if (buf_len_)
- memmove(buf_, buf_ + num_bytes, buf_len_);
+ memmove(buf_->data(), buf_->data() + num_bytes, buf_len_);
FillBuf();
@@ -51,7 +52,7 @@ void UploadDataStream::FillBuf() {
size_t bytes_copied = std::min(count, size_remaining);
- memcpy(buf_ + buf_len_, &d[next_element_offset_], bytes_copied);
+ memcpy(buf_->data() + buf_len_, &d[next_element_offset_], bytes_copied);
buf_len_ += bytes_copied;
if (bytes_copied == count) {
@@ -88,7 +89,8 @@ void UploadDataStream::FillBuf() {
int count = static_cast<int>(std::min(
static_cast<uint64>(size_remaining), next_element_remaining_));
if (count > 0 &&
- (rv = next_element_stream_.Read(buf_ + buf_len_, count, NULL)) > 0) {
+ (rv = next_element_stream_.Read(buf_->data() + buf_len_,
+ count, NULL)) > 0) {
buf_len_ += rv;
next_element_remaining_ -= rv;
} else {
diff --git a/net/base/upload_data_stream.h b/net/base/upload_data_stream.h
index b39c550..e65d08b 100644
--- a/net/base/upload_data_stream.h
+++ b/net/base/upload_data_stream.h
@@ -6,6 +6,7 @@
#define NET_BASE_UPLOAD_DATA_STREAM_H_
#include "net/base/file_stream.h"
+#include "net/base/io_buffer.h"
#include "net/base/upload_data.h"
namespace net {
@@ -16,7 +17,7 @@ class UploadDataStream {
~UploadDataStream();
// Returns the stream's buffer and buffer length.
- const char* buf() const { return buf_; }
+ IOBuffer* buf() const { return buf_; }
size_t buf_len() const { return buf_len_; }
// Call to indicate that a portion of the stream's buffer was consumed. This
@@ -38,7 +39,7 @@ class UploadDataStream {
// once, then we memmove the remaining portion and back-fill the buffer for
// the next "write" call. buf_len_ indicates how much data is in the buffer.
enum { kBufSize = 16384 };
- char buf_[kBufSize];
+ scoped_refptr<IOBuffer> buf_;
size_t buf_len_;
// Iterator to the upload element to be written to the send buffer next.
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index e059d97..18c4d9f 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -746,19 +746,13 @@ int HttpNetworkTransaction::DoWriteBody() {
DCHECK(request_body_stream_.get());
DCHECK(request_body_stream_->size());
- const char* buf = request_body_stream_->buf();
int buf_len = static_cast<int>(request_body_stream_->buf_len());
- DCHECK(!write_buffer_);
- write_buffer_ = new IOBuffer(buf_len);
- memcpy(write_buffer_->data(), buf, buf_len);
- return connection_.socket()->Write(write_buffer_, buf_len, &io_callback_);
+ return connection_.socket()->Write(request_body_stream_->buf(), buf_len,
+ &io_callback_);
}
int HttpNetworkTransaction::DoWriteBodyComplete(int result) {
- DCHECK(write_buffer_);
- write_buffer_ = NULL;
-
if (result < 0)
return HandleIOError(result);
diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h
index 9ba9cc0..291091a 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -311,7 +311,6 @@ class HttpNetworkTransaction : public HttpTransaction {
scoped_refptr<RequestHeaders> request_headers_;
size_t request_headers_bytes_sent_;
scoped_ptr<UploadDataStream> request_body_stream_;
- scoped_refptr<IOBuffer> write_buffer_;
// The read buffer may be larger than it is full. The 'capacity' indicates
// the allocation size of the buffer, and the 'len' indicates how much data