59 static size_t HTTPConvergenceLayer_callback_read(
void *ptr,
size_t size,
size_t nmemb,
void *s)
62 std::istream *stream =
static_cast<std::istream*
>(s);
64 if (stream->eof())
return 0;
66 char *buffer =
static_cast<char*
>(ptr);
68 stream->read(buffer, (size * nmemb));
69 retcode = stream->gcount();
82 static size_t HTTPConvergenceLayer_callback_write(
void *ptr,
size_t size,
size_t nmemb,
void *s)
84 std::ostream *stream =
static_cast<std::ostream*
>(s);
85 char *buffer =
static_cast<char*
>(ptr);
87 if (!stream->good())
return 0;
89 stream->write(buffer, (size * nmemb));
92 return (size * nmemb);
103 : _server(server), _push_iob(NULL),
_running(true)
105 curl_global_init(CURL_GLOBAL_ALL);
115 curl_global_cleanup();
149 while(_stream.good())
164 std::cerr <<
"error: " << e.
what() << std::endl;
188 std::string url_send;
204 size_t length = io.
size();
218 curl_up = curl_easy_init();
222 curl_easy_setopt(curl_up, CURLOPT_READFUNCTION, HTTPConvergenceLayer_callback_read);
225 curl_easy_setopt(curl_up, CURLOPT_UPLOAD, 1L);
228 curl_easy_setopt(curl_up, CURLOPT_PUT, 1L);
231 curl_easy_setopt(curl_up, CURLOPT_CONNECTTIMEOUT, 0);
235 curl_easy_setopt(curl_up, CURLOPT_URL, url_send.c_str());
238 curl_easy_setopt(curl_up, CURLOPT_READDATA, &(*io));
242 curl_easy_setopt(curl_up, CURLOPT_INFILESIZE_LARGE,
246 res = curl_easy_perform(curl_up);
251 curl_easy_getinfo (curl_up, CURLINFO_RESPONSE_CODE, &http_code);
267 curl_easy_cleanup(curl_up);
314 curl_down = curl_easy_init();
318 curl_easy_setopt(curl_down, CURLOPT_URL, url.c_str());
321 curl_easy_setopt(curl_down, CURLOPT_CONNECTTIMEOUT, 0);
324 curl_easy_setopt(curl_down, CURLOPT_NOPROGRESS, 1L);
339 std::auto_ptr<ibrcommon::iobuffer> auto_kill(_push_iob);
340 std::ostream os(_push_iob);
344 curl_easy_setopt(curl_down, CURLOPT_WRITEFUNCTION, HTTPConvergenceLayer_callback_write);
347 curl_easy_setopt(curl_down, CURLOPT_WRITEDATA, &os);
351 curl_easy_perform(curl_down);
372 curl_easy_cleanup(curl_down);
395 if (_push_iob != NULL)
408 return "HTTPConvergenceLayer";