]> granicus.if.org Git - libevent/commitdiff
Add evhttp_connection_set_family() to set addrinfo->family for DNS requests
authorAzat Khuzhin <a3at.mail@gmail.com>
Fri, 21 Mar 2014 13:32:09 +0000 (17:32 +0400)
committerAzat Khuzhin <a3at.mail@gmail.com>
Fri, 21 Mar 2014 13:32:09 +0000 (17:32 +0400)
This is useful if you want to avoid extra dns requests.

http-internal.h
http.c
include/event2/http.h

index 82dd402a06264fba874bcc0a1e171a8efa0f2508..6f2f5b855d93c6ac31f0a3fe9cbbf3cd086a00ea 100644 (file)
@@ -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 e8672b778095f04b08bb17dcb2c8fcaadf27dc6a..2c153b71f735935c21cfb4507141b1219b009cbf 100644 (file)
--- 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);
index 956d9d6c86a83c2dc83850c6e5a11f0668267bc8..69aa801208cd7de0a26d01b319c1c48bb5b6bb35 100644 (file)
@@ -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