| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 user_buffer_ = new DrainableIOBuffer(buf, buf_len); | 189 user_buffer_ = new DrainableIOBuffer(buf, buf_len); |
| 190 int result = PopulateUserReadBuffer(); | 190 int result = PopulateUserReadBuffer(); |
| 191 if (result == 0) { | 191 if (result == 0) { |
| 192 DCHECK(callback); | 192 DCHECK(callback); |
| 193 old_read_callback_ = callback; | 193 old_read_callback_ = callback; |
| 194 return ERR_IO_PENDING; | 194 return ERR_IO_PENDING; |
| 195 } | 195 } |
| 196 user_buffer_ = NULL; | 196 user_buffer_ = NULL; |
| 197 return result; | 197 return result; |
| 198 } | 198 } |
| 199 int SpdyProxyClientSocket::Read(IOBuffer* buf, int buf_len, |
| 200 const CompletionCallback& callback) { |
| 201 DCHECK(!old_read_callback_ && read_callback_.is_null()); |
| 202 DCHECK(!user_buffer_); |
| 203 |
| 204 if (next_state_ == STATE_DISCONNECTED) |
| 205 return ERR_SOCKET_NOT_CONNECTED; |
| 206 |
| 207 if (next_state_ == STATE_CLOSED && read_buffer_.empty()) { |
| 208 return 0; |
| 209 } |
| 210 |
| 211 DCHECK(next_state_ == STATE_OPEN || next_state_ == STATE_CLOSED); |
| 212 DCHECK(buf); |
| 213 user_buffer_ = new DrainableIOBuffer(buf, buf_len); |
| 214 int result = PopulateUserReadBuffer(); |
| 215 if (result == 0) { |
| 216 DCHECK(!callback.is_null()); |
| 217 read_callback_ = callback; |
| 218 return ERR_IO_PENDING; |
| 219 } |
| 220 user_buffer_ = NULL; |
| 221 return result; |
| 222 } |
| 199 | 223 |
| 200 int SpdyProxyClientSocket::PopulateUserReadBuffer() { | 224 int SpdyProxyClientSocket::PopulateUserReadBuffer() { |
| 201 if (!user_buffer_) | 225 if (!user_buffer_) |
| 202 return ERR_IO_PENDING; | 226 return ERR_IO_PENDING; |
| 203 | 227 |
| 204 while (!read_buffer_.empty() && user_buffer_->BytesRemaining() > 0) { | 228 while (!read_buffer_.empty() && user_buffer_->BytesRemaining() > 0) { |
| 205 scoped_refptr<DrainableIOBuffer> data = read_buffer_.front(); | 229 scoped_refptr<DrainableIOBuffer> data = read_buffer_.front(); |
| 206 const int bytes_to_copy = std::min(user_buffer_->BytesRemaining(), | 230 const int bytes_to_copy = std::min(user_buffer_->BytesRemaining(), |
| 207 data->BytesRemaining()); | 231 data->BytesRemaining()); |
| 208 memcpy(user_buffer_->data(), data->data(), bytes_to_copy); | 232 memcpy(user_buffer_->data(), data->data(), bytes_to_copy); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 } | 585 } |
| 562 // This may have been deleted by read_callback_, so check first. | 586 // This may have been deleted by read_callback_, so check first. |
| 563 if (weak_ptr && write_callback) | 587 if (weak_ptr && write_callback) |
| 564 write_callback->Run(ERR_CONNECTION_CLOSED); | 588 write_callback->Run(ERR_CONNECTION_CLOSED); |
| 565 } | 589 } |
| 566 | 590 |
| 567 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { | 591 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { |
| 568 } | 592 } |
| 569 | 593 |
| 570 } // namespace net | 594 } // namespace net |
| OLD | NEW |