I am looking for a better way to change Boost Asio HTTP Server 3 Example to maintain a list of currently connected clients.
If I changed server.hpp from the example as:
class server : private boost::noncopyable
{
public:
typedef std::vector< connection_ptr > ConnectionList;
ConnectionList::const_iterator GetClientList() const
{
return connection_list_.begin();
};
void handle_accept(const boost::system::error_code& e)
{
if (!e)
{
connection_list_.push_back( new_connection_ );
new_connection_->start();
}
}
private:
ConnectionList connection_list_;
};
Then I would spoil the connection object's lifetime so that it does not go out of scope and disconnect from the client, since it still contains the link contained in the ConnectionList.
If instead my ConnectionList is defined as typedef std::vector< boost::weak_ptr< connection > > ConnectionList;, then I run the risk of disconnecting the client and folding its pointer while someone is using it from GetClientList().
Anyone have a suggestion for a good and safe way to do this?
Thanks PaulH