mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-14 06:49:35 -04:00
evdns: export cancel via callbacks in util (like async lib core/extra issues)
This commit is contained in:
parent
334340da51
commit
8cbe65d5f4
1
evdns.c
1
evdns.c
@ -3908,6 +3908,7 @@ evdns_base_new(struct event_base *event_base, int flags)
|
|||||||
* functionality. We can't just call evdns_getaddrinfo directly or
|
* functionality. We can't just call evdns_getaddrinfo directly or
|
||||||
* else libevent-core will depend on libevent-extras. */
|
* else libevent-core will depend on libevent-extras. */
|
||||||
evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo);
|
evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo);
|
||||||
|
evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel);
|
||||||
|
|
||||||
base = mm_malloc(sizeof(struct evdns_base));
|
base = mm_malloc(sizeof(struct evdns_base));
|
||||||
if (base == NULL)
|
if (base == NULL)
|
||||||
|
22
evutil.c
22
evutil.c
@ -1546,6 +1546,7 @@ evutil_freeaddrinfo(struct evutil_addrinfo *ai)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static evdns_getaddrinfo_fn evdns_getaddrinfo_impl = NULL;
|
static evdns_getaddrinfo_fn evdns_getaddrinfo_impl = NULL;
|
||||||
|
static evdns_getaddrinfo_cancel_fn evdns_getaddrinfo_cancel_impl = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn)
|
evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn)
|
||||||
@ -1553,27 +1554,40 @@ evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn)
|
|||||||
if (!evdns_getaddrinfo_impl)
|
if (!evdns_getaddrinfo_impl)
|
||||||
evdns_getaddrinfo_impl = fn;
|
evdns_getaddrinfo_impl = fn;
|
||||||
}
|
}
|
||||||
|
void
|
||||||
|
evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn)
|
||||||
|
{
|
||||||
|
if (!evdns_getaddrinfo_cancel_impl)
|
||||||
|
evdns_getaddrinfo_cancel_impl = fn;
|
||||||
|
}
|
||||||
|
|
||||||
/* Internal helper function: act like evdns_getaddrinfo if dns_base is set;
|
/* Internal helper function: act like evdns_getaddrinfo if dns_base is set;
|
||||||
* otherwise do a blocking resolve and pass the result to the callback in the
|
* otherwise do a blocking resolve and pass the result to the callback in the
|
||||||
* way that evdns_getaddrinfo would.
|
* way that evdns_getaddrinfo would.
|
||||||
*/
|
*/
|
||||||
int
|
struct evdns_getaddrinfo_request *evutil_getaddrinfo_async_(
|
||||||
evutil_getaddrinfo_async_(struct evdns_base *dns_base,
|
struct evdns_base *dns_base,
|
||||||
const char *nodename, const char *servname,
|
const char *nodename, const char *servname,
|
||||||
const struct evutil_addrinfo *hints_in,
|
const struct evutil_addrinfo *hints_in,
|
||||||
void (*cb)(int, struct evutil_addrinfo *, void *), void *arg)
|
void (*cb)(int, struct evutil_addrinfo *, void *), void *arg)
|
||||||
{
|
{
|
||||||
if (dns_base && evdns_getaddrinfo_impl) {
|
if (dns_base && evdns_getaddrinfo_impl) {
|
||||||
evdns_getaddrinfo_impl(
|
return evdns_getaddrinfo_impl(
|
||||||
dns_base, nodename, servname, hints_in, cb, arg);
|
dns_base, nodename, servname, hints_in, cb, arg);
|
||||||
} else {
|
} else {
|
||||||
struct evutil_addrinfo *ai=NULL;
|
struct evutil_addrinfo *ai=NULL;
|
||||||
int err;
|
int err;
|
||||||
err = evutil_getaddrinfo(nodename, servname, hints_in, &ai);
|
err = evutil_getaddrinfo(nodename, servname, hints_in, &ai);
|
||||||
cb(err, ai, arg);
|
cb(err, ai, arg);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request *data)
|
||||||
|
{
|
||||||
|
if (evdns_getaddrinfo_cancel_impl && data) {
|
||||||
|
evdns_getaddrinfo_cancel_impl(data);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -357,8 +357,10 @@ typedef struct evdns_getaddrinfo_request* (*evdns_getaddrinfo_fn)(
|
|||||||
const char *nodename, const char *servname,
|
const char *nodename, const char *servname,
|
||||||
const struct evutil_addrinfo *hints_in,
|
const struct evutil_addrinfo *hints_in,
|
||||||
void (*cb)(int, struct evutil_addrinfo *, void *), void *arg);
|
void (*cb)(int, struct evutil_addrinfo *, void *), void *arg);
|
||||||
|
|
||||||
void evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn);
|
void evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn);
|
||||||
|
typedef void (*evdns_getaddrinfo_cancel_fn)(
|
||||||
|
struct evdns_getaddrinfo_request *req);
|
||||||
|
void evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn);
|
||||||
|
|
||||||
struct evutil_addrinfo *evutil_new_addrinfo_(struct sockaddr *sa,
|
struct evutil_addrinfo *evutil_new_addrinfo_(struct sockaddr *sa,
|
||||||
ev_socklen_t socklen, const struct evutil_addrinfo *hints);
|
ev_socklen_t socklen, const struct evutil_addrinfo *hints);
|
||||||
@ -368,10 +370,12 @@ void evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo *hints);
|
|||||||
int evutil_getaddrinfo_common_(const char *nodename, const char *servname,
|
int evutil_getaddrinfo_common_(const char *nodename, const char *servname,
|
||||||
struct evutil_addrinfo *hints, struct evutil_addrinfo **res, int *portnum);
|
struct evutil_addrinfo *hints, struct evutil_addrinfo **res, int *portnum);
|
||||||
|
|
||||||
int evutil_getaddrinfo_async_(struct evdns_base *dns_base,
|
struct evdns_getaddrinfo_request *evutil_getaddrinfo_async_(
|
||||||
|
struct evdns_base *dns_base,
|
||||||
const char *nodename, const char *servname,
|
const char *nodename, const char *servname,
|
||||||
const struct evutil_addrinfo *hints_in,
|
const struct evutil_addrinfo *hints_in,
|
||||||
void (*cb)(int, struct evutil_addrinfo *, void *), void *arg);
|
void (*cb)(int, struct evutil_addrinfo *, void *), void *arg);
|
||||||
|
void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request *data);
|
||||||
|
|
||||||
/** Return true iff sa is a looback address. (That is, it is 127.0.0.1/8, or
|
/** Return true iff sa is a looback address. (That is, it is 127.0.0.1/8, or
|
||||||
* ::1). */
|
* ::1). */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user