mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
move cirular queue removal into its own function
svn:r957
This commit is contained in:
parent
cdf9453af4
commit
1eeb96aa88
45
evdns.c
45
evdns.c
@ -341,6 +341,7 @@ static const int global_nameserver_timeouts_length = sizeof(global_nameserver_ti
|
|||||||
|
|
||||||
static struct nameserver *nameserver_pick(struct evdns_base *base);
|
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_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 void nameserver_ready_callback(evutil_socket_t fd, short events, void *arg);
|
||||||
static int evdns_transmit(struct evdns_base *base);
|
static int evdns_transmit(struct evdns_base *base);
|
||||||
static int evdns_request_transmit(struct evdns_request *req);
|
static int evdns_request_transmit(struct evdns_request *req);
|
||||||
@ -566,16 +567,8 @@ request_trans_id_set(struct evdns_request *const req, const u16 trans_id) {
|
|||||||
static void
|
static void
|
||||||
request_finished(struct evdns_request *const req, struct evdns_request **head) {
|
request_finished(struct evdns_request *const req, struct evdns_request **head) {
|
||||||
struct evdns_base *base = req->base;
|
struct evdns_base *base = req->base;
|
||||||
if (head) {
|
if (head)
|
||||||
if (req->next == req) {
|
evdns_request_remove(req, head);
|
||||||
/* only item in the list */
|
|
||||||
*head = NULL;
|
|
||||||
} else {
|
|
||||||
req->next->prev = req->prev;
|
|
||||||
req->prev->next = req->next;
|
|
||||||
if (*head == req) *head = req->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log(EVDNS_LOG_DEBUG, "Removing timeout for request %lx",
|
log(EVDNS_LOG_DEBUG, "Removing timeout for request %lx",
|
||||||
(unsigned long) req);
|
(unsigned long) req);
|
||||||
@ -633,16 +626,8 @@ evdns_requests_pump_waiting_queue(struct evdns_base *base) {
|
|||||||
struct evdns_request *req;
|
struct evdns_request *req;
|
||||||
/* move a request from the waiting queue to the inflight queue */
|
/* move a request from the waiting queue to the inflight queue */
|
||||||
assert(base->req_waiting_head);
|
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;
|
req = base->req_waiting_head;
|
||||||
base->req_waiting_head = NULL;
|
evdns_request_remove(req, &base->req_waiting_head);
|
||||||
} else {
|
|
||||||
req = base->req_waiting_head;
|
|
||||||
req->next->prev = req->prev;
|
|
||||||
req->prev->next = req->next;
|
|
||||||
base->req_waiting_head = req->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
base->global_requests_waiting--;
|
base->global_requests_waiting--;
|
||||||
base->global_requests_inflight++;
|
base->global_requests_inflight++;
|
||||||
@ -2252,6 +2237,20 @@ evdns_nameserver_ip_add(const char *ip_as_string) {
|
|||||||
return evdns_base_nameserver_ip_add(current_base, ip_as_string);
|
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 */
|
/* insert into the tail of the queue */
|
||||||
static void
|
static void
|
||||||
evdns_request_insert(struct evdns_request *req, struct evdns_request **head) {
|
evdns_request_insert(struct evdns_request *req, struct evdns_request **head) {
|
||||||
@ -2770,13 +2769,7 @@ evdns_base_set_max_requests_inflight(struct evdns_base *base, int maxinflight)
|
|||||||
for (i = 0; i < old_n_heads; ++i) {
|
for (i = 0; i < old_n_heads; ++i) {
|
||||||
while (old_heads[i]) {
|
while (old_heads[i]) {
|
||||||
req = old_heads[i];
|
req = old_heads[i];
|
||||||
if (req->next == req) {
|
evdns_request_remove(req, &old_heads[i]);
|
||||||
old_heads[i] = NULL;
|
|
||||||
} else {
|
|
||||||
old_heads[i] = req->next;
|
|
||||||
req->next->prev = req->prev;
|
|
||||||
req->prev->next = req->next;
|
|
||||||
}
|
|
||||||
evdns_request_insert(req, &new_heads[req->trans_id % n_heads]);
|
evdns_request_insert(req, &new_heads[req->trans_id % n_heads]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user