Boost Asio HTTP Server 3 の例を変更して、現在接続されているクライアントのリストを維持する最良の方法を探しています。
例から server.hpp を次のように変更すると:
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_;
};
次に、接続オブジェクトの有効期間を台無しにして、スコープ外に出ないようにして、クライアントから切断します。これは、ConnectionList で参照が維持されているためです。
代わりに、私の ConnectionList が次のようtypedef std::vector< boost::weak_ptr< connection > > ConnectionList;
に定義されている場合、誰かがGetClientList()
.
これを行うための適切で安全な方法について誰か提案がありますか?
ありがとう、ポールH