29 #if defined(__linux__) 30 #include <linux/sockios.h> 31 #include <sys/ioctl.h> 41 float TcpTransport::s_reconnectWaitMultiplier = 2.0f;
47 , m_remoteEndpoint(m_socket.remote_endpoint())
48 , m_nextReconnectWait(s_initialReconnectWait)
50 this->setLocalUri(FaceUri(m_socket.local_endpoint()));
51 this->setRemoteUri(FaceUri(m_socket.remote_endpoint()));
52 this->setScope(faceScope);
53 this->setPersistency(persistency);
61 TcpTransport::getSendQueueLength()
63 int queueLength = getSendQueueBytes();
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));
102 TcpTransport::handleError(
const boost::system::error_code& error)
109 boost::system::error_code ec;
121 TcpTransport::reconnect()
137 #
if BOOST_VERSION >= 107000
138 m_socket.get_executor()
140 m_socket.get_io_service()
141 #endif // BOOST_VERSION >= 107000 143 this->resetReceiveBuffer();
144 this->resetSendQueue();
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)
167 m_reconnectEvent.cancel();
168 m_nextReconnectWait = s_initialReconnectWait;
170 this->setLocalUri(FaceUri(m_socket.local_endpoint()));
173 this->startReceive();
177 TcpTransport::handleReconnectTimeout()
180 boost::system::error_code error;
181 m_socket.close(error);
184 m_nextReconnectWait =
185 std::min(time::duration_cast<time::milliseconds>(m_nextReconnectWait * s_reconnectWaitMultiplier),
193 TcpTransport::doClose()
195 m_reconnectEvent.cancel();
void doClose() override
performs Transport specific operations to close the transport
NFD_LOG_MEMBER_INIT_SPECIALIZED((DatagramTransport< boost::asio::ip::udp, Multicast >), MulticastUdpTransport)
#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
virtual void handleError(const boost::system::error_code &error)
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
the transport is being closed due to a failure
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
Copyright (c) 2011-2015 Regents of the University of California.
the transport is closed, and can be safely deallocated
void post(const std::function< void()> &callback)
the transport is being closed gracefully, either by the peer or by a call to close() ...
Catch-all error for socket component errors that don't fit in other categories.
the transport is up and can transmit packets
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
the transport is temporarily down, and is being recovered
boost::chrono::milliseconds milliseconds