From 12c29b0f6eb55cfc096276f3ad808248cee6ff76 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 21 Mar 2014 17:32:09 +0400 Subject: [PATCH] Add evhttp_connection_set_family() to set addrinfo->family for DNS requests This is useful if you want to avoid extra dns requests. --- http-internal.h | 1 + http.c | 9 ++++++++- include/event2/http.h | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/http-internal.h b/http-internal.h index 82dd402a..6f2f5b85 100644 --- a/http-internal.h +++ b/http-internal.h @@ -99,6 +99,7 @@ struct evhttp_connection { struct event_base *base; struct evdns_base *dns_base; + int ai_family; /* Saved conn_addr, to extract IP address from it. * diff --git a/http.c b/http.c index e8672b77..2c153b71 100644 --- a/http.c +++ b/http.c @@ -2259,6 +2259,7 @@ evhttp_connection_base_bufferevent_new(struct event_base *base, struct evdns_bas evhttp_deferred_read_cb, evcon); evcon->dns_base = dnsbase; + evcon->ai_family = AF_UNSPEC; return (evcon); @@ -2286,6 +2287,12 @@ evhttp_connection_base_new(struct event_base *base, struct evdns_base *dnsbase, return evhttp_connection_base_bufferevent_new(base, dnsbase, NULL, address, port); } +void evhttp_connection_set_family(struct evhttp_connection *evcon, + int family) +{ + evcon->ai_family = family; +} + void evhttp_connection_set_base(struct evhttp_connection *evcon, struct event_base *base) @@ -2411,7 +2418,7 @@ evhttp_connection_connect_(struct evhttp_connection *evcon) evcon->state = EVCON_CONNECTING; if (bufferevent_socket_connect_hostname(evcon->bufev, evcon->dns_base, - AF_UNSPEC, evcon->address, evcon->port) < 0) { + evcon->ai_family, evcon->address, evcon->port) < 0) { evcon->state = old_state; event_sock_warn(evcon->fd, "%s: connection to \"%s\" failed", __func__, evcon->address); diff --git a/include/event2/http.h b/include/event2/http.h index 956d9d6c..69aa8012 100644 --- a/include/event2/http.h +++ b/include/event2/http.h @@ -546,6 +546,12 @@ struct evhttp_connection *evhttp_connection_base_new( struct event_base *base, struct evdns_base *dnsbase, const char *address, unsigned short port); +/** + * Set family hint for DNS requests. + */ +void evhttp_connection_set_family(struct evhttp_connection *evcon, + int family); + /** Takes ownership of the request object * * Can be used in a request callback to keep onto the request until