KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Currently, I have implemented a singly linked list, like so: struct PeerNode { struct Peer* cargo; struct PeerNode* next; }; ...and I have a struct that contains a couple of these linked lists, like so: struct Torrent { ... struct PeerNode* peer_list; struct PeerNode* unchoked_peers; ... } I would like to replace this by using the macros provided by sys/queue.h . I gather that I could replace my code with something like this: struct Torrent { ... LIST_ENTRY(PeerNode, Peer) peer_list; struct PeerNode* unchoked_peers; ... } Then, from looking at man queue , I believe I would initialize the lists by doing something like this: LIST_INIT(&peer_list); LIST_INIT(unchoked_peers); However, I don't understand how LIST_ENTRY factors into usage of the list. From the man page, it says: "The macro LIST_ENTRY declares a structure that connects the elements in the list," but I don't really understand what this means. Why would I want to declare a structure to connect the elements in the list? Shouldn't each node be connected to the next node via a pointer, like my initial linked list implementation? How would I replace my linked lists with the implementation provided by sys/queue.h ? How would I insert an element into the list?
Tags (comma-separated)
Save Edits
Cancel