mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
http: reuse connected address only with EVHTTP_CON_REUSE_CONNECTED_ADDR
This commit is contained in:
parent
eedbeff368
commit
a50f5f0ac0
18
http.c
18
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);
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user