| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/macros.h" |
| 18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 21 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
| 24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 25 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 26 #include "base/thread_task_runner_handle.h" | 27 #include "base/thread_task_runner_handle.h" |
| 27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 158 } |
| 158 | 159 |
| 159 bool IsCompleteResponse(const std::string& response) { | 160 bool IsCompleteResponse(const std::string& response) { |
| 160 // Check end of headers first. | 161 // Check end of headers first. |
| 161 int end_of_headers = HttpUtil::LocateEndOfHeaders(response.data(), | 162 int end_of_headers = HttpUtil::LocateEndOfHeaders(response.data(), |
| 162 response.size()); | 163 response.size()); |
| 163 if (end_of_headers < 0) | 164 if (end_of_headers < 0) |
| 164 return false; | 165 return false; |
| 165 | 166 |
| 166 // Return true if response has data equal to or more than content length. | 167 // Return true if response has data equal to or more than content length. |
| 167 int64 body_size = static_cast<int64>(response.size()) - end_of_headers; | 168 int64_t body_size = static_cast<int64_t>(response.size()) - end_of_headers; |
| 168 DCHECK_LE(0, body_size); | 169 DCHECK_LE(0, body_size); |
| 169 scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders( | 170 scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders( |
| 170 HttpUtil::AssembleRawHeaders(response.data(), end_of_headers))); | 171 HttpUtil::AssembleRawHeaders(response.data(), end_of_headers))); |
| 171 return body_size >= headers->GetContentLength(); | 172 return body_size >= headers->GetContentLength(); |
| 172 } | 173 } |
| 173 | 174 |
| 174 scoped_refptr<IOBufferWithSize> read_buffer_; | 175 scoped_refptr<IOBufferWithSize> read_buffer_; |
| 175 scoped_refptr<DrainableIOBuffer> write_buffer_; | 176 scoped_refptr<DrainableIOBuffer> write_buffer_; |
| 176 scoped_ptr<TCPClientSocket> socket_; | 177 scoped_ptr<TCPClientSocket> socket_; |
| 177 int connect_result_; | 178 int connect_result_; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 buf_len); | 530 buf_len); |
| 530 memcpy(buf->data(), pending_read_data_.data(), read_len); | 531 memcpy(buf->data(), pending_read_data_.data(), read_len); |
| 531 pending_read_data_.erase(0, read_len); | 532 pending_read_data_.erase(0, read_len); |
| 532 return read_len; | 533 return read_len; |
| 533 } | 534 } |
| 534 int Write(IOBuffer* buf, | 535 int Write(IOBuffer* buf, |
| 535 int buf_len, | 536 int buf_len, |
| 536 const CompletionCallback& callback) override { | 537 const CompletionCallback& callback) override { |
| 537 return ERR_NOT_IMPLEMENTED; | 538 return ERR_NOT_IMPLEMENTED; |
| 538 } | 539 } |
| 539 int SetReceiveBufferSize(int32 size) override { return ERR_NOT_IMPLEMENTED; } | 540 int SetReceiveBufferSize(int32_t size) override { |
| 540 int SetSendBufferSize(int32 size) override { return ERR_NOT_IMPLEMENTED; } | 541 return ERR_NOT_IMPLEMENTED; |
| 542 } |
| 543 int SetSendBufferSize(int32_t size) override { return ERR_NOT_IMPLEMENTED; } |
| 541 | 544 |
| 542 void DidRead(const char* data, int data_len) { | 545 void DidRead(const char* data, int data_len) { |
| 543 if (!read_buf_.get()) { | 546 if (!read_buf_.get()) { |
| 544 pending_read_data_.append(data, data_len); | 547 pending_read_data_.append(data, data_len); |
| 545 return; | 548 return; |
| 546 } | 549 } |
| 547 int read_len = std::min(data_len, read_buf_len_); | 550 int read_len = std::min(data_len, read_buf_len_); |
| 548 memcpy(read_buf_->data(), data, read_len); | 551 memcpy(read_buf_->data(), data, read_len); |
| 549 pending_read_data_.assign(data + read_len, data_len - read_len); | 552 pending_read_data_.assign(data + read_len, data_len - read_len); |
| 550 read_buf_ = NULL; | 553 read_buf_ = NULL; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 649 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); |
| 647 client.Send("GET / HTTP/1.1\r\n\r\n"); | 650 client.Send("GET / HTTP/1.1\r\n\r\n"); |
| 648 ASSERT_FALSE(RunUntilRequestsReceived(1)); | 651 ASSERT_FALSE(RunUntilRequestsReceived(1)); |
| 649 ASSERT_EQ(1ul, connection_ids_.size()); | 652 ASSERT_EQ(1ul, connection_ids_.size()); |
| 650 ASSERT_EQ(0ul, requests_.size()); | 653 ASSERT_EQ(0ul, requests_.size()); |
| 651 } | 654 } |
| 652 | 655 |
| 653 } // namespace | 656 } // namespace |
| 654 | 657 |
| 655 } // namespace net | 658 } // namespace net |
| OLD | NEW |