http: use IP address that we got before (if any) during retrying

Before this patch every time we are retrying our request we resolve
domain, but we could optimize this (since UDP is slow) by using cached
conn_address value, so do this.
This commit is contained in:
Azat Khuzhin 2014-11-12 20:23:46 +03:00
parent 8bb3842552
commit 54c887d823

19
http.c
View File

@ -2418,6 +2418,9 @@ int
evhttp_connection_connect_(struct evhttp_connection *evcon) evhttp_connection_connect_(struct evhttp_connection *evcon)
{ {
int old_state = evcon->state; int old_state = evcon->state;
const char *address = evcon->address;
const struct sockaddr *sa = evhttp_connection_get_addr(evcon);
int ret;
if (evcon->state == EVCON_CONNECTING) if (evcon->state == EVCON_CONNECTING)
return (0); return (0);
@ -2458,8 +2461,20 @@ evhttp_connection_connect_(struct evhttp_connection *evcon)
evcon->state = EVCON_CONNECTING; evcon->state = EVCON_CONNECTING;
if (bufferevent_socket_connect_hostname(evcon->bufev, evcon->dns_base, if (sa && (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)) {
evcon->ai_family, evcon->address, evcon->port) < 0) { int socklen;
if (sa->sa_family == AF_INET) {
socklen = sizeof(struct sockaddr_in);
} else if (sa->sa_family == AF_INET6) {
socklen = sizeof(struct sockaddr_in6);
}
ret = bufferevent_socket_connect(evcon->bufev, sa, socklen);
} else {
ret = bufferevent_socket_connect_hostname(evcon->bufev,
evcon->dns_base, evcon->ai_family, address, evcon->port);
}
if (ret < 0) {
evcon->state = old_state; evcon->state = old_state;
event_sock_warn(evcon->fd, "%s: connection to \"%s\" failed", event_sock_warn(evcon->fd, "%s: connection to \"%s\" failed",
__func__, evcon->address); __func__, evcon->address);