本文整理汇总了C++中curl_easy_reset函数的典型用法代码示例。如果您正苦于以下问题:C++ curl_easy_reset函数的具体用法?C++ curl_easy_reset怎么用?C++ curl_easy_reset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_easy_reset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: curl_set_handle_opts
static void curl_set_handle_opts(struct dload_payload *payload,
CURL *curl, char *error_buffer)
{
alpm_handle_t *handle = payload->handle;
const char *useragent = getenv("HTTP_USER_AGENT");
struct stat st;
/* the curl_easy handle is initialized with the alpm handle, so we only need
* to reset the handle's parameters for each time it's used. */
curl_easy_reset(curl);
curl_easy_setopt(curl, CURLOPT_URL, payload->fileurl);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, dload_progress_cb);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, (void *)payload);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, dload_parseheader_cb);
curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)payload);
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, dload_sockopt_cb);
curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, (void *)handle);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
_alpm_log(handle, ALPM_LOG_DEBUG, "url: %s\n", payload->fileurl);
if(payload->max_size) {
_alpm_log(handle, ALPM_LOG_DEBUG, "maxsize: %jd\n",
(intmax_t)payload->max_size);
curl_easy_setopt(curl, CURLOPT_MAXFILESIZE_LARGE,
(curl_off_t)payload->max_size);
}
if(useragent != NULL) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, useragent);
}
if(!payload->allow_resume && !payload->force && payload->destfile_name &&
stat(payload->destfile_name, &st) == 0) {
/* start from scratch, but only download if our local is out of date. */
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, (long)st.st_mtime);
_alpm_log(handle, ALPM_LOG_DEBUG,
"using time condition: %lu\n", (long)st.st_mtime);
} else if(stat(payload->tempfile_name, &st) == 0 && payload->allow_resume) {
/* a previous partial download exists, resume from end of file. */
payload->tempfile_openmode = "ab";
curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, (curl_off_t)st.st_size);
_alpm_log(handle, ALPM_LOG_DEBUG,
"tempfile found, attempting continuation from %jd bytes\n",
(intmax_t)st.st_size);
payload->initial_size = st.st_size;
}
}
示例2: ds3_connection_release
void ds3_connection_release(ds3_connection_pool* pool, ds3_connection* connection) {
g_mutex_lock(&pool->mutex);
curl_easy_reset(connection);
pool->tail = _pool_inc(pool, pool->tail);
g_mutex_unlock(&pool->mutex);
g_cond_signal(&pool->available_connections);
}
示例3: _ResetHandle
void
_ResetHandle() {
curl_easy_reset(handle_);
#ifdef DEBUG
curl_easy_setopt(handle_, CURLOPT_VERBOSE, 1L);
#ifdef CRAZY_VERBOSE
curl_easy_setopt(handle_, CURLOPT_DEBUGFUNCTION, _CurlTrace);
#endif
#endif
}
示例4: authRequest
json_t* authRequest(Parameters& params, std::string url, std::string signature, std::string content) {
unsigned char digest[MD5_DIGEST_LENGTH];
MD5((unsigned char*)signature.c_str(), strlen(signature.c_str()), (unsigned char*)&digest);
char mdString[33];
for (int i = 0; i < 16; i++) {
sprintf(&mdString[i*2], "%02X", (unsigned int)digest[i]);
}
std::ostringstream oss;
oss << content << "&sign=" << mdString;
std::string postParameters = oss.str().c_str();
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "contentType: application/x-www-form-urlencoded");
CURLcode resCurl;
if (params.curl) {
curl_easy_setopt(params.curl, CURLOPT_POST,1L);
curl_easy_setopt(params.curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(params.curl, CURLOPT_POSTFIELDS, postParameters.c_str());
curl_easy_setopt(params.curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(params.curl, CURLOPT_WRITEFUNCTION, WriteCallback);
std::string readBuffer;
curl_easy_setopt(params.curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(params.curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(params.curl, CURLOPT_CONNECTTIMEOUT, 10L);
resCurl = curl_easy_perform(params.curl);
json_t* root;
json_error_t error;
while (resCurl != CURLE_OK) {
*params.logFile << "<OKCoin> Error with cURL. Retry in 2 sec..." << std::endl;
sleep(4.0);
resCurl = curl_easy_perform(params.curl);
}
root = json_loads(readBuffer.c_str(), 0, &error);
while (!root) {
*params.logFile << "<OKCoin> Error with JSON:\n" << error.text << std::endl;
*params.logFile << "<OKCoin> Buffer:\n" << readBuffer.c_str() << std::endl;
*params.logFile << "<OKCoin> Retrying..." << std::endl;
sleep(4.0);
readBuffer = "";
resCurl = curl_easy_perform(params.curl);
while (resCurl != CURLE_OK) {
*params.logFile << "<OKCoin> Error with cURL. Retry in 2 sec..." << std::endl;
sleep(4.0);
readBuffer = "";
resCurl = curl_easy_perform(params.curl);
}
root = json_loads(readBuffer.c_str(), 0, &error);
}
curl_slist_free_all(headers);
curl_easy_reset(params.curl);
return root;
} else {
*params.logFile << "<OKCoin> Error with cURL init." << std::endl;
return NULL;
}
}
示例5: qeo_mgmt_curl_util_https_get_with_cb
qeo_mgmt_client_retcode_t qeo_mgmt_curl_util_https_get_with_cb(qeo_mgmt_client_ctx_t *mg_ctx,
const char* url,
char *header,
qeo_mgmt_client_ssl_ctx_cb ssl_cb,
void *ssl_cookie,
curl_write_callback data_cb,
void *write_cookie)
{
curl_ssl_ctx_helper curlsslhelper = { ssl_cb, ssl_cookie };
qeo_mgmt_client_retcode_t ret = QMGMTCLIENT_EFAIL;
const char *cafile = NULL;
const char *capath = NULL;
//Setting CURLOPT_CAINF and PATH is mandatory; otherwise SSL_CTX_FUNCTION will not be called.
curl_opt_helper opts[] = {
{ CURLOPT_SSL_VERIFYHOST, (void*)2 }, /* ensure certificate matches host */
{ CURLOPT_SSL_VERIFYPEER, (void*)0 }, /* ensure certificate is valid */
{ CURLOPT_CAINFO, NULL },
{ CURLOPT_CAPATH, NULL },
{ CURLOPT_SSL_CTX_FUNCTION, (void*)qeo_mgmt_curl_sslctx_cb },
{ CURLOPT_SSL_CTX_DATA, (void*)&curlsslhelper }
};
bool reset = false;
do {
if ((mg_ctx == NULL ) || (mg_ctx->curl_ctx == NULL) || (url == NULL) || (ssl_cb == NULL) || (data_cb == NULL)){
ret = QMGMTCLIENT_EINVAL;
break;
}
if (QEO_UTIL_OK != qeo_platform_get_cacert_path(&cafile, &capath)) {
ret = QMGMTCLIENT_EFAIL;
break;
}
/* insert values into options array */
opts[2].cookie = (void*)cafile;
opts[3].cookie = (void*)capath;
reset = true;
if (CURLE_OK != qeo_mgmt_curl_util_set_opts(opts, sizeof(opts) / sizeof(curl_opt_helper), mg_ctx)) {
ret = QMGMTCLIENT_EINVAL;
break;
}
ret = qeo_mgmt_curl_util_http_get_with_cb(mg_ctx, url, header, data_cb, write_cookie);
reset = false;/* Already done. */
} while (0);
if (reset == true){
/* Make sure we reset all configuration for next calls */
curl_easy_reset(mg_ctx->curl_ctx);
}
if (ret != QMGMTCLIENT_OK) {
qeo_log_w("Failure in https_get_%s",url);
}
return ret;
}
示例6: return_connection
void return_connection(CURL *curl)
{
curl_easy_reset(curl) ;
pthread_mutex_lock(&pool_mut);
if(curl_pool.free_connect_count >= curl_pool.buffer_connect_count)
curl_easy_cleanup(curl) ;
else
curl_pool.curl_free_connect[(curl_pool.free_connect_count)++] = curl ;
curl_pool.used_connect_count-- ;
pthread_mutex_unlock(&pool_mut);
}
示例7: R_handle_reset
SEXP R_handle_reset(SEXP ptr){
//reset all fields
reference *ref = get_ref(ptr);
set_form(ref, NULL);
set_headers(ref, NULL);
curl_easy_reset(ref->handle);
//restore default settings
set_handle_defaults(ref);
return ScalarLogical(1);
}
示例8: curl_easy_reset
bool curlHttpRequest::Request(const std::string &url, const std::string &request, std::string method, std::string &response, int timeout)
{
m_response_code = 0;
response.clear();
response.reserve(64 * 1024);
curl_easy_reset(m_pcurl);
curl_easy_setopt(m_pcurl, CURLOPT_URL, url.c_str());
curl_easy_setopt(m_pcurl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(m_pcurl, CURLOPT_TIMEOUT, timeout);
curl_easy_setopt(m_pcurl, CURLOPT_WRITEFUNCTION,curlHttpRequest::WriteData);
curl_easy_setopt(m_pcurl, CURLOPT_WRITEDATA, &response);
if(method == "get")
{
curl_easy_setopt(m_pcurl, CURLOPT_HTTPGET, 1);
}
else if(method == "post")
{
curl_easy_setopt(m_pcurl, CURLOPT_POST, 1L);
curl_easy_setopt(m_pcurl, CURLOPT_POSTFIELDSIZE, request.length());
curl_easy_setopt(m_pcurl, CURLOPT_POSTFIELDS, request.c_str());
}
else if(method == "put")
{
curl_easy_setopt(m_pcurl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(m_pcurl, CURLOPT_POSTFIELDSIZE, request.length());
curl_easy_setopt(m_pcurl, CURLOPT_POSTFIELDS, request.c_str());
}
else if(method == "delete")
{
curl_easy_setopt(m_pcurl, CURLOPT_CUSTOMREQUEST, "DELETE");
}
else
{
return false;
}
CURLcode rc = curl_easy_perform(m_pcurl);
if(rc != CURLE_OK)
{
m_error = std::string(curl_easy_strerror(rc));
return false;
}
rc = curl_easy_getinfo(m_pcurl, CURLINFO_RESPONSE_CODE , &m_response_code);
if(rc != CURLE_OK)
{
m_error = std::string(curl_easy_strerror(rc));
return false;
}
return true;
}
示例9: http_reset_request
void http_reset_request (
http_t * http
)
{
if ( unlikely (! http) )
{
return;
}
curl_easy_reset (http->curl);
http_clear_form (http);
}
示例10: HttpClient_Init
/* 初始化HttpClient,使用前务必调用 */
void HttpClient_Init(HttpClient *client) {
//{{{
curl_version_info_data *version;
if (client->curl == NULL) {
client->curl = curl_easy_init();
client->responseText = HttpBuffer_New();
client->responseHeader = HttpBuffer_New();
} else {
curl_easy_reset(client->curl);
}
/* 重置失败次数 */
client->fail_times = 0;
client->retry_times = 5;
client->retry_interval = 1;
/* 重置失败回调 */
client->fail_reset_callback = NULL;
client->fail_reset_context = NULL;
/* 清空body cstr */
if (client->c_responseText != NULL) {
free(client->c_responseText);
client->c_responseText = NULL;
}
/* 清空header cstr */
if (client->c_responseHeader != NULL) {
free(client->c_responseText);
client->c_responseText = NULL;
}
/* curl 初始化 */
curl_easy_setopt(client->curl, CURLOPT_WRITEFUNCTION, _HttpClient_WriteData);
curl_easy_setopt(client->curl, CURLOPT_WRITEDATA, client);
curl_easy_setopt(client->curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(client->curl, CURLOPT_SSL_VERIFYHOST, 0);
/* 选个快点的加密算法 */
version = curl_version_info(CURLVERSION_NOW);
if (strstr(version->ssl_version, "OpenSSL") != NULL) {
curl_easy_setopt(client->curl, CURLOPT_SSL_CIPHER_LIST, "RC4-SHA");
} else if (strstr(version->ssl_version, "NSS") != NULL) {
curl_easy_setopt(client->curl, CURLOPT_SSL_CIPHER_LIST, "rc4,rsa_rc4_128_sha");
}
/* 设置默认超时时间 */
curl_easy_setopt(client->curl, CURLOPT_TIMEOUT, 20);
curl_easy_setopt(client->curl, CURLOPT_CONNECTTIMEOUT, 5);
}
示例11: test
int test(char *URL)
{
CURLM *multi;
CURL *easy;
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
if ((multi = curl_multi_init()) == NULL) {
fprintf(stderr, "curl_multi_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
if ((easy = curl_easy_init()) == NULL) {
fprintf(stderr, "curl_easy_init() failed\n");
curl_multi_cleanup(multi);
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
curl_multi_setopt(multi, CURLMOPT_PIPELINING, 1);
curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(easy, CURLOPT_URL, URL);
curl_multi_add_handle(multi, easy);
if (perform(multi) != CURLM_OK)
printf("retrieve 1 failed\n");
curl_multi_remove_handle(multi, easy);
curl_easy_reset(easy);
curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(easy, CURLOPT_URL, arg2);
curl_multi_add_handle(multi, easy);
if (perform(multi) != CURLM_OK)
printf("retrieve 2 failed\n");
curl_multi_remove_handle(multi, easy);
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_global_cleanup();
printf("Finished!\n");
return 0;
}
示例12: curl_context_cleanup
/* ****************************************************************************
*
* curl_context_cleanup -
*/
void curl_context_cleanup(void)
{
for (std::map<std::string, struct curl_context>::iterator it = contexts.begin(); it != contexts.end(); ++it)
{
curl_easy_reset(it->second.curl);
curl_easy_cleanup(it->second.curl);
it->second.curl = NULL;
release_curl_context(&it->second, true);
}
contexts.clear();
curl_global_cleanup();
}
示例13: init
///============================CLEAN BEFORE CLOSING==================================///
void Browser::clean()
{
init();
curl_easy_reset(curl);
history_.clear();
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept:");
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
curl = curl_easy_init();
}
示例14: initFile
/**
* @brief 开始文件下载任务
* @author LuChenQun
* @date 2015/07/05
* @return int 任务结果
*/
int NetWork::startDownloadFile()
{
int code = CURLE_OK;
QByteArray urlBa = m_url.toLocal8Bit();
char *url = urlBa.data();
// 初始化文件
code = initFile();
if (code != NETWORK_INIT_FILE_SUCCESS)
{
return code;
}
curl_easy_reset(m_curl);
curl_easy_setopt(m_curl, CURLOPT_URL, url);
curl_easy_setopt(m_curl, CURLOPT_LOW_SPEED_LIMIT, 10);
curl_easy_setopt(m_curl, CURLOPT_LOW_SPEED_TIME, 300);
curl_easy_setopt(m_curl, CURLOPT_HEADER, 1);
curl_easy_setopt(m_curl, CURLOPT_NOBODY, 1);
// 获取文件大小
code = curl_easy_perform(m_curl);
double fileSize = 0;
curl_easy_getinfo(m_curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fileSize);
emitFileSize(fileSize);
if (getDiskFreeSpace("e:/") <= (m_fileSize))
{
code = NETWORK_DISK_NO_SPACE;
return code;
}
curl_easy_setopt(m_curl, CURLOPT_HEADER, 0);
curl_easy_setopt(m_curl, CURLOPT_NOBODY, 0);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, writeData);
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, this);
curl_easy_setopt(m_curl, CURLOPT_RESUME_FROM_LARGE, m_breakPoint); // 断点续传
curl_easy_setopt(m_curl, CURLOPT_XFERINFOFUNCTION, progress); // 进度
curl_easy_setopt(m_curl, CURLOPT_XFERINFODATA, this);
curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1L); // 多线程需要注意的
curl_easy_setopt(m_curl, CURLOPT_FORBID_REUSE, 1);
code = curl_easy_perform(m_curl);
m_downloadFile.flush();
m_downloadFile.close();
return code;
}
示例15: request_deinitialize
static void request_deinitialize(Request *request)
{
if (request->headers) {
curl_slist_free_all(request->headers);
}
error_parser_deinitialize(&(request->errorParser));
// curl_easy_reset prevents connections from being re-used for some
// reason. This makes HTTP Keep-Alive meaningless and is very bad for
// performance. But it is necessary to allow curl to work properly.
// xxx todo figure out why
curl_easy_reset(request->curl);
}