Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: libcurl_http_fetcher.cc

Issue 3187005: Increase retry timeout to 1 minute. (Closed) Base URL: http://src.chromium.org/git/update_engine.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libcurl_http_fetcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_seconds(5, 115 g_timeout_add_seconds(retry_seconds_,
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);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 &StaticFDCallback, 209 &StaticFDCallback,
210 this); 210 this);
211 io_channels_[i] = make_pair(io_channel, tag); 211 io_channels_[i] = make_pair(io_channel, tag);
212 static int io_counter = 0; 212 static int io_counter = 0;
213 io_counter++; 213 io_counter++;
214 if (io_counter % 50 == 0) { 214 if (io_counter % 50 == 0) {
215 LOG(INFO) << "io_counter = " << io_counter; 215 LOG(INFO) << "io_counter = " << io_counter;
216 } 216 }
217 } 217 }
218 218
219 // Wet up a timeout callback for libcurl 219 // Set up a timeout callback for libcurl.
220 long ms = 0;
221 CHECK_EQ(curl_multi_timeout(curl_multi_handle_, &ms), CURLM_OK);
222 if (ms < 0) {
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
225 // currently has no stored timeout value. You must not wait too long
226 // (more than a few seconds perhaps) before you call
227 // curl_multi_perform() again.
228 ms = idle_ms_;
229 }
230 if (!timeout_source_) { 220 if (!timeout_source_) {
231 LOG(INFO) << "setting up timeout source:" << ms; 221 LOG(INFO) << "Setting up timeout source: " << idle_seconds_ << " seconds.";
232 timeout_source_ = g_timeout_source_new_seconds(1); 222 timeout_source_ = g_timeout_source_new_seconds(idle_seconds_);
233 CHECK(timeout_source_); 223 g_source_set_callback(timeout_source_, StaticTimeoutCallback, this, NULL);
234 g_source_set_callback(timeout_source_, StaticTimeoutCallback, this,
235 NULL);
236 g_source_attach(timeout_source_, NULL); 224 g_source_attach(timeout_source_, NULL);
237 static int counter = 0;
238 counter++;
239 if (counter % 50 == 0) {
240 LOG(INFO) << "counter = " << counter;
241 }
242 } 225 }
243 } 226 }
244 227
245 bool LibcurlHttpFetcher::FDCallback(GIOChannel *source, 228 bool LibcurlHttpFetcher::FDCallback(GIOChannel *source,
246 GIOCondition condition) { 229 GIOCondition condition) {
247 CurlPerformOnce(); 230 CurlPerformOnce();
248 // We handle removing of this source elsewhere, so we always return true. 231 // We handle removing of this source elsewhere, so we always return true.
249 // The docs say, "the function should return FALSE if the event source 232 // The docs say, "the function should return FALSE if the event source
250 // should be removed." 233 // should be removed."
251 // http://www.gtk.org/api/2.6/glib/glib-IO-Channels.html#GIOFunc 234 // http://www.gtk.org/api/2.6/glib/glib-IO-Channels.html#GIOFunc
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 curl_handle_ = NULL; 273 curl_handle_ = NULL;
291 } 274 }
292 if (curl_multi_handle_) { 275 if (curl_multi_handle_) {
293 CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK); 276 CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK);
294 curl_multi_handle_ = NULL; 277 curl_multi_handle_ = NULL;
295 } 278 }
296 transfer_in_progress_ = false; 279 transfer_in_progress_ = false;
297 } 280 }
298 281
299 } // namespace chromeos_update_engine 282 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « libcurl_http_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698