33 time::milliseconds TcpTransport::s_initialReconnectWait = time::seconds(1);
34 time::milliseconds TcpTransport::s_maxReconnectWait = time::minutes(5);
35 float TcpTransport::s_reconnectWaitMultiplier = 2.0f;
39 , m_remoteEndpoint(m_socket.remote_endpoint())
40 , m_nextReconnectWait(s_initialReconnectWait)
45 if (
m_socket.local_endpoint().address().is_loopback() &&
46 m_socket.remote_endpoint().address().is_loopback())
47 this->
setScope(ndn::nfd::FACE_SCOPE_LOCAL);
49 this->
setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
52 this->
setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT);
68 if (oldPersistency == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
80 if (this->
getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
85 boost::system::error_code error;
97 TcpTransport::reconnect()
108 BOOST_ASSERT(
getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT);
117 [
this] { handleReconnectTimeout(); });
118 m_socket.async_connect(m_remoteEndpoint,
119 [
this] (
const boost::system::error_code& error) { handleReconnect(error); });
123 TcpTransport::handleReconnect(
const boost::system::error_code& error)
128 error == boost::asio::error::operation_aborted) {
138 m_reconnectEvent.
cancel();
139 m_nextReconnectWait = s_initialReconnectWait;
148 TcpTransport::handleReconnectTimeout()
151 boost::system::error_code error;
155 m_nextReconnectWait =
156 std::min(time::duration_cast<time::milliseconds>(m_nextReconnectWait * s_reconnectWaitMultiplier),
166 m_reconnectEvent.
cancel();
void resetReceiveBuffer()
void setLocalUri(const FaceUri &uri)
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
void setScope(ndn::nfd::FaceScope scope)
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
bool canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const final
invoked by canChangePersistencyTo to perform the check
boost::asio::ip::tcp protocol
TcpTransport(protocol::socket &&socket, ndn::nfd::FacePersistency persistency)
the transport is being closed due to a failure
Implements Transport for stream-based protocols.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
the transport is closed, and can be safely deallocated
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
#define NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(cls, specialization, name)
void setLinkType(ndn::nfd::LinkType linkType)
the transport is requested to be closed
void afterChangePersistency(ndn::nfd::FacePersistency oldPersistency) final
invoked after the persistency has been changed
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
void handleError(const boost::system::error_code &error) final
ndn::nfd::FacePersistency getPersistency() const
EventId schedule(const time::nanoseconds &after, const Scheduler::Event &event)
schedule an event
void doClose() final
performs Transport specific operations to close the transport
TransportState getState() const
virtual void doClose() override
performs Transport specific operations to close the transport
void setState(TransportState newState)
set transport state
void setRemoteUri(const FaceUri &uri)
void cancel()
cancels the event manually
virtual void handleError(const boost::system::error_code &error)
protocol::socket m_socket
the transport is down temporarily, and is being recovered
boost::asio::io_service & getGlobalIoService()