From 2967f903d89ab0387e226873abef4cc34a8f366e Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Tue, 24 May 2016 06:25:28 +0100 Subject: [PATCH] discard data received from http connection --- src/http.cc | 15 +++++++++++++-- src/http.h | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/http.cc b/src/http.cc index 9c16bda..ef242fb 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 2a9c3df..f75d4ad 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(); -- GitLab