首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >evhttp_request_new() evhttp_request返回null

问evhttp_request_new() evhttp_request返回null
EN

Stack Overflow用户
提问于 2013-01-30 11:41:24
回答 1查看 1.4K关注 0票数 0

我写了一个libevet程序来从某个web界面获取数据。代码如下:有时候self->done的结构evhttp_request *req是空的。我找不到这是为什么。

代码语言:javascript
复制
response->connecttime = spi_utils_float_time();
self->evreq = evhttp_request_new(self->done, task);
if (self->evreq == NULL) {
    SPI_LOG_ERROR("spider", "cannot create evhttp_request");
    goto download_error;
}

/* bson_print(&task->task); */

/** set header and body */
/* TODO: set timeout */
spi_http_request_split_header(self, self->header->str, self->evreq);
if (self->body != NULL)
    evbuffer_add_printf(self->evreq->output_buffer, (const char*)self->body->str);

    if (self->method == spi_http_post)
            cmd_type = EVHTTP_REQ_POST;

self->evcon = evhttp_connection_new(self->host->str, self->port);
if (self->evcon == NULL) {
    SPI_LOG_ERROR("spider", "evhttp_connection_new Failed!\n");
    goto download_error;
}

SPI_LOG_DEBUG("spider", "set retries: %d.", 5);
evhttp_connection_set_retries(self->evcon, 3);
SPI_LOG_DEBUG("spider", "set timeout: %d.", 60);
evhttp_connection_set_timeout(self->evcon, 20);

response->connectedtime = spi_utils_float_time();

response->crawltime = spi_utils_float_time();

SPI_LOG_DEBUG("spider", "evhttp_make_request");
if (evhttp_make_request(self->evcon, self->evreq, cmd_type, self->path->str) == -1) {
    SPI_LOG_ERROR("spider", "evhttp_make_request Failed.\n");
    goto download_error;
}
EN

回答 1

Stack Overflow用户

发布于 2013-07-07 06:46:59

(从你的问题看,不完全清楚你是从哪里得到NULL的,但你的意思可能是)

如果超时,传递给evhttp_request_new的回调可能会得到NULL。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14596297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档