Skip to content

Commit

Permalink
Tune references logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Feb 13, 2014
1 parent 5325e87 commit ebf6eba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
20 changes: 16 additions & 4 deletions src/resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req,
return true;
}

static void
rdns_request_unschedule (struct rdns_request *req)
{
req->async->del_timer (req->async->data,
req->async_event);
/* Remove from id hashes */
HASH_DEL (req->io->requests, req);
}

void
rdns_process_read (int fd, void *arg)
{
Expand Down Expand Up @@ -268,7 +277,8 @@ rdns_process_read (int fd, void *arg)
if (req != NULL) {
if (rdns_parse_reply (in, r, req, &rep)) {
UPSTREAM_OK (req->io->srv);
REF_RETAIN (req);
req->state = RDNS_REQUEST_REPLIED;
rdns_request_unschedule (req);
req->func (rep, req->arg);
REF_RELEASE (req);
}
Expand All @@ -289,7 +299,8 @@ rdns_process_timer (void *arg)
if (req->retransmits == 0) {
UPSTREAM_FAIL (req->io->srv, time (NULL));
rep = rdns_make_reply (req, DNS_RC_TIMEOUT);
REF_RETAIN (req);
req->state = RDNS_REQUEST_REPLIED;
rdns_request_unschedule (req);
req->func (rep, req->arg);
REF_RELEASE (req);

Expand All @@ -308,7 +319,8 @@ rdns_process_timer (void *arg)
else if (r == -1) {
UPSTREAM_FAIL (req->io->srv, time (NULL));
rep = rdns_make_reply (req, DNS_RC_NETERR);
REF_RETAIN (req);
req->state = RDNS_REQUEST_REPLIED;
rdns_request_unschedule (req);
req->func (rep, req->arg);
REF_RELEASE (req);
}
Expand Down Expand Up @@ -349,7 +361,7 @@ rdns_process_retransmit (int fd, void *arg)
else if (r == -1) {
UPSTREAM_FAIL (req->io->srv, time (NULL));
rep = rdns_make_reply (req, DNS_RC_NETERR);
REF_RETAIN (req);
req->state = RDNS_REQUEST_REPLIED;
req->func (rep, req->arg);
REF_RELEASE (req);
}
Expand Down
7 changes: 4 additions & 3 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,13 @@ rdns_request_free (struct rdns_request *req)
if (req->reply != NULL) {
rdns_reply_free (req->reply);
}
if (req->state >= RDNS_REQUEST_SENT) {
if (req->state >= RDNS_REQUEST_SENT &&
req->state < RDNS_REQUEST_REPLIED) {
/* Remove timer */
req->async->del_timer (req->async->data,
req->async_event);
/* Remove from id hashes */
HASH_DEL (req->io->requests, req);
}
else if (req->state == RDNS_REQUEST_REGISTERED) {
/* Remove retransmit event */
Expand All @@ -310,8 +313,6 @@ rdns_request_free (struct rdns_request *req)
}
#endif
if (req->io != NULL && req->state > RDNS_REQUEST_NEW) {
/* Remove from id hashes */
HASH_DEL (req->io->requests, req);
REF_RELEASE (req->io);
REF_RELEASE (req->resolver);
}
Expand Down
1 change: 0 additions & 1 deletion test/dns_curve.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ static void
rdns_regress_callback (struct rdns_reply *reply, void *arg)
{
printf ("got result for host: %s\n", (const char *)arg);
rdns_request_release (reply->request);

if (--remain_tests == 0) {
rdns_resolver_release (reply->resolver);
Expand Down
1 change: 0 additions & 1 deletion test/dns_regress.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ static void
rdns_regress_callback (struct rdns_reply *reply, void *arg)
{
printf ("got result for host: %s\n", (const char *)arg);
rdns_request_release (reply->request);

if (--remain_tests == 0) {
rdns_resolver_release (reply->resolver);
Expand Down

0 comments on commit ebf6eba

Please sign in to comment.