Hi, Nick, Thanks for your reply. It's very helpful.
Thanks and Regards, Wenliang On Thu, Feb 9, 2012 at 12:12 AM, Nick Mathewson <ni...@freehaven.net> wrote: > On Wed, Feb 8, 2012 at 5:37 AM, Wenliang Zhang <wla...@gmail.com> wrote: > > Hi, all, > > Personally, my first approach would be to do it with something closer > to a reference count: in the data associated with each bufferevent, > remember the number of messages it has outstanding, and don't actually > free the bufferevent until it has received a close _and_ it has no > messages waiting. > > Alternatively, you could use a weak-reference style system where > instead of having a pointer to the bufferevent, each Message would get > a pointer to a a "weak reference" object that either had a pointer to > the bufferevent, or a NULL pointer to indicate that the bufferevent > had gone away. You'd free these objects once the bufferevent had no > more outstanding messages. > > Or you could keep a linked list of messages for each bufferevent, and, > when about to free the bufferevent, first cancel each message or mark > it as having to bufferevent to send to. > > There are probably other ways too. > > hth, > -- > Nick > *********************************************************************** > To unsubscribe, send an e-mail to majord...@freehaven.net with > unsubscribe libevent-users in the body. >