38 : m_localEndpoint(localEndpoint)
39 , m_pingInterval(10_s)
50 m_server.set_tcp_pre_bind_handler([isV6 = m_localEndpoint.address().is_v6()] (
const auto& acceptor) {
52 acceptor->set_option(boost::asio::ip::v6_only(
true));
54 return websocketpp::lib::error_code{};
56 m_server.
set_open_handler(std::bind(&WebSocketChannel::handleOpen,
this, _1));
65 m_server.set_reuse_addr(
true);
71 BOOST_ASSERT(!m_server.is_listening());
73 m_pingInterval = interval;
79 BOOST_ASSERT(!m_server.is_listening());
87 auto it = m_channelFaces.find(hdl);
88 if (it != m_channelFaces.end()) {
99 auto it = m_channelFaces.find(hdl);
100 if (it != m_channelFaces.end()) {
112 auto it = m_channelFaces.find(hdl);
113 if (it != m_channelFaces.end()) {
114 static_cast<WebSocketTransport*
>(it->second->getTransport())->receiveMessage(msg->get_payload());
126 auto linkService = make_unique<GenericLinkService>();
127 auto transport = make_unique<WebSocketTransport>(hdl, m_server, m_pingInterval);
129 face->setChannel(shared_from_this());
131 BOOST_ASSERT(m_channelFaces.count(hdl) == 0);
132 m_channelFaces[hdl] = face;
135 m_onFaceCreatedCallback(face);
141 auto it = m_channelFaces.find(hdl);
142 if (it != m_channelFaces.end()) {
158 m_onFaceCreatedCallback = onFaceCreated;
160 m_server.listen(m_localEndpoint);
static level const all
Special aggregate value representing "all levels".
void listen(const FaceCreatedCallback &onFaceCreated)
Enable listening on the local endpoint, accept connections, and create faces when remote host makes a...
void set_pong_timeout_handler(pong_timeout_handler h)
void handlePong(websocketpp::connection_hdl hdl)
void setUri(const FaceUri &uri)
#define NFD_LOG_INIT(name)
void set_open_handler(open_handler h)
Class implementing WebSocket-based channel to create faces.
void setPongTimeout(time::milliseconds timeout)
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
void set_close_handler(close_handler h)
void connectFaceClosedSignal(Face &face, std::function< void()> f)
Invokes a callback when a 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.
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
void set_pong_handler(pong_handler h)
void clear_error_channels(log::level channels)
Clear Error logging channels.
bool isListening() const final
Returns whether the channel is listening.
represents the underlying protocol and address used by a Face
void handlePongTimeout(websocketpp::connection_hdl hdl)
void clear_access_channels(log::level channels)
Clear Access logging channels.
std::function< void(const shared_ptr< Face > &)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
A Transport that communicates on a WebSocket connection.
void set_pong_timeout(long dur)
Set pong timeout.
boost::asio::ip::tcp::endpoint Endpoint
void set_message_handler(message_handler h)
static level const all
Special aggregate value representing "all levels".
boost::chrono::milliseconds milliseconds