35 time::milliseconds pingInterval)
38 , m_pingInterval(pingInterval)
40 const auto& sock = m_server.get_con_from_hdl(hdl)->get_socket();
41 this->setLocalUri(
FaceUri(sock.local_endpoint(),
"ws"));
42 this->setRemoteUri(
FaceUri(sock.remote_endpoint(),
"wsclient"));
44 if (sock.local_endpoint().address().is_loopback() &&
45 sock.remote_endpoint().address().is_loopback())
63 BOOST_THROW_EXCEPTION(
64 std::invalid_argument(
"WebSocketTransport supports only FACE_PERSISTENCY_ON_DEMAND"));
73 websocketpp::lib::error_code error;
74 m_server.send(m_handle, packet.packet.wire(), packet.packet.size(),
75 websocketpp::frame::opcode::binary, error);
77 return processErrorCode(error);
83 WebSocketTransport::receiveMessage(
const std::string& msg)
89 std::tie(isOk, element) =
Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.c_str()), msg.size());
99 WebSocketTransport::schedulePing()
101 m_pingEventId =
scheduler::schedule(m_pingInterval, bind(&WebSocketTransport::sendPing,
this));
105 WebSocketTransport::sendPing()
111 websocketpp::lib::error_code error;
112 m_server.ping(m_handle,
"NFD-WebSocket", error);
114 return processErrorCode(error);
116 this->schedulePing();
120 WebSocketTransport::handlePong()
128 WebSocketTransport::handlePongTimeout()
136 WebSocketTransport::processErrorCode(
const websocketpp::lib::error_code& error)
153 WebSocketTransport::doClose()
157 m_pingEventId.cancel();
160 websocketpp::lib::error_code error;
161 m_server.close(m_handle, websocketpp::close::status::normal,
"closed by NFD", error);
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to construct block from Buffer.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
websocketpp::server< websocketpp::config::asio > Server
represents the underlying protocol and address used by a Face
stores a packet along with the remote endpoint
Class representing a wire element of NDN-TLV packet format.
the transport is being closed due to a failure
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
Copyright (c) 2011-2015 Regents of the University of California.
the transport is closed, and can be safely deallocated
the transport is requested to be closed
#define NFD_LOG_INIT(name)
EventId schedule(const time::nanoseconds &after, const Scheduler::Event &event)
schedule an event
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.