37 : m_localEndpoint(localEndpoint)
38 , m_pingInterval(10_s)
44 m_server.clear_access_channels(websocketpp::log::alevel::all);
45 m_server.clear_error_channels(websocketpp::log::elevel::all);
49 m_server.set_open_handler(bind(&WebSocketChannel::handleOpen,
this, _1));
50 m_server.set_close_handler(bind(&WebSocketChannel::handleClose,
this, _1));
51 m_server.set_message_handler(bind(&WebSocketChannel::handleMessage,
this, _1, _2));
54 m_server.set_pong_handler(bind(&WebSocketChannel::handlePong,
this, _1));
55 m_server.set_pong_timeout_handler(bind(&WebSocketChannel::handlePongTimeout,
this, _1));
58 m_server.set_reuse_addr(
true);
62 WebSocketChannel::setPingInterval(time::milliseconds interval)
64 BOOST_ASSERT(!m_server.is_listening());
66 m_pingInterval = interval;
70 WebSocketChannel::setPongTimeout(time::milliseconds timeout)
72 BOOST_ASSERT(!m_server.is_listening());
74 m_server.set_pong_timeout(static_cast<long>(timeout.count()));
78 WebSocketChannel::handlePongTimeout(websocketpp::connection_hdl hdl)
80 auto it = m_channelFaces.find(hdl);
81 if (it != m_channelFaces.end()) {
90 WebSocketChannel::handlePong(websocketpp::connection_hdl hdl)
92 auto it = m_channelFaces.find(hdl);
93 if (it != m_channelFaces.end()) {
102 WebSocketChannel::handleMessage(websocketpp::connection_hdl hdl,
103 websocket::Server::message_ptr msg)
105 auto it = m_channelFaces.find(hdl);
106 if (it != m_channelFaces.end()) {
107 static_cast<WebSocketTransport*
>(it->second->getTransport())->receiveMessage(msg->get_payload());
115 WebSocketChannel::handleOpen(websocketpp::connection_hdl hdl)
117 NFD_LOG_CHAN_TRACE(
"Incoming connection from " << m_server.get_con_from_hdl(hdl)->get_remote_endpoint());
119 auto linkService = make_unique<GenericLinkService>();
120 auto transport = make_unique<WebSocketTransport>(hdl, ref(m_server), m_pingInterval);
121 auto face = make_shared<Face>(std::move(linkService), std::move(transport));
123 BOOST_ASSERT(m_channelFaces.count(hdl) == 0);
124 m_channelFaces[hdl] =
face;
127 m_onFaceCreatedCallback(
face);
131 WebSocketChannel::handleClose(websocketpp::connection_hdl hdl)
133 auto it = m_channelFaces.find(hdl);
134 if (it != m_channelFaces.end()) {
150 m_onFaceCreatedCallback = onFaceCreated;
152 m_server.listen(m_localEndpoint);
153 m_server.start_accept();
void listen(const FaceCreatedCallback &onFaceCreated)
Enable listening on the local endpoint, accept connections, and create faces when remote host makes a...
void setUri(const FaceUri &uri)
detail::SimulatorIo & getGlobalIoService()
std::function< void(const shared_ptr< Face > &face)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the face is closed
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
WebSocketChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket channel for the local endpoint.
Copyright (c) 2011-2015 Regents of the University of California.
#define NFD_LOG_CHAN_INFO(msg)
Log a message at INFO level.
#define NFD_LOG_CHAN_TRACE(msg)
Log a message at TRACE level.
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
represents the underlying protocol and address used by a Face
bool isListening() const override
Returns whether the channel is listening.
boost::asio::ip::tcp::endpoint Endpoint
#define NFD_LOG_INIT(name)