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

Side by Side Diff: net/socket/buffered_write_stream_socket.cc

Issue 9433015: Add a force pipelining option to load flags. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix build on other platforms Created 8 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/socket/buffered_write_stream_socket.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop.h"
10 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h"
12
13 namespace net {
14
15 BufferedWriteStreamSocket::BufferedWriteStreamSocket(
16 StreamSocket* socket_to_wrap)
17 : wrapped_socket_(socket_to_wrap),
18 io_buffer_(new GrowableIOBuffer()),
19 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
20 pending_callback_(false),
21 error_(0) {
22 }
23
24 BufferedWriteStreamSocket::~BufferedWriteStreamSocket() {
25 }
26
27 int BufferedWriteStreamSocket::Read(IOBuffer* buf, int buf_len,
28 const CompletionCallback& callback) {
29 return wrapped_socket_->Read(buf, buf_len, callback);
30 }
31
32 int BufferedWriteStreamSocket::Write(IOBuffer* buf, int buf_len,
33 const CompletionCallback& callback) {
34 if (error_) {
35 return error_;
36 }
37 int old_capacity = io_buffer_->capacity();
38 io_buffer_->SetCapacity(old_capacity + buf_len);
39 memcpy(io_buffer_->data() + old_capacity, buf->data(), buf_len);
40 if (!pending_callback_) {
41 MessageLoop::current()->PostTask(
42 FROM_HERE,
43 base::Bind(&BufferedWriteStreamSocket::DoDelayedWrite,
44 weak_factory_.GetWeakPtr()));
45 pending_callback_ = true;
46 }
47 return buf_len;
48 }
49
50 bool BufferedWriteStreamSocket::SetReceiveBufferSize(int32 size) {
51 return wrapped_socket_->SetReceiveBufferSize(size);
52 }
53
54 bool BufferedWriteStreamSocket::SetSendBufferSize(int32 size) {
55 return wrapped_socket_->SetSendBufferSize(size);
56 }
57
58 int BufferedWriteStreamSocket::Connect(const CompletionCallback& callback) {
59 return wrapped_socket_->Connect(callback);
60 }
61
62 void BufferedWriteStreamSocket::Disconnect() {
63 wrapped_socket_->Disconnect();
64 }
65
66 bool BufferedWriteStreamSocket::IsConnected() const {
67 return wrapped_socket_->IsConnected();
68 }
69
70 bool BufferedWriteStreamSocket::IsConnectedAndIdle() const {
71 return wrapped_socket_->IsConnectedAndIdle();
72 }
73
74 int BufferedWriteStreamSocket::GetPeerAddress(AddressList* address) const {
75 return wrapped_socket_->GetPeerAddress(address);
76 }
77
78 int BufferedWriteStreamSocket::GetLocalAddress(IPEndPoint* address) const {
79 return wrapped_socket_->GetLocalAddress(address);
80 }
81
82 const BoundNetLog& BufferedWriteStreamSocket::NetLog() const {
83 return wrapped_socket_->NetLog();
84 }
85
86 void BufferedWriteStreamSocket::SetSubresourceSpeculation() {
87 wrapped_socket_->SetSubresourceSpeculation();
88 }
89
90 void BufferedWriteStreamSocket::SetOmniboxSpeculation() {
91 wrapped_socket_->SetOmniboxSpeculation();
92 }
93
94 bool BufferedWriteStreamSocket::WasEverUsed() const {
95 return wrapped_socket_->WasEverUsed();
96 }
97
98 bool BufferedWriteStreamSocket::UsingTCPFastOpen() const {
99 return wrapped_socket_->UsingTCPFastOpen();
100 }
101
102 int64 BufferedWriteStreamSocket::NumBytesRead() const {
103 return wrapped_socket_->NumBytesRead();
104 }
105
106 base::TimeDelta BufferedWriteStreamSocket::GetConnectTimeMicros() const {
107 return wrapped_socket_->GetConnectTimeMicros();
108 }
109
110 void BufferedWriteStreamSocket::DoDelayedWrite() {
111 int result = wrapped_socket_->Write(
112 io_buffer_, io_buffer_->RemainingCapacity(),
113 base::Bind(&BufferedWriteStreamSocket::OnIOComplete,
114 base::Unretained(this)));
115 if (result == ERR_IO_PENDING) {
116 pending_callback_ = true;
117 } else {
118 OnIOComplete(result);
119 }
120 }
121
122 void BufferedWriteStreamSocket::OnIOComplete(int result) {
123 pending_callback_ = false;
124 if (result < 0) {
125 error_ = result;
126 io_buffer_->SetCapacity(0);
127 } else {
128 io_buffer_->set_offset(io_buffer_->offset() + result);
129 if (io_buffer_->RemainingCapacity()) {
130 DoDelayedWrite();
131 } else {
132 io_buffer_->SetCapacity(0);
133 }
134 }
135 }
136
137 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698