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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 if ((transfer_size_ >= 0) && (bytes_downloaded_ < transfer_size_)) { | 105 if ((transfer_size_ >= 0) && (bytes_downloaded_ < transfer_size_)) { |
106 // Need to restart transfer | 106 // Need to restart transfer |
107 retry_count_++; | 107 retry_count_++; |
108 LOG(INFO) << "Restarting transfer b/c we finished, had downloaded " | 108 LOG(INFO) << "Restarting transfer b/c we finished, had downloaded " |
109 << bytes_downloaded_ << " bytes, but transfer_size_ is " | 109 << bytes_downloaded_ << " bytes, but transfer_size_ is " |
110 << transfer_size_ << ". retry_count: " << retry_count_; | 110 << transfer_size_ << ". retry_count: " << retry_count_; |
111 if (retry_count_ > kMaxRetriesCount) { | 111 if (retry_count_ > kMaxRetriesCount) { |
112 if (delegate_) | 112 if (delegate_) |
113 delegate_->TransferComplete(this, false); // success | 113 delegate_->TransferComplete(this, false); // success |
114 } else { | 114 } else { |
115 g_timeout_add(5 * 1000, | 115 g_timeout_add_seconds(5, |
116 &LibcurlHttpFetcher::StaticRetryTimeoutCallback, | 116 &LibcurlHttpFetcher::StaticRetryTimeoutCallback, |
117 this); | 117 this); |
118 } | 118 } |
119 return; | 119 return; |
120 } else { | 120 } else { |
121 if (delegate_) { | 121 if (delegate_) { |
122 // success is when http_response_code is 2xx | 122 // success is when http_response_code is 2xx |
123 bool success = (http_response_code >= 200) && | 123 bool success = (http_response_code >= 200) && |
124 (http_response_code < 300); | 124 (http_response_code < 300); |
125 delegate_->TransferComplete(this, success); | 125 delegate_->TransferComplete(this, success); |
126 } | 126 } |
127 } | 127 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 if (ms < 0) { | 222 if (ms < 0) { |
223 // From http://curl.haxx.se/libcurl/c/curl_multi_timeout.html: | 223 // From http://curl.haxx.se/libcurl/c/curl_multi_timeout.html: |
224 // if libcurl returns a -1 timeout here, it just means that libcurl | 224 // if libcurl returns a -1 timeout here, it just means that libcurl |
225 // currently has no stored timeout value. You must not wait too long | 225 // currently has no stored timeout value. You must not wait too long |
226 // (more than a few seconds perhaps) before you call | 226 // (more than a few seconds perhaps) before you call |
227 // curl_multi_perform() again. | 227 // curl_multi_perform() again. |
228 ms = idle_ms_; | 228 ms = idle_ms_; |
229 } | 229 } |
230 if (!timeout_source_) { | 230 if (!timeout_source_) { |
231 LOG(INFO) << "setting up timeout source:" << ms; | 231 LOG(INFO) << "setting up timeout source:" << ms; |
232 timeout_source_ = g_timeout_source_new(1000); | 232 timeout_source_ = g_timeout_source_new_seconds(1); |
233 CHECK(timeout_source_); | 233 CHECK(timeout_source_); |
234 g_source_set_callback(timeout_source_, StaticTimeoutCallback, this, | 234 g_source_set_callback(timeout_source_, StaticTimeoutCallback, this, |
235 NULL); | 235 NULL); |
236 g_source_attach(timeout_source_, NULL); | 236 g_source_attach(timeout_source_, NULL); |
237 static int counter = 0; | 237 static int counter = 0; |
238 counter++; | 238 counter++; |
239 if (counter % 50 == 0) { | 239 if (counter % 50 == 0) { |
240 LOG(INFO) << "counter = " << counter; | 240 LOG(INFO) << "counter = " << counter; |
241 } | 241 } |
242 } | 242 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 curl_handle_ = NULL; | 290 curl_handle_ = NULL; |
291 } | 291 } |
292 if (curl_multi_handle_) { | 292 if (curl_multi_handle_) { |
293 CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK); | 293 CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK); |
294 curl_multi_handle_ = NULL; | 294 curl_multi_handle_ = NULL; |
295 } | 295 } |
296 transfer_in_progress_ = false; | 296 transfer_in_progress_ = false; |
297 } | 297 } |
298 | 298 |
299 } // namespace chromeos_update_engine | 299 } // namespace chromeos_update_engine |
OLD | NEW |