enum {
RDNS_REQUEST_NEW = 0,
RDNS_REQUEST_REGISTERED = 1,
- RDNS_REQUEST_SENT,
+ RDNS_REQUEST_WAIT_SEND,
+ RDNS_REQUEST_WAIT_REPLY,
RDNS_REQUEST_REPLIED
} state;
HASH_ADD_INT (req->io->requests, id, req);
req->async_event = resolver->async->add_write (resolver->async->data,
fd, req);
+ req->state = RDNS_REQUEST_WAIT_SEND;
}
/*
* If request is already processed then the calling function
/* Fill timeout */
req->async_event = resolver->async->add_timer (resolver->async->data,
req->timeout, req);
- req->state = RDNS_REQUEST_SENT;
+ req->state = RDNS_REQUEST_WAIT_REPLY;
}
return 1;
return true;
}
-static void
-rdns_request_unschedule (struct rdns_request *req)
-{
- if (req->async_event) {
- 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)
{
req->resolver->ups->data);
}
- req->state = RDNS_REQUEST_REPLIED;
rdns_request_unschedule (req);
+ req->state = RDNS_REQUEST_REPLIED;
req->func (rep, req->arg);
REF_RELEASE (req);
}
}
rep = rdns_make_reply (req, RDNS_RC_TIMEOUT);
- req->state = RDNS_REQUEST_REPLIED;
rdns_request_unschedule (req);
+ req->state = RDNS_REQUEST_REPLIED;
req->func (rep, req->arg);
REF_RELEASE (req);
req->async_event);
req->async_event = req->async->add_write (req->async->data,
req->io->sock, req);
- req->state = RDNS_REQUEST_REGISTERED;
+ req->state = RDNS_REQUEST_WAIT_SEND;
}
else if (r == -1) {
if (req->resolver->ups && req->io->srv->ups_elt) {
}
else {
req->async->repeat_timer (req->async->data, req->async_event);
+ req->state = RDNS_REQUEST_WAIT_REPLY;
}
}
/* Retransmit one more time */
req->async_event = req->async->add_write (req->async->data,
fd, req);
- req->state = RDNS_REQUEST_REGISTERED;
+ req->state = RDNS_REQUEST_WAIT_SEND;
}
else if (r == -1) {
if (req->resolver->ups && req->io->srv->ups_elt) {
else {
req->async_event = req->async->add_timer (req->async->data,
req->timeout, req);
- req->state = RDNS_REQUEST_SENT;
+ req->state = RDNS_REQUEST_WAIT_REPLY;
}
}
if (req->reply != NULL) {
rdns_reply_free (req->reply);
}
- 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 */
- req->async->del_write (req->async->data,
- req->async_event);
+ if (req->async_event) {
+ if (req->state == RDNS_REQUEST_WAIT_REPLY) {
+ /* 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_WAIT_SEND) {
+ /* Remove retransmit event */
+ req->async->del_write (req->async->data,
+ req->async_event);
+ }
}
#ifdef TWEETNACL
if (req->curve_plugin_data != NULL) {
return req;
}
+void
+rdns_request_unschedule (struct rdns_request *req)
+{
+ if (req->async_event) {
+ if (req->state == RDNS_REQUEST_WAIT_REPLY) {
+ req->async->del_timer (req->async->data,
+ req->async_event);
+ /* Remove from id hashes */
+ HASH_DEL (req->io->requests, req);
+ req->async_event = NULL;
+ }
+ else if (req->state == RDNS_REQUEST_WAIT_SEND) {
+ req->async->del_write (req->async->data,
+ req->async_event);
+ /* Remove from id hashes */
+ HASH_DEL (req->io->requests, req);
+ req->async_event = NULL;
+ }
+ }
+}
+
void
rdns_request_release (struct rdns_request *req)
{
+ rdns_request_unschedule (req);
REF_RELEASE (req);
}
*/
void rdns_reply_free (struct rdns_reply *rep);
+void rdns_request_unschedule (struct rdns_request *req);
+
#endif /* UTIL_H_ */
struct rspamd_dns_request_ud *reqdata = (struct rspamd_dns_request_ud *)arg;
rdns_request_release (reqdata->req);
+
if (reqdata->pool == NULL) {
g_slice_free1 (sizeof (struct rspamd_dns_request_ud), reqdata);
}