| OLD | NEW |
| 1 // Copyright (c) 2011 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/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
| 6 | 6 |
| 7 #include <algorithm> // min | 7 #include <algorithm> // min |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return ERR_IO_PENDING; | 165 return ERR_IO_PENDING; |
| 166 } | 166 } |
| 167 user_buffer_ = NULL; | 167 user_buffer_ = NULL; |
| 168 return result; | 168 return result; |
| 169 } | 169 } |
| 170 | 170 |
| 171 int SpdyProxyClientSocket::PopulateUserReadBuffer() { | 171 int SpdyProxyClientSocket::PopulateUserReadBuffer() { |
| 172 if (!user_buffer_) | 172 if (!user_buffer_) |
| 173 return ERR_IO_PENDING; | 173 return ERR_IO_PENDING; |
| 174 | 174 |
| 175 int bytes_read = 0; |
| 175 while (!read_buffer_.empty() && user_buffer_->BytesRemaining() > 0) { | 176 while (!read_buffer_.empty() && user_buffer_->BytesRemaining() > 0) { |
| 176 scoped_refptr<DrainableIOBuffer> data = read_buffer_.front(); | 177 scoped_refptr<DrainableIOBuffer> data = read_buffer_.front(); |
| 177 const int bytes_to_copy = std::min(user_buffer_->BytesRemaining(), | 178 const int bytes_to_copy = std::min(user_buffer_->BytesRemaining(), |
| 178 data->BytesRemaining()); | 179 data->BytesRemaining()); |
| 179 memcpy(user_buffer_->data(), data->data(), bytes_to_copy); | 180 memcpy(user_buffer_->data(), data->data(), bytes_to_copy); |
| 180 user_buffer_->DidConsume(bytes_to_copy); | 181 user_buffer_->DidConsume(bytes_to_copy); |
| 182 bytes_read += bytes_to_copy; |
| 181 if (data->BytesRemaining() == bytes_to_copy) { | 183 if (data->BytesRemaining() == bytes_to_copy) { |
| 182 // Consumed all data from this buffer | 184 // Consumed all data from this buffer |
| 183 read_buffer_.pop_front(); | 185 read_buffer_.pop_front(); |
| 184 } else { | 186 } else { |
| 185 data->DidConsume(bytes_to_copy); | 187 data->DidConsume(bytes_to_copy); |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 | 190 |
| 191 if (bytes_read > 0 && spdy_stream_) |
| 192 spdy_stream_->IncreaseRecvWindowSize(bytes_read); |
| 193 |
| 189 return user_buffer_->BytesConsumed(); | 194 return user_buffer_->BytesConsumed(); |
| 190 } | 195 } |
| 191 | 196 |
| 192 int SpdyProxyClientSocket::Write(IOBuffer* buf, int buf_len, | 197 int SpdyProxyClientSocket::Write(IOBuffer* buf, int buf_len, |
| 193 const CompletionCallback& callback) { | 198 const CompletionCallback& callback) { |
| 194 DCHECK(write_callback_.is_null()); | 199 DCHECK(write_callback_.is_null()); |
| 195 if (next_state_ != STATE_OPEN) | 200 if (next_state_ != STATE_OPEN) |
| 196 return ERR_SOCKET_NOT_CONNECTED; | 201 return ERR_SOCKET_NOT_CONNECTED; |
| 197 | 202 |
| 198 DCHECK(spdy_stream_); | 203 DCHECK(spdy_stream_); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 } | 512 } |
| 508 // This may have been deleted by read_callback_, so check first. | 513 // This may have been deleted by read_callback_, so check first. |
| 509 if (weak_ptr && !write_callback.is_null()) | 514 if (weak_ptr && !write_callback.is_null()) |
| 510 write_callback.Run(ERR_CONNECTION_CLOSED); | 515 write_callback.Run(ERR_CONNECTION_CLOSED); |
| 511 } | 516 } |
| 512 | 517 |
| 513 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { | 518 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { |
| 514 } | 519 } |
| 515 | 520 |
| 516 } // namespace net | 521 } // namespace net |
| OLD | NEW |