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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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) 2012 The Chromium Authors. All rights reserved. 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 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 #include "net/socket/buffered_write_stream_socket.h" 5 #include "net/socket/buffered_write_stream_socket.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 18 matching lines...) Expand all
29 backup_buffer_(new GrowableIOBuffer()), 29 backup_buffer_(new GrowableIOBuffer()),
30 callback_pending_(false), 30 callback_pending_(false),
31 wrapped_write_in_progress_(false), 31 wrapped_write_in_progress_(false),
32 error_(0), 32 error_(0),
33 weak_factory_(this) { 33 weak_factory_(this) {
34 } 34 }
35 35
36 BufferedWriteStreamSocket::~BufferedWriteStreamSocket() { 36 BufferedWriteStreamSocket::~BufferedWriteStreamSocket() {
37 } 37 }
38 38
39 int BufferedWriteStreamSocket::Read(IOBuffer* buf, int buf_len, 39 int BufferedWriteStreamSocket::Read(IOBuffer* buf,
40 int buf_len,
40 const CompletionCallback& callback) { 41 const CompletionCallback& callback) {
41 return wrapped_socket_->Read(buf, buf_len, callback); 42 return wrapped_socket_->Read(buf, buf_len, callback);
42 } 43 }
43 44
44 int BufferedWriteStreamSocket::Write(IOBuffer* buf, int buf_len, 45 int BufferedWriteStreamSocket::Write(IOBuffer* buf,
46 int buf_len,
45 const CompletionCallback& callback) { 47 const CompletionCallback& callback) {
46 if (error_) { 48 if (error_) {
47 return error_; 49 return error_;
48 } 50 }
49 GrowableIOBuffer* idle_buffer = 51 GrowableIOBuffer* idle_buffer =
50 wrapped_write_in_progress_ ? backup_buffer_.get() : io_buffer_.get(); 52 wrapped_write_in_progress_ ? backup_buffer_.get() : io_buffer_.get();
51 AppendBuffer(idle_buffer, buf, buf_len); 53 AppendBuffer(idle_buffer, buf, buf_len);
52 if (!callback_pending_) { 54 if (!callback_pending_) {
53 base::MessageLoop::current()->PostTask( 55 base::MessageLoop::current()->PostTask(
54 FROM_HERE, 56 FROM_HERE,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 wrapped_write_in_progress_ = true; 136 wrapped_write_in_progress_ = true;
135 } else { 137 } else {
136 OnIOComplete(result); 138 OnIOComplete(result);
137 } 139 }
138 } 140 }
139 141
140 void BufferedWriteStreamSocket::OnIOComplete(int result) { 142 void BufferedWriteStreamSocket::OnIOComplete(int result) {
141 callback_pending_ = false; 143 callback_pending_ = false;
142 wrapped_write_in_progress_ = false; 144 wrapped_write_in_progress_ = false;
143 if (backup_buffer_->RemainingCapacity()) { 145 if (backup_buffer_->RemainingCapacity()) {
144 AppendBuffer(io_buffer_.get(), backup_buffer_.get(), 146 AppendBuffer(io_buffer_.get(),
147 backup_buffer_.get(),
145 backup_buffer_->RemainingCapacity()); 148 backup_buffer_->RemainingCapacity());
146 backup_buffer_->SetCapacity(0); 149 backup_buffer_->SetCapacity(0);
147 } 150 }
148 if (result < 0) { 151 if (result < 0) {
149 error_ = result; 152 error_ = result;
150 io_buffer_->SetCapacity(0); 153 io_buffer_->SetCapacity(0);
151 } else { 154 } else {
152 io_buffer_->set_offset(io_buffer_->offset() + result); 155 io_buffer_->set_offset(io_buffer_->offset() + result);
153 if (io_buffer_->RemainingCapacity()) { 156 if (io_buffer_->RemainingCapacity()) {
154 DoDelayedWrite(); 157 DoDelayedWrite();
155 } else { 158 } else {
156 io_buffer_->SetCapacity(0); 159 io_buffer_->SetCapacity(0);
157 } 160 }
158 } 161 }
159 } 162 }
160 163
161 } // namespace net 164 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698