|
From: Ignacy G. <sf...@qu...> - 2008-09-05 01:04:20
|
On Thu, Sep 04, 2008 at 10:37:40PM +0200, thus spake Ignacy Gawedzki: > On Thu, Sep 04, 2008 at 08:55:36PM +0200, thus spake P. Durante: > > since the private data is in a reference counted smart pointer > > (Connection::_pvt), delete is called automatically when the last > > Connection referring to that Private data is deallocated > > You know that's funny, because I was about to suggest the use of a smart > pointer, to do just that. I've totally overlooked that it was already a smart > pointer. =) Sorry for the bother then, my bad. Back to the original issue: here's a patch. What this does is basically add a sort of "bound callback" to each connection that is filled during Server::on_new_conn_cb() and provides everything but the Connection::Private pointer for Connection::Private::do_dispatch() to call. The idea is to make the server handle the fact that the connection is disconnected. First "privately" in Server::Private::on_rem_connection() which in turn calls Server::on_rem_connection() using the pointer to the Server's instance that has been bounded in the callback. By the way, is there any good reason for Callback::_cb not to be a reference instead of a pointer? I've also added specialisations in util.h for the case a callback doesn't need any argument. I wrote this for an earlier version that's been changed since, but I decided to leave it there so it won't harm. One last question: wouldn't it be better to avoid linear search during detach_server()? An iterator to the added list element could be kept somewhere in Connection::Private and could be used by Server::Private::on_rem_connection() to remove the element in O(1). Please tell me what you think. Ignacy -- -= Best Viewed Using [INLINE] =- |