static struct nameserver *nameserver_pick(struct evdns_base *base);
static void evdns_request_insert(struct evdns_request *req, struct evdns_request **head);
+static void evdns_request_remove(struct evdns_request *req, struct evdns_request **head);
static void nameserver_ready_callback(evutil_socket_t fd, short events, void *arg);
static int evdns_transmit(struct evdns_base *base);
static int evdns_request_transmit(struct evdns_request *req);
static void
request_finished(struct evdns_request *const req, struct evdns_request **head) {
struct evdns_base *base = req->base;
- if (head) {
- if (req->next == req) {
- /* only item in the list */
- *head = NULL;
- } else {
- req->next->prev = req->prev;
- req->prev->next = req->next;
- if (*head == req) *head = req->next;
- }
- }
+ if (head)
+ evdns_request_remove(req, head);
log(EVDNS_LOG_DEBUG, "Removing timeout for request %lx",
(unsigned long) req);
struct evdns_request *req;
/* move a request from the waiting queue to the inflight queue */
assert(base->req_waiting_head);
- if (base->req_waiting_head->next == base->req_waiting_head) {
- /* only one item in the queue */
- req = base->req_waiting_head;
- base->req_waiting_head = NULL;
- } else {
- req = base->req_waiting_head;
- req->next->prev = req->prev;
- req->prev->next = req->next;
- base->req_waiting_head = req->next;
- }
+ req = base->req_waiting_head;
+ evdns_request_remove(req, &base->req_waiting_head);
base->global_requests_waiting--;
base->global_requests_inflight++;
return evdns_base_nameserver_ip_add(current_base, ip_as_string);
}
+/* remove from the queue */
+static void
+evdns_request_remove(struct evdns_request *req, struct evdns_request **head)
+{
+ if (req->next == req) {
+ /* only item in the list */
+ *head = NULL;
+ } else {
+ req->next->prev = req->prev;
+ req->prev->next = req->next;
+ if (*head == req) *head = req->next;
+ }
+}
+
/* insert into the tail of the queue */
static void
evdns_request_insert(struct evdns_request *req, struct evdns_request **head) {
for (i = 0; i < old_n_heads; ++i) {
while (old_heads[i]) {
req = old_heads[i];
- if (req->next == req) {
- old_heads[i] = NULL;
- } else {
- old_heads[i] = req->next;
- req->next->prev = req->prev;
- req->prev->next = req->next;
- }
+ evdns_request_remove(req, &old_heads[i]);
evdns_request_insert(req, &new_heads[req->trans_id % n_heads]);
}
}