29 #include <boost/asio/defer.hpp>
31 #if defined(__linux__)
32 #include <linux/sockios.h>
33 #include <sys/ioctl.h>
38 namespace ip = boost::asio::ip;
43 ndn::nfd::FacePersistency persistency,
44 ndn::nfd::FaceScope faceScope)
46 , m_remoteEndpoint(m_socket.remote_endpoint())
47 , m_nextReconnectWait(INITIAL_RECONNECT_DELAY)
53 this->
setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT);
67 #if defined(__linux__)
69 if (ioctl(
m_socket.native_handle(), SIOCOUTQNSD, &nsd) < 0) {
70 NFD_LOG_FACE_WARN(
"Failed to obtain send queue length from socket: " << std::strerror(errno));
91 if (oldPersistency == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
103 if (this->
getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
108 boost::system::error_code ec;
120 TcpTransport::reconnect()
131 BOOST_ASSERT(
getPersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT);
139 m_reconnectEvent =
getScheduler().schedule(m_nextReconnectWait,
140 [
this] { this->handleReconnectTimeout(); });
141 m_socket.async_connect(m_remoteEndpoint, [
this] (
const auto& e) { this->handleReconnect(e); });
145 TcpTransport::handleReconnect(
const boost::system::error_code& error)
150 error == boost::asio::error::operation_aborted) {
160 m_reconnectEvent.cancel();
161 m_nextReconnectWait = INITIAL_RECONNECT_DELAY;
170 TcpTransport::handleReconnectTimeout()
173 boost::system::error_code error;
177 m_nextReconnectWait =
178 std::min(time::duration_cast<time::milliseconds>(m_nextReconnectWait * RECONNECT_DELAY_MULTIPLIER),
179 MAX_RECONNECT_DELAY);
188 m_reconnectEvent.cancel();
Implements a Transport for stream-based protocols.
virtual void handleError(const boost::system::error_code &error)
void doClose() override
Performs Transport specific operations to close the transport.
void resetReceiveBuffer()
size_t getSendQueueBytes() const
protocol::socket m_socket
bool canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const final
Invoked by canChangePersistencyTo to perform the check.
void handleError(const boost::system::error_code &error) final
void afterChangePersistency(ndn::nfd::FacePersistency oldPersistency) final
Invoked after the persistency has been changed.
TcpTransport(boost::asio::ip::tcp::socket &&socket, ndn::nfd::FacePersistency persistency, ndn::nfd::FaceScope faceScope)
ssize_t getSendQueueLength() final
Returns the current send queue length of the transport (in octets).
void doClose() final
Performs Transport specific operations to close the transport.
void setScope(ndn::nfd::FaceScope scope) noexcept
void setPersistency(ndn::nfd::FacePersistency newPersistency)
Changes the persistency setting of the transport.
ndn::nfd::FacePersistency getPersistency() const noexcept
Returns the current persistency setting of the transport.
void setMtu(ssize_t mtu) noexcept
TransportState getState() const noexcept
Returns the current transport state.
void setState(TransportState newState)
Set transport state.
void setLocalUri(const FaceUri &uri) noexcept
void setLinkType(ndn::nfd::LinkType linkType) noexcept
void setRemoteUri(const FaceUri &uri) noexcept
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
#define NFD_LOG_MEMBER_INIT_SPECIALIZED(cls, name)
@ CLOSED
the transport is closed, and can be safely deallocated
@ CLOSING
the transport is being closed gracefully, either by the peer or by a call to close()
@ FAILED
the transport is being closed due to a failure
@ DOWN
the transport is temporarily down, and is being recovered
@ UP
the transport is up and can transmit packets
constexpr ssize_t MTU_UNLIMITED
Indicates that the transport has no limit on payload size.
ndn::Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
boost::asio::io_context & getGlobalIoService()
Returns the global io_context instance for the calling thread.