mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-08 20:07:56 -04:00
Add evhttp_connection_set_family() to set addrinfo->family for DNS requests
This is useful if you want to avoid extra dns requests.
This commit is contained in:
parent
a60632a1ec
commit
12c29b0f6e
@ -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.
|
||||
*
|
||||
|
9
http.c
9
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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user