OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 "update_engine/libcurl_http_fetcher.h" | 5 #include "update_engine/libcurl_http_fetcher.h" |
6 #include <algorithm> | 6 #include <algorithm> |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 using std::max; | 9 using std::max; |
10 using std::make_pair; | 10 using std::make_pair; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 CHECK_EQ(curl_multi_add_handle(curl_multi_handle_, curl_handle_), CURLM_OK); | 71 CHECK_EQ(curl_multi_add_handle(curl_multi_handle_, curl_handle_), CURLM_OK); |
72 transfer_in_progress_ = true; | 72 transfer_in_progress_ = true; |
73 } | 73 } |
74 | 74 |
75 // Begins the transfer, which must not have already been started. | 75 // Begins the transfer, which must not have already been started. |
76 void LibcurlHttpFetcher::BeginTransfer(const std::string& url) { | 76 void LibcurlHttpFetcher::BeginTransfer(const std::string& url) { |
77 transfer_size_ = -1; | 77 transfer_size_ = -1; |
78 bytes_downloaded_ = 0; | 78 bytes_downloaded_ = 0; |
79 resume_offset_ = 0; | 79 resume_offset_ = 0; |
80 retry_count_ = 0; | 80 retry_count_ = 0; |
| 81 http_response_code_ = 0; |
81 ResumeTransfer(url); | 82 ResumeTransfer(url); |
82 CurlPerformOnce(); | 83 CurlPerformOnce(); |
83 } | 84 } |
84 | 85 |
85 void LibcurlHttpFetcher::TerminateTransfer() { | 86 void LibcurlHttpFetcher::TerminateTransfer() { |
86 CleanUp(); | 87 CleanUp(); |
87 } | 88 } |
88 | 89 |
89 void LibcurlHttpFetcher::CurlPerformOnce() { | 90 void LibcurlHttpFetcher::CurlPerformOnce() { |
90 CHECK(transfer_in_progress_); | 91 CHECK(transfer_in_progress_); |
91 int running_handles = 0; | 92 int running_handles = 0; |
92 CURLMcode retcode = CURLM_CALL_MULTI_PERFORM; | 93 CURLMcode retcode = CURLM_CALL_MULTI_PERFORM; |
93 | 94 |
94 // libcurl may request that we immediately call curl_multi_perform after it | 95 // libcurl may request that we immediately call curl_multi_perform after it |
95 // returns, so we do. libcurl promises that curl_multi_perform will not block. | 96 // returns, so we do. libcurl promises that curl_multi_perform will not block. |
96 while (CURLM_CALL_MULTI_PERFORM == retcode) { | 97 while (CURLM_CALL_MULTI_PERFORM == retcode) { |
97 retcode = curl_multi_perform(curl_multi_handle_, &running_handles); | 98 retcode = curl_multi_perform(curl_multi_handle_, &running_handles); |
98 } | 99 } |
99 if (0 == running_handles) { | 100 if (0 == running_handles) { |
100 long http_response_code = 0; | 101 long http_response_code = 0; |
101 if (curl_easy_getinfo(curl_handle_, | 102 if (curl_easy_getinfo(curl_handle_, |
102 CURLINFO_RESPONSE_CODE, | 103 CURLINFO_RESPONSE_CODE, |
103 &http_response_code) == CURLE_OK) { | 104 &http_response_code) == CURLE_OK) { |
104 LOG(INFO) << "HTTP response code: " << http_response_code; | 105 LOG(INFO) << "HTTP response code: " << http_response_code; |
105 } else { | 106 } else { |
106 LOG(ERROR) << "Unable to get http response code."; | 107 LOG(ERROR) << "Unable to get http response code."; |
107 } | 108 } |
| 109 http_response_code_ = static_cast<int>(http_response_code); |
108 | 110 |
109 // we're done! | 111 // we're done! |
110 CleanUp(); | 112 CleanUp(); |
111 | 113 |
112 if ((transfer_size_ >= 0) && (bytes_downloaded_ < transfer_size_)) { | 114 if ((transfer_size_ >= 0) && (bytes_downloaded_ < transfer_size_)) { |
113 // Need to restart transfer | 115 // Need to restart transfer |
114 retry_count_++; | 116 retry_count_++; |
115 LOG(INFO) << "Restarting transfer b/c we finished, had downloaded " | 117 LOG(INFO) << "Restarting transfer b/c we finished, had downloaded " |
116 << bytes_downloaded_ << " bytes, but transfer_size_ is " | 118 << bytes_downloaded_ << " bytes, but transfer_size_ is " |
117 << transfer_size_ << ". retry_count: " << retry_count_; | 119 << transfer_size_ << ". retry_count: " << retry_count_; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 curl_handle_ = NULL; | 282 curl_handle_ = NULL; |
281 } | 283 } |
282 if (curl_multi_handle_) { | 284 if (curl_multi_handle_) { |
283 CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK); | 285 CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK); |
284 curl_multi_handle_ = NULL; | 286 curl_multi_handle_ = NULL; |
285 } | 287 } |
286 transfer_in_progress_ = false; | 288 transfer_in_progress_ = false; |
287 } | 289 } |
288 | 290 |
289 } // namespace chromeos_update_engine | 291 } // namespace chromeos_update_engine |
OLD | NEW |