[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] The function list operation of "_evdns_nameserver_add_impl"



On Wed, Dec 21, 2011 at 7:53 AM, wang qin <scpl0000@xxxxxxxxx> wrote:
>
> Dear,
>
> I do not understand of the list operation of the _evdns_nameserver_add_impl.
>
> How to understand this snippet?
>
> Best is figures and notes.
>
>
>
> Thank you very much!
>
>
>        /* insert this nameserver into the list of them */
>        if (!server_head) {
>                ns->next = ns->prev = ns;
>                server_head = ns;
>        } else {
>                ns->next = server_head->next;
>                ns->prev = server_head;
>                server_head->next = ns;
>                if (server_head->prev == server_head) {
>                        server_head->prev = ns;
>                }
>        }

It looks like it's supposed to be a circular doubly linked list to me.
 If the list is empty, then the new nameserver is inserted as the sole
node, and its prev and next pointers are set to itself (to make the
list circular).  But if the list is notempty, we insert the new
nameserver after the current head (server_head).

It looks like there's a possible bug there; I don't see anything that
points ns->next->prev at ns.   If that's so, the best solution here is
probably to replace the whole thing evdns_base.server_head thing with
a CIRCLEQ or such.

(FWIW, this looks like really old code; Libevent 2.0 is the version
folks should be using. Libevent 1.4 is not under active development.)

yrs,
-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.