rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 5 | #include "update_engine/libcurl_http_fetcher.h" |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 6 | #include <algorithm> |
Chris Masone | 790e62e | 2010-08-12 10:41:18 -0700 | [diff] [blame] | 7 | #include "base/logging.h" |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 8 | |
| 9 | using std::max; |
| 10 | using std::make_pair; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 11 | |
| 12 | // This is a concrete implementation of HttpFetcher that uses libcurl to do the |
| 13 | // http work. |
| 14 | |
| 15 | namespace chromeos_update_engine { |
| 16 | |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 17 | namespace { |
| 18 | const int kMaxRetriesCount = 20; |
Darin Petkov | 3a4016a | 2010-09-28 13:54:17 -0700 | [diff] [blame] | 19 | const char kCACertificatesPath[] = "/usr/share/update_engine/ca-certificates"; |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 20 | } |
| 21 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 22 | LibcurlHttpFetcher::~LibcurlHttpFetcher() { |
| 23 | CleanUp(); |
| 24 | } |
| 25 | |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 26 | void LibcurlHttpFetcher::ResumeTransfer(const std::string& url) { |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 27 | LOG(INFO) << "Starting/Resuming transfer"; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 28 | CHECK(!transfer_in_progress_); |
| 29 | url_ = url; |
| 30 | curl_multi_handle_ = curl_multi_init(); |
| 31 | CHECK(curl_multi_handle_); |
| 32 | |
| 33 | curl_handle_ = curl_easy_init(); |
| 34 | CHECK(curl_handle_); |
| 35 | |
| 36 | if (post_data_set_) { |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 37 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_POST, 1), CURLE_OK); |
| 38 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_POSTFIELDS, |
| 39 | &post_data_[0]), |
| 40 | CURLE_OK); |
| 41 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_POSTFIELDSIZE, |
| 42 | post_data_.size()), |
| 43 | CURLE_OK); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 44 | } |
| 45 | |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 46 | if (bytes_downloaded_ > 0) { |
| 47 | // Resume from where we left off |
| 48 | resume_offset_ = bytes_downloaded_; |
| 49 | CHECK_EQ(curl_easy_setopt(curl_handle_, |
| 50 | CURLOPT_RESUME_FROM_LARGE, |
| 51 | bytes_downloaded_), CURLE_OK); |
| 52 | } |
| 53 | |
| 54 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_WRITEDATA, this), CURLE_OK); |
| 55 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_WRITEFUNCTION, |
| 56 | StaticLibcurlWrite), CURLE_OK); |
| 57 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_URL, url_.c_str()), CURLE_OK); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 58 | |
Darin Petkov | 192ced4 | 2010-07-23 16:20:24 -0700 | [diff] [blame] | 59 | // If the connection drops under 10 bytes/sec for 3 minutes, reconnect. |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 60 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_LOW_SPEED_LIMIT, 10), |
| 61 | CURLE_OK); |
Darin Petkov | 192ced4 | 2010-07-23 16:20:24 -0700 | [diff] [blame] | 62 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_LOW_SPEED_TIME, 3 * 60), |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 63 | CURLE_OK); |
| 64 | |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 65 | // By default, libcurl doesn't follow redirections. Allow up to |
| 66 | // |kMaxRedirects| redirections. |
Darin Petkov | 3a4016a | 2010-09-28 13:54:17 -0700 | [diff] [blame] | 67 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_FOLLOWLOCATION, 1), CURLE_OK); |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 68 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_MAXREDIRS, kMaxRedirects), |
| 69 | CURLE_OK); |
| 70 | |
Darin Petkov | 3a4016a | 2010-09-28 13:54:17 -0700 | [diff] [blame] | 71 | // Makes sure that peer certificate verification is enabled and restricts the |
| 72 | // set of trusted certificates. |
| 73 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_SSL_VERIFYPEER, 1), CURLE_OK); |
| 74 | CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_CAPATH, kCACertificatesPath), |
| 75 | CURLE_OK); |
| 76 | |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 77 | CHECK_EQ(curl_multi_add_handle(curl_multi_handle_, curl_handle_), CURLM_OK); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 78 | transfer_in_progress_ = true; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 79 | } |
| 80 | |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 81 | // Begins the transfer, which must not have already been started. |
| 82 | void LibcurlHttpFetcher::BeginTransfer(const std::string& url) { |
| 83 | transfer_size_ = -1; |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 84 | resume_offset_ = 0; |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 85 | retry_count_ = 0; |
Darin Petkov | cb46621 | 2010-08-26 09:40:11 -0700 | [diff] [blame] | 86 | http_response_code_ = 0; |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 87 | ResumeTransfer(url); |
| 88 | CurlPerformOnce(); |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 89 | } |
| 90 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 91 | void LibcurlHttpFetcher::TerminateTransfer() { |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame^] | 92 | if (in_write_callback_) |
| 93 | terminate_requested_ = true; |
| 94 | else |
| 95 | CleanUp(); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Andrew de los Reyes | cb31933 | 2010-07-19 10:55:01 -0700 | [diff] [blame] | 98 | void LibcurlHttpFetcher::CurlPerformOnce() { |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 99 | CHECK(transfer_in_progress_); |
| 100 | int running_handles = 0; |
| 101 | CURLMcode retcode = CURLM_CALL_MULTI_PERFORM; |
| 102 | |
| 103 | // libcurl may request that we immediately call curl_multi_perform after it |
| 104 | // returns, so we do. libcurl promises that curl_multi_perform will not block. |
| 105 | while (CURLM_CALL_MULTI_PERFORM == retcode) { |
| 106 | retcode = curl_multi_perform(curl_multi_handle_, &running_handles); |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame^] | 107 | if (terminate_requested_) { |
| 108 | CleanUp(); |
| 109 | return; |
| 110 | } |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 111 | } |
| 112 | if (0 == running_handles) { |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame^] | 113 | GetHttpResponseCode(); |
| 114 | if (http_response_code_) { |
| 115 | LOG(INFO) << "HTTP response code: " << http_response_code_; |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 116 | } else { |
| 117 | LOG(ERROR) << "Unable to get http response code."; |
| 118 | } |
Darin Petkov | 192ced4 | 2010-07-23 16:20:24 -0700 | [diff] [blame] | 119 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 120 | // we're done! |
| 121 | CleanUp(); |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 122 | |
| 123 | if ((transfer_size_ >= 0) && (bytes_downloaded_ < transfer_size_)) { |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 124 | // Need to restart transfer |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 125 | retry_count_++; |
| 126 | LOG(INFO) << "Restarting transfer b/c we finished, had downloaded " |
| 127 | << bytes_downloaded_ << " bytes, but transfer_size_ is " |
| 128 | << transfer_size_ << ". retry_count: " << retry_count_; |
| 129 | if (retry_count_ > kMaxRetriesCount) { |
| 130 | if (delegate_) |
| 131 | delegate_->TransferComplete(this, false); // success |
| 132 | } else { |
Darin Petkov | b83371f | 2010-08-17 09:34:49 -0700 | [diff] [blame] | 133 | g_timeout_add_seconds(retry_seconds_, |
Darin Petkov | 9b11165 | 2010-08-16 11:46:25 -0700 | [diff] [blame] | 134 | &LibcurlHttpFetcher::StaticRetryTimeoutCallback, |
| 135 | this); |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 136 | } |
Andrew de los Reyes | cb31933 | 2010-07-19 10:55:01 -0700 | [diff] [blame] | 137 | return; |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 138 | } else { |
| 139 | if (delegate_) { |
Andrew de los Reyes | fb4ad7d | 2010-07-19 10:43:46 -0700 | [diff] [blame] | 140 | // success is when http_response_code is 2xx |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame^] | 141 | bool success = (http_response_code_ >= 200) && |
| 142 | (http_response_code_ < 300); |
Andrew de los Reyes | fb4ad7d | 2010-07-19 10:43:46 -0700 | [diff] [blame] | 143 | delegate_->TransferComplete(this, success); |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 146 | } else { |
| 147 | // set up callback |
| 148 | SetupMainloopSources(); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | size_t LibcurlHttpFetcher::LibcurlWrite(void *ptr, size_t size, size_t nmemb) { |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame^] | 153 | GetHttpResponseCode(); |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 154 | { |
| 155 | double transfer_size_double; |
| 156 | CHECK_EQ(curl_easy_getinfo(curl_handle_, |
| 157 | CURLINFO_CONTENT_LENGTH_DOWNLOAD, |
| 158 | &transfer_size_double), CURLE_OK); |
| 159 | off_t new_transfer_size = static_cast<off_t>(transfer_size_double); |
| 160 | if (new_transfer_size > 0) { |
| 161 | transfer_size_ = resume_offset_ + new_transfer_size; |
| 162 | } |
| 163 | } |
| 164 | bytes_downloaded_ += size * nmemb; |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame^] | 165 | in_write_callback_ = true; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 166 | if (delegate_) |
| 167 | delegate_->ReceivedBytes(this, reinterpret_cast<char*>(ptr), size * nmemb); |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame^] | 168 | in_write_callback_ = false; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 169 | return size * nmemb; |
| 170 | } |
| 171 | |
| 172 | void LibcurlHttpFetcher::Pause() { |
| 173 | CHECK(curl_handle_); |
| 174 | CHECK(transfer_in_progress_); |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 175 | CHECK_EQ(curl_easy_pause(curl_handle_, CURLPAUSE_ALL), CURLE_OK); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | void LibcurlHttpFetcher::Unpause() { |
| 179 | CHECK(curl_handle_); |
| 180 | CHECK(transfer_in_progress_); |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 181 | CHECK_EQ(curl_easy_pause(curl_handle_, CURLPAUSE_CONT), CURLE_OK); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // This method sets up callbacks with the glib main loop. |
| 185 | void LibcurlHttpFetcher::SetupMainloopSources() { |
| 186 | fd_set fd_read; |
| 187 | fd_set fd_write; |
| 188 | fd_set fd_exec; |
| 189 | |
| 190 | FD_ZERO(&fd_read); |
| 191 | FD_ZERO(&fd_write); |
| 192 | FD_ZERO(&fd_exec); |
| 193 | |
| 194 | int fd_max = 0; |
| 195 | |
| 196 | // Ask libcurl for the set of file descriptors we should track on its |
| 197 | // behalf. |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 198 | CHECK_EQ(curl_multi_fdset(curl_multi_handle_, &fd_read, &fd_write, |
| 199 | &fd_exec, &fd_max), CURLM_OK); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 200 | |
| 201 | // We should iterate through all file descriptors up to libcurl's fd_max or |
| 202 | // the highest one we're tracking, whichever is larger |
| 203 | if (!io_channels_.empty()) |
| 204 | fd_max = max(fd_max, io_channels_.rbegin()->first); |
| 205 | |
| 206 | // For each fd, if we're not tracking it, track it. If we are tracking it, |
| 207 | // but libcurl doesn't care about it anymore, stop tracking it. |
| 208 | // After this loop, there should be exactly as many GIOChannel objects |
| 209 | // in io_channels_ as there are fds that we're tracking. |
| 210 | for (int i = 0; i <= fd_max; i++) { |
| 211 | if (!(FD_ISSET(i, &fd_read) || FD_ISSET(i, &fd_write) || |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 212 | FD_ISSET(i, &fd_exec))) { |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 213 | // if we have an outstanding io_channel, remove it |
| 214 | if (io_channels_.find(i) != io_channels_.end()) { |
| 215 | g_source_remove(io_channels_[i].second); |
| 216 | g_io_channel_unref(io_channels_[i].first); |
| 217 | io_channels_.erase(io_channels_.find(i)); |
| 218 | } |
| 219 | continue; |
| 220 | } |
| 221 | // If we are already tracking this fd, continue. |
| 222 | if (io_channels_.find(i) != io_channels_.end()) |
| 223 | continue; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 224 | // We must track a new fd |
| 225 | GIOChannel *io_channel = g_io_channel_unix_new(i); |
| 226 | guint tag = g_io_add_watch( |
| 227 | io_channel, |
| 228 | static_cast<GIOCondition>(G_IO_IN | G_IO_OUT | G_IO_PRI | |
| 229 | G_IO_ERR | G_IO_HUP), |
| 230 | &StaticFDCallback, |
| 231 | this); |
| 232 | io_channels_[i] = make_pair(io_channel, tag); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 233 | static int io_counter = 0; |
| 234 | io_counter++; |
| 235 | if (io_counter % 50 == 0) { |
| 236 | LOG(INFO) << "io_counter = " << io_counter; |
| 237 | } |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Darin Petkov | b83371f | 2010-08-17 09:34:49 -0700 | [diff] [blame] | 240 | // Set up a timeout callback for libcurl. |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 241 | if (!timeout_source_) { |
Darin Petkov | b83371f | 2010-08-17 09:34:49 -0700 | [diff] [blame] | 242 | LOG(INFO) << "Setting up timeout source: " << idle_seconds_ << " seconds."; |
| 243 | timeout_source_ = g_timeout_source_new_seconds(idle_seconds_); |
| 244 | g_source_set_callback(timeout_source_, StaticTimeoutCallback, this, NULL); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 245 | g_source_attach(timeout_source_, NULL); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 246 | } |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | bool LibcurlHttpFetcher::FDCallback(GIOChannel *source, |
| 250 | GIOCondition condition) { |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 251 | CurlPerformOnce(); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 252 | // We handle removing of this source elsewhere, so we always return true. |
| 253 | // The docs say, "the function should return FALSE if the event source |
| 254 | // should be removed." |
| 255 | // http://www.gtk.org/api/2.6/glib/glib-IO-Channels.html#GIOFunc |
| 256 | return true; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 259 | gboolean LibcurlHttpFetcher::RetryTimeoutCallback() { |
| 260 | ResumeTransfer(url_); |
| 261 | CurlPerformOnce(); |
| 262 | return FALSE; // Don't have glib auto call this callback again |
| 263 | } |
| 264 | |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 265 | gboolean LibcurlHttpFetcher::TimeoutCallback() { |
Andrew de los Reyes | cb31933 | 2010-07-19 10:55:01 -0700 | [diff] [blame] | 266 | // We always return true, even if we don't want glib to call us back. |
| 267 | // We will remove the event source separately if we don't want to |
| 268 | // be called back. |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 269 | if (!transfer_in_progress_) |
| 270 | return TRUE; |
Andrew de los Reyes | 9bbd187 | 2010-07-16 14:52:29 -0700 | [diff] [blame] | 271 | CurlPerformOnce(); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 272 | return TRUE; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void LibcurlHttpFetcher::CleanUp() { |
| 276 | if (timeout_source_) { |
| 277 | g_source_destroy(timeout_source_); |
| 278 | timeout_source_ = NULL; |
| 279 | } |
| 280 | |
| 281 | for (IOChannels::iterator it = io_channels_.begin(); |
| 282 | it != io_channels_.end(); ++it) { |
| 283 | g_source_remove(it->second.second); |
| 284 | g_io_channel_unref(it->second.first); |
| 285 | } |
| 286 | io_channels_.clear(); |
| 287 | |
| 288 | if (curl_handle_) { |
| 289 | if (curl_multi_handle_) { |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 290 | CHECK_EQ(curl_multi_remove_handle(curl_multi_handle_, curl_handle_), |
| 291 | CURLM_OK); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 292 | } |
| 293 | curl_easy_cleanup(curl_handle_); |
| 294 | curl_handle_ = NULL; |
| 295 | } |
| 296 | if (curl_multi_handle_) { |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 297 | CHECK_EQ(curl_multi_cleanup(curl_multi_handle_), CURLM_OK); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 298 | curl_multi_handle_ = NULL; |
| 299 | } |
| 300 | transfer_in_progress_ = false; |
| 301 | } |
| 302 | |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame^] | 303 | void LibcurlHttpFetcher::GetHttpResponseCode() { |
| 304 | long http_response_code = 0; |
| 305 | if (curl_easy_getinfo(curl_handle_, |
| 306 | CURLINFO_RESPONSE_CODE, |
| 307 | &http_response_code) == CURLE_OK) { |
| 308 | http_response_code_ = static_cast<int>(http_response_code); |
| 309 | } |
| 310 | } |
| 311 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 312 | } // namespace chromeos_update_engine |