29 #if defined(__linux__) 30 #include <linux/sockios.h> 31 #include <sys/ioctl.h> 39 time::milliseconds TcpTransport::s_initialReconnectWait = 1_s;
40 time::milliseconds TcpTransport::s_maxReconnectWait = 5_min;
41 float TcpTransport::s_reconnectWaitMultiplier = 2.0f;
44 ndn::nfd::FacePersistency persistency,
45 ndn::nfd::FaceScope faceScope)
47 , m_remoteEndpoint(m_socket.remote_endpoint())
48 , m_nextReconnectWait(s_initialReconnectWait)
54 this->
setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT);
68 #if defined(__linux__) 70 if (ioctl(
m_socket.native_handle(), SIOCOUTQNSD, &nsd) < 0) {
71 NFD_LOG_FACE_WARN(
"Failed to obtain send queue length from socket: " << std::strerror(errno));
92 if (oldPersistency == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
104 if (this->
getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
109 boost::system::error_code ec;
121 TcpTransport::reconnect()
132 BOOST_ASSERT(
getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT);
137 #
if BOOST_VERSION >= 107000
141 #endif // BOOST_VERSION >= 107000 146 m_reconnectEvent =
getScheduler().schedule(m_nextReconnectWait,
147 [
this] { this->handleReconnectTimeout(); });
148 m_socket.async_connect(m_remoteEndpoint, [
this] (
const auto& e) { this->handleReconnect(e); });
152 TcpTransport::handleReconnect(
const boost::system::error_code& error)
157 error == boost::asio::error::operation_aborted) {
167 m_reconnectEvent.cancel();
168 m_nextReconnectWait = s_initialReconnectWait;
177 TcpTransport::handleReconnectTimeout()
180 boost::system::error_code error;
184 m_nextReconnectWait =
185 std::min(time::duration_cast<time::milliseconds>(m_nextReconnectWait * s_reconnectWaitMultiplier),
195 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)
#define NFD_LOG_MEMBER_INIT_SPECIALIZED(cls, name)
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
the transport is being closed due to a failure
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
Implements Transport for stream-based protocols.
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
size_t getSendQueueBytes() const
bool canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const final
invoked by canChangePersistencyTo to perform the check
ssize_t getSendQueueLength() final
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
TcpTransport(protocol::socket &&socket, ndn::nfd::FacePersistency persistency, ndn::nfd::FaceScope faceScope)
the transport is closed, and can be safely deallocated
void setLinkType(ndn::nfd::LinkType linkType)
the transport is being closed gracefully, either by the peer or by a call to close() ...
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
void doClose() final
performs Transport specific operations to close the transport
TransportState getState() const
void doClose() override
performs Transport specific operations to close the transport
void setState(TransportState newState)
set transport state
void setRemoteUri(const FaceUri &uri)
the transport is up and can transmit packets
virtual void handleError(const boost::system::error_code &error)
protocol::socket m_socket
the transport is temporarily down, and is being recovered
boost::asio::io_service & getGlobalIoService()
Returns the global io_service instance for the calling thread.