【发布时间】:2019-09-14 01:19:39
【问题描述】:
我有一段代码使用 websocketpp 来运行服务器。我想确定到达服务器的不同连接。为此,似乎应该使用websocketpp::connection_hdl hdl。
namespace websocketpp {
/// A handle to uniquely identify a connection.
/**
* This type uniquely identifies a connection. It is implemented as a weak
* pointer to the connection in question. This provides uniqueness across
* multiple endpoints and ensures that IDs never conflict or run out.
*
* It is safe to make copies of this handle, store those copies in containers,
* and use them from other threads.
*
* This handle can be upgraded to a full shared_ptr using
* `endpoint::get_con_from_hdl()` from within a handler fired by the connection
* that owns the handler.
*/
typedef lib::weak_ptr<void> connection_hdl;
但正如你所见,这是一个weak_ptr<void>,我不知道如何与其他人进行比较。
我有一张以websocketpp::connection_hdl 作为索引的地图,当我尝试查看是否存在以下索引时:
std::map<websocketpp::connection_hdl, asio::ip::tcp::socket> active_connections;
if (active_connections.count(con->get_socket()) > 0) {}
编译器抱怨:
错误 C2678:二进制“
有什么方法可以从连接中获取套接字(原始整数套接字)。如果可以,我可以将其用作索引并解决问题。
你能找到其他解决方法吗?
【问题讨论】: