http - Why does evhttp_request_get_connection() always return NULL? -


in following example program:

#include <event2/event.h> #include <event2/http.h> #include <assert.h>  void response_cb(struct evhttp_request* req, void *arg) {     assert(evhttp_request_get_response_code(req)<400);/* passes */     assert(evhttp_request_get_connection(req));/* fails ??? */ }  int main(int argc, char **argv) {     struct event_base* ev_base;     struct evhttp_connection *http_conn;     struct evhttp_request *req;      ev_base = event_base_new();     http_conn = evhttp_connection_base_new(ev_base, null, "google.com", 80);     req = evhttp_request_new(response_cb, null);      evhttp_make_request(http_conn, req, evhttp_req_get, "/");      event_base_dispatch(ev_base);     return -1; } 

in response_cb first assert passes, expected, seconds fails i.e. evhttp_request_get_connection(req) returns null. why that?

the documentation evhttp_request_get_connection claims:

returns connection object associated request or null.

but still have connection. not dispose of anywhere.

am doing wrong or bug or obscure feature?

you cannot pointer connection in response callback, because connection has been released (closed, or kept open fore reuse if http keepalive enabled).

you can see in evhttp_connection_done() (http.c, around lines 780 817) response callback called after request's connection field (evcon) has been set null. agree evhttp api not clear, though.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -