1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

async-dns:

This commit is contained in:
Andy Green 2021-02-19 11:31:06 +00:00
parent 14c5b7ebaf
commit b47511352e
7 changed files with 25 additions and 19 deletions

View file

@ -325,12 +325,15 @@ solo:
n = lws_getaddrinfo46(wsi, ads, &result);
}
#else
lwsi_set_state(wsi, LRS_WAITING_DNS);
/* this is either FAILED, CONTINUING, or already called connect_4 */
n = lws_async_dns_query(wsi->a.context, wsi->tsi, ads,
LWS_ADNS_RECORD_A, lws_client_connect_3_connect,
wsi, NULL);
lwsl_notice("%s: %s: post async dns, state 0x%x\n",
__func__, lws_wsi_tag(wsi), lwsi_state(wsi));
if (n == LADNS_RET_FAILED_WSI_CLOSED)
return NULL;

View file

@ -1093,8 +1093,6 @@ __lws_vhost_destroy_pt_wsi_dieback_start(struct lws_vhost *vh)
return;
#endif
lwsl_info("%s: %s\n", __func__, vh->name);
#if defined(LWS_WITH_CLIENT)
/*
* destroy any wsi that are associated with us but have no socket
@ -1261,7 +1259,7 @@ __lws_vhost_destroy2(struct lws_vhost *vh)
vh->being_destroyed = 0;
lwsl_info("%s: %s\n", __func__, vh->name);
// lwsl_info("%s: %s\n", __func__, vh->name);
#if defined(LWS_WITH_DEPRECATED_THINGS)
/*

View file

@ -207,8 +207,12 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason,
case LWSSSSRET_OK:
break;
case LWSSSSRET_DISCONNECT_ME:
lwsl_notice("%s: proxlicent RX ended with DISCONNECT_ME\n",
__func__);
return -1;
case LWSSSSRET_DESTROY_ME:
lwsl_notice("%s: proxlicent RX ended with DESTROY_ME\n",
__func__);
lws_set_opaque_user_data(wsi, NULL);
lws_sspc_destroy(&h);
return -1;

View file

@ -484,6 +484,7 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
break;
case LWS_CALLBACK_RAW_WRITEABLE:
lwsl_debug("%s: %s: LWS_CALLBACK_RAW_WRITEABLE, state 0x%x\n",
__func__, lws_wsi_tag(wsi), lwsi_state(wsi));

View file

@ -611,8 +611,8 @@ lws_adns_parse_udp(lws_async_dns_t *dns, const uint8_t *pkt, size_t len)
memset(c, 0, sizeof(*c));
/* place it at end, no need to care about alignment padding */
adst.name = ((const char *)c) + est - n;
memcpy((char *)adst.name, nm, (unsigned int)n);
c->name = adst.name = ((const char *)c) + est - n;
memcpy((char *)c->name, nm, (unsigned int)n);
/*
* Then walk the packet again, placing the objects we accounted for
@ -656,7 +656,7 @@ lws_adns_parse_udp(lws_async_dns_t *dns, const uint8_t *pkt, size_t len)
} else {
q->firstcache = c;
c->incomplete = q->responded != q->asked;
c->incomplete = !q->responded;// != q->asked;
/*
* Only register the first one into the cache...

View file

@ -386,14 +386,19 @@ lws_adns_cache_t *
lws_adns_get_cache(lws_async_dns_t *dns, const char *name)
{
lws_adns_cache_t *c;
const char *cn;
if (!name) {
assert(0);
return NULL;
}
lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1,
lws_dll2_get_head(&dns->cached)) {
c = lws_container_of(d, lws_adns_cache_t, list);
cn = lws_adns_cache_to_name(c);
if (name && !c->incomplete && !strcasecmp(name, cn)) {
lwsl_notice("%s vs %s (inc %d)\n", name, c->name, c->incomplete);
if (!c->incomplete && !strcasecmp(name, c->name)) {
/* Keep sorted by LRU: move to the head */
lws_dll2_remove(&c->list);
lws_dll2_add_head(&c->list, &dns->cached);
@ -410,7 +415,6 @@ void
lws_adns_dump(lws_async_dns_t *dns)
{
lws_adns_cache_t *c;
const char *cn;
if (!dns)
return;
@ -421,10 +425,9 @@ lws_adns_dump(lws_async_dns_t *dns)
lws_start_foreach_dll(struct lws_dll2 *, d,
lws_dll2_get_head(&dns->cached)) {
c = lws_container_of(d, lws_adns_cache_t, list);
cn = lws_adns_cache_to_name(c);
lwsl_info("%s: cache: '%s', exp: %lldus, incomp %d, "
"fl 0x%x, refc %d, res %p\n", __func__, cn,
"fl 0x%x, refc %d, res %p\n", __func__, c->name,
(long long)(c->sul.us - lws_now_usecs()),
c->incomplete, c->flags, c->refcount, c->results);
} lws_end_foreach_dll(d);
@ -733,7 +736,8 @@ lws_async_dns_query(struct lws_context *context, int tsi, const char *name,
sa46 = (lws_sockaddr46 *)&ai[1];
ai->ai_socktype = SOCK_STREAM;
memcpy(&sa46[1], name, nlen + 1);
c->name = (const char *)&sa46[1];
memcpy((char *)c->name, name, nlen + 1);
ai->ai_canonname = (char *)&sa46[1];
c->results = ai;

View file

@ -42,17 +42,13 @@ typedef struct lws_adns_cache {
struct lws_adns_cache *firstcache;
struct lws_adns_cache *chain;
struct addrinfo *results;
const char *name;
uint8_t flags; /* b0 = has ipv4, b1 = has ipv6 */
char refcount;
char incomplete;
/* addrinfo, lws_sa46, then name overallocated here */
} lws_adns_cache_t;
#define lws_adns_cache_to_name(_a) (((const char *)_a) + \
sizeof(lws_adns_cache_t) + \
sizeof(struct addrinfo) + \
sizeof(lws_sockaddr46))
/*
* these objects are used while a query is ongoing...
*/