diff --git a/src/http.cc b/src/http.cc index 9c16bdac86d73bf3057f3c9e5e2e6490cc9b7c78..ef242fb407753f0efe50b37c00d02f905fc8c598 100644 --- a/src/http.cc +++ b/src/http.cc @@ -19,17 +19,23 @@ */ #include "http.h" +#include "config.h" #include <stdio.h> #include <unistd.h> namespace microb { int Uploader::curl_read_cb(char *buffer, size_t size, size_t nitems, - void *instream) { - Uploader *up = static_cast<Uploader *>(instream); + void *user_data) { + Uploader *up = static_cast<Uploader *>(user_data); return up->callback(buffer, size, nitems); } +int Uploader::curl_write_cb(char *buffer, size_t size, size_t nitems, + void *user_data) { + return size * nitems; +} + void Uploader::close() { stop_.set(); ring_buffer_->close(); @@ -76,12 +82,17 @@ util::Status Uploader::init_request() { curl_easy_setopt(handle_, CURLOPT_USERNAME, username_.c_str()); curl_easy_setopt(handle_, CURLOPT_PASSWORD, password_.c_str()); } + curl_easy_setopt(handle_, CURLOPT_NOSIGNAL, 1); + // curl_easy_setopt(handle_, CURLOPT_HTTP_TRANSFER_DECODING, 0); curl_easy_setopt(handle_, CURLOPT_UPLOAD, 1); curl_easy_setopt(handle_, CURLOPT_FAILONERROR, 1); curl_easy_setopt(handle_, CURLOPT_ERRORBUFFER, errbuf_); curl_easy_setopt(handle_, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(handle_, CURLOPT_READFUNCTION, curl_read_cb); curl_easy_setopt(handle_, CURLOPT_READDATA, static_cast<void *>(this)); + curl_easy_setopt(handle_, CURLOPT_WRITEFUNCTION, curl_write_cb); + curl_easy_setopt(handle_, CURLOPT_USERAGENT, + PACKAGE_NAME "/" PACKAGE_VERSION); return util::Status(OK); } diff --git a/src/http.h b/src/http.h index 2a9c3df03d9738d6d5c8d3b21c29cfdc30181275..f75d4adc8a4927c0e76073fc075be0dc1a8da3c5 100644 --- a/src/http.h +++ b/src/http.h @@ -93,8 +93,9 @@ protected: util::Status init_request(); static int curl_read_cb(char *buffer, size_t size, size_t nitems, - void *instream); - static void *curl_run_cb(void *ptr); + void *user_data); + static int curl_write_cb(char *buffer, size_t size, size_t nitems, + void *user_data); }; void http_initialize();