|
|
@@ -11,7 +11,7 @@ struct ai_ctx { |
|
|
|
void *arg; |
|
|
|
int cancel; |
|
|
|
int error; |
|
|
|
short port; |
|
|
|
uint16_t port; |
|
|
|
}; |
|
|
|
|
|
|
|
BTPDQ_HEAD(ai_ctx_tq, ai_ctx); |
|
|
@@ -21,7 +21,7 @@ static pthread_mutex_t m_aiq_lock; |
|
|
|
static pthread_cond_t m_aiq_cond; |
|
|
|
|
|
|
|
struct ai_ctx * |
|
|
|
btpd_addrinfo(const char *node, short port, struct addrinfo *hints, |
|
|
|
btpd_addrinfo(const char *node, uint16_t port, struct addrinfo *hints, |
|
|
|
void (*cb)(void *, int, struct addrinfo *), void *arg) |
|
|
|
{ |
|
|
|
struct ai_ctx *ctx = btpd_calloc(1, sizeof(*ctx)); |
|
|
@@ -30,8 +30,7 @@ btpd_addrinfo(const char *node, short port, struct addrinfo *hints, |
|
|
|
ctx->arg = arg; |
|
|
|
snprintf(ctx->node, sizeof(ctx->node), "%s", node); |
|
|
|
ctx->port = port; |
|
|
|
if (port > 0) |
|
|
|
snprintf(ctx->service, sizeof(ctx->service), "%hd", port); |
|
|
|
snprintf(ctx->service, sizeof(ctx->service), "%hu", port); |
|
|
|
|
|
|
|
pthread_mutex_lock(&m_aiq_lock); |
|
|
|
BTPDQ_INSERT_TAIL(&m_aiq, ctx, entry); |
|
|
@@ -62,7 +61,6 @@ static void * |
|
|
|
addrinfo_td(void *arg) |
|
|
|
{ |
|
|
|
struct ai_ctx *ctx; |
|
|
|
char *service; |
|
|
|
while (1) { |
|
|
|
pthread_mutex_lock(&m_aiq_lock); |
|
|
|
while (BTPDQ_EMPTY(&m_aiq)) |
|
|
@@ -71,8 +69,8 @@ addrinfo_td(void *arg) |
|
|
|
BTPDQ_REMOVE(&m_aiq, ctx, entry); |
|
|
|
pthread_mutex_unlock(&m_aiq_lock); |
|
|
|
|
|
|
|
service = ctx->port > 0 ? ctx->service : NULL; |
|
|
|
ctx->error = getaddrinfo(ctx->node, service, &ctx->hints, &ctx->res); |
|
|
|
ctx->error = |
|
|
|
getaddrinfo(ctx->node, ctx->service, &ctx->hints, &ctx->res); |
|
|
|
|
|
|
|
td_post_begin(); |
|
|
|
td_post(addrinfo_td_cb, ctx); |
|
|
|