From a50f5f0ac05c85daff4f21824df052bcfdb9d5ec Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 1 Jan 2015 06:27:31 +0300 Subject: [PATCH] http: reuse connected address only with EVHTTP_CON_REUSE_CONNECTED_ADDR --- http.c | 18 +++++++++++++++++- include/event2/http.h | 12 ++++++++++++ test/regress_http.c | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/http.c b/http.c index 500e3e2a..f1038f7b 100644 --- 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); diff --git a/include/event2/http.h b/include/event2/http.h index 689643ff..cdf65ec5 100644 --- a/include/event2/http.h +++ b/include/event2/http.h @@ -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 diff --git a/test/regress_http.c b/test/regress_http.c index 72aa2dd2..4a025c3c 100644 --- a/test/regress_http.c +++ b/test/regress_http.c @@ -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 */ -- 2.40.0