]> granicus.if.org Git - libevent/commitdiff
http: reuse connected address only with EVHTTP_CON_REUSE_CONNECTED_ADDR
authorAzat Khuzhin <a3at.mail@gmail.com>
Thu, 1 Jan 2015 03:27:31 +0000 (06:27 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Tue, 18 Aug 2015 17:06:53 +0000 (20:06 +0300)
http.c
include/event2/http.h
test/regress_http.c

diff --git a/http.c b/http.c
index 500e3e2a639b08facaed733568458802524c494f..f1038f7b21822dccc4e2a6dc3ffb26f313603996 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2334,6 +2334,20 @@ void evhttp_connection_set_family(struct evhttp_connection *evcon,
        evcon->ai_family = family;
 }
 
+int evhttp_connection_set_flags(struct evhttp_connection *evcon,
+       int flags)
+{
+       if (flags & ~(EVHTTP_CON_REUSE_CONNECTED_ADDR)) {
+               return 1;
+       }
+
+       evcon->flags &= ~(EVHTTP_CON_REUSE_CONNECTED_ADDR);
+
+       evcon->flags |= EVHTTP_CON_REUSE_CONNECTED_ADDR;
+
+       return 0;
+}
+
 void
 evhttp_connection_set_base(struct evhttp_connection *evcon,
     struct event_base *base)
@@ -2461,7 +2475,9 @@ evhttp_connection_connect_(struct evhttp_connection *evcon)
 
        evcon->state = EVCON_CONNECTING;
 
-       if (sa && (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)) {
+       if (evcon->flags & EVHTTP_CON_REUSE_CONNECTED_ADDR &&
+               sa &&
+               (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)) {
                int socklen;
                if (sa->sa_family == AF_INET) {
                        socklen = sizeof(struct sockaddr_in);
index 689643ff7b296a946c0dd656b187d4ff7c2de0c0..cdf65ec5d7996c316a6f0d2d65563669c36a5c24 100644 (file)
@@ -636,6 +636,18 @@ struct evhttp_connection *evhttp_connection_base_new(
 void evhttp_connection_set_family(struct evhttp_connection *evcon,
        int family);
 
+#define EVHTTP_CON_REUSE_CONNECTED_ADDR  0x0008  /* reuse connection address on retry */
+/**
+ * Set connection flags.
+ *
+ * @see EVHTTP_CON_*
+ * @return 0 on success, otherwise non zero (for example if flag doesn't
+ * supported).
+ */
+EVENT2_EXPORT_SYMBOL
+int evhttp_connection_set_flags(struct evhttp_connection *evcon,
+       int flags);
+
 /** Takes ownership of the request object
  *
  * Can be used in a request callback to keep onto the request until
index 72aa2dd23b22c4d415ff574586eedd6ce05e50c0..4a025c3c8ef67b556e42067f46b159521b0a0a23 100644 (file)
@@ -3344,6 +3344,8 @@ http_connection_retry_test_impl(void *arg, const char *addr, struct evdns_base *
 
        evcon = evhttp_connection_base_new(data->base, dns_base, addr, port);
        tt_assert(evcon);
+       if (dns_base)
+               tt_assert(!evhttp_connection_set_flags(evcon, EVHTTP_CON_REUSE_CONNECTED_ADDR));
 
        evhttp_connection_set_timeout(evcon, 1);
        /* also bind to local host */