sd-dns: coding style cleanup
This commit is contained in:
parent
f3621dec52
commit
8e50b5a77c
|
@ -229,7 +229,8 @@ static int send_addrinfo_reply(int out_fd, unsigned id, int ret, struct addrinfo
|
||||||
struct addrinfo *k;
|
struct addrinfo *k;
|
||||||
|
|
||||||
for (k = ai; k; k = k->ai_next) {
|
for (k = ai; k; k = k->ai_next) {
|
||||||
if (!(p = serialize_addrinfo(p, k, &resp->header.length, (char*) data + BUFSIZE - (char*) p))) {
|
p = serialize_addrinfo(p, k, &resp->header.length, (char*) data + BUFSIZE - (char*) p);
|
||||||
|
if (!p) {
|
||||||
resp->ret = EAI_MEMORY;
|
resp->ret = EAI_MEMORY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -457,8 +458,8 @@ asyncns_t* asyncns_new(unsigned n_proc) {
|
||||||
|
|
||||||
for (asyncns->valid_workers = 0; asyncns->valid_workers < n_proc; asyncns->valid_workers++) {
|
for (asyncns->valid_workers = 0; asyncns->valid_workers < n_proc; asyncns->valid_workers++) {
|
||||||
int r;
|
int r;
|
||||||
|
r = pthread_create(&asyncns->workers[asyncns->valid_workers], NULL, thread_worker, asyncns);
|
||||||
if ((r = pthread_create(&asyncns->workers[asyncns->valid_workers], NULL, thread_worker, asyncns)) != 0) {
|
if (r) {
|
||||||
errno = r;
|
errno = r;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -532,7 +533,8 @@ static asyncns_query_t *lookup_query(asyncns_t *asyncns, unsigned id) {
|
||||||
asyncns_query_t *q;
|
asyncns_query_t *q;
|
||||||
assert(asyncns);
|
assert(asyncns);
|
||||||
|
|
||||||
if ((q = asyncns->queries[id % MAX_QUERIES]))
|
q = asyncns->queries[id % MAX_QUERIES];
|
||||||
|
if (q)
|
||||||
if (q->id == id)
|
if (q->id == id)
|
||||||
return q;
|
return q;
|
||||||
|
|
||||||
|
@ -572,7 +574,8 @@ static const void *unserialize_addrinfo(const void *p, struct addrinfo **ret_ai,
|
||||||
if (*length < l)
|
if (*length < l)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(ai = malloc(sizeof(struct addrinfo))))
|
ai = malloc(sizeof(struct addrinfo));
|
||||||
|
if (!ai)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
ai->ai_addr = NULL;
|
ai->ai_addr = NULL;
|
||||||
|
@ -626,7 +629,8 @@ static int handle_response(asyncns_t *asyncns, const packet_t *packet, size_t le
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(q = lookup_query(asyncns, resp->id)))
|
q = lookup_query(asyncns, resp->id);
|
||||||
|
if (!q)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (resp->type) {
|
switch (resp->type) {
|
||||||
|
@ -730,7 +734,8 @@ int asyncns_wait(asyncns_t *asyncns, int block) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((l = recv(asyncns->fds[RESPONSE_RECV_FD], buf, sizeof(buf), 0)) < 0)) {
|
l = recv(asyncns->fds[RESPONSE_RECV_FD], buf, sizeof(buf), 0);
|
||||||
|
if (l < 0) {
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
|
|
||||||
if (errno != EAGAIN)
|
if (errno != EAGAIN)
|
||||||
|
@ -765,7 +770,6 @@ static asyncns_query_t *alloc_query(asyncns_t *asyncns) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (asyncns->queries[asyncns->current_index]) {
|
while (asyncns->queries[asyncns->current_index]) {
|
||||||
|
|
||||||
asyncns->current_index++;
|
asyncns->current_index++;
|
||||||
asyncns->current_id++;
|
asyncns->current_id++;
|
||||||
|
|
||||||
|
@ -773,7 +777,8 @@ static asyncns_query_t *alloc_query(asyncns_t *asyncns) {
|
||||||
asyncns->current_index -= MAX_QUERIES;
|
asyncns->current_index -= MAX_QUERIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(q = asyncns->queries[asyncns->current_index] = malloc(sizeof(asyncns_query_t)))) {
|
q = asyncns->queries[asyncns->current_index] = malloc(sizeof(asyncns_query_t));
|
||||||
|
if (!q) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -806,10 +811,10 @@ asyncns_query_t* asyncns_getaddrinfo(asyncns_t *asyncns, const char *node, const
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(q = alloc_query(asyncns)))
|
q = alloc_query(asyncns);
|
||||||
|
if (!q)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
req->node_len = node ? strlen(node)+1 : 0;
|
req->node_len = node ? strlen(node)+1 : 0;
|
||||||
req->service_len = service ? strlen(service)+1 : 0;
|
req->service_len = service ? strlen(service)+1 : 0;
|
||||||
|
|
||||||
|
@ -892,10 +897,10 @@ asyncns_query_t* asyncns_getnameinfo(asyncns_t *asyncns, const struct sockaddr *
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(q = alloc_query(asyncns)))
|
q = alloc_query(asyncns);
|
||||||
|
if (!q)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
req->header.id = q->id;
|
req->header.id = q->id;
|
||||||
req->header.type = q->type = REQUEST_NAMEINFO;
|
req->header.type = q->type = REQUEST_NAMEINFO;
|
||||||
req->header.length = sizeof(nameinfo_request_t) + salen;
|
req->header.length = sizeof(nameinfo_request_t) + salen;
|
||||||
|
@ -977,7 +982,8 @@ static asyncns_query_t * asyncns_res(asyncns_t *asyncns, query_type_t qtype, con
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(q = alloc_query(asyncns)))
|
q = alloc_query(asyncns);
|
||||||
|
if (!q)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
req->dname_len = strlen(dname) + 1;
|
req->dname_len = strlen(dname) + 1;
|
||||||
|
|
|
@ -56,7 +56,6 @@ int main(int argc, char *argv[]) {
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
q1 = asyncns_getaddrinfo(asyncns, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints);
|
q1 = asyncns_getaddrinfo(asyncns, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints);
|
||||||
|
|
||||||
if (!q1)
|
if (!q1)
|
||||||
fprintf(stderr, "asyncns_getaddrinfo(): %s\n", strerror(errno));
|
fprintf(stderr, "asyncns_getaddrinfo(): %s\n", strerror(errno));
|
||||||
|
|
||||||
|
@ -66,27 +65,25 @@ int main(int argc, char *argv[]) {
|
||||||
sa.sin_port = htons(80);
|
sa.sin_port = htons(80);
|
||||||
|
|
||||||
q2 = asyncns_getnameinfo(asyncns, (struct sockaddr*) &sa, sizeof(sa), 0, 1, 1);
|
q2 = asyncns_getnameinfo(asyncns, (struct sockaddr*) &sa, sizeof(sa), 0, 1, 1);
|
||||||
|
|
||||||
if (!q2)
|
if (!q2)
|
||||||
fprintf(stderr, "asyncns_getnameinfo(): %s\n", strerror(errno));
|
fprintf(stderr, "asyncns_getnameinfo(): %s\n", strerror(errno));
|
||||||
|
|
||||||
/* Make a res_query() call */
|
/* Make a res_query() call */
|
||||||
q3 = asyncns_res_query(asyncns, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV);
|
q3 = asyncns_res_query(asyncns, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV);
|
||||||
|
|
||||||
if (!q3)
|
if (!q3)
|
||||||
fprintf(stderr, "asyncns_res_query(): %s\n", strerror(errno));
|
fprintf(stderr, "asyncns_res_query(): %s\n", strerror(errno));
|
||||||
|
|
||||||
/* Wait until the three queries are completed */
|
/* Wait until the three queries are completed */
|
||||||
while (!asyncns_isdone(asyncns, q1)
|
while (!asyncns_isdone(asyncns, q1) ||
|
||||||
|| !asyncns_isdone(asyncns, q2)
|
!asyncns_isdone(asyncns, q2) ||
|
||||||
|| !asyncns_isdone(asyncns, q3)) {
|
!asyncns_isdone(asyncns, q3)) {
|
||||||
if (asyncns_wait(asyncns, 1) < 0) {
|
if (asyncns_wait(asyncns, 1) < 0)
|
||||||
fprintf(stderr, "asyncns_wait(): %s\n", strerror(errno));
|
fprintf(stderr, "asyncns_wait(): %s\n", strerror(errno));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Interpret the result of the name -> addr query */
|
/* Interpret the result of the name -> addr query */
|
||||||
if ((ret = asyncns_getaddrinfo_done(asyncns, q1, &ai)))
|
ret = asyncns_getaddrinfo_done(asyncns, q1, &ai);
|
||||||
|
if (ret)
|
||||||
fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret);
|
fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret);
|
||||||
else {
|
else {
|
||||||
struct addrinfo *i;
|
struct addrinfo *i;
|
||||||
|
@ -105,13 +102,15 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Interpret the result of the addr -> name query */
|
/* Interpret the result of the addr -> name query */
|
||||||
if ((ret = asyncns_getnameinfo_done(asyncns, q2, host, sizeof(host), serv, sizeof(serv))))
|
ret = asyncns_getnameinfo_done(asyncns, q2, host, sizeof(host), serv, sizeof(serv));
|
||||||
|
if (ret)
|
||||||
fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret);
|
fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret);
|
||||||
else
|
else
|
||||||
printf("%s -- %s\n", host, serv);
|
printf("%s -- %s\n", host, serv);
|
||||||
|
|
||||||
/* Interpret the result of the SRV lookup */
|
/* Interpret the result of the SRV lookup */
|
||||||
if ((ret = asyncns_res_done(asyncns, q3, &srv)) < 0) {
|
ret = asyncns_res_done(asyncns, q3, &srv);
|
||||||
|
if (ret < 0) {
|
||||||
fprintf(stderr, "error: %s %i\n", strerror(errno), ret);
|
fprintf(stderr, "error: %s %i\n", strerror(errno), ret);
|
||||||
} else if (ret == 0) {
|
} else if (ret == 0) {
|
||||||
fprintf(stderr, "No reply for SRV lookup\n");
|
fprintf(stderr, "No reply for SRV lookup\n");
|
||||||
|
|
Loading…
Reference in a new issue