26 #ifndef NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP 27 #define NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP 44 template<
class Protocol,
class Addressing = Unicast>
60 receiveDatagram(
const uint8_t* buffer,
size_t nBytesReceived,
61 const boost::system::error_code& error);
71 handleSend(const
boost::system::error_code& error,
72 size_t nBytesSent, const
Block& payload);
75 handleReceive(const
boost::system::error_code& error,
76 size_t nBytesReceived);
79 processErrorCode(const
boost::system::error_code& error);
82 hasBeenUsedRecently() const;
88 makeEndpointId(const typename protocol::endpoint& ep);
91 typename protocol::socket m_socket;
92 typename protocol::endpoint m_sender;
98 bool m_hasBeenUsedRecently;
102 template<class T, class U>
104 : m_socket(
std::move(socket))
105 , m_hasBeenUsedRecently(false)
107 m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
109 boost::asio::placeholders::error,
110 boost::asio::placeholders::bytes_transferred));
113 template<
class T,
class U>
119 if (m_socket.is_open()) {
122 boost::system::error_code error;
123 m_socket.cancel(error);
124 m_socket.close(error);
134 template<
class T,
class U>
140 m_socket.async_send(boost::asio::buffer(packet.packet),
142 boost::asio::placeholders::error,
143 boost::asio::placeholders::bytes_transferred,
147 template<
class T,
class U>
150 const boost::system::error_code& error)
153 return processErrorCode(error);
165 if (element.
size() != nBytesReceived) {
166 NFD_LOG_FACE_WARN(
"Received datagram size and decoded element size don't match");
170 m_hasBeenUsedRecently =
true;
174 this->receive(std::move(tp));
177 template<
class T,
class U>
180 size_t nBytesReceived)
182 receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
184 if (m_socket.is_open())
185 m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
187 boost::asio::placeholders::error,
188 boost::asio::placeholders::bytes_transferred));
191 template<
class T,
class U>
194 size_t nBytesSent,
const Block& payload)
198 return processErrorCode(error);
203 template<
class T,
class U>
212 error == boost::asio::error::operation_aborted)
221 if (error != boost::asio::error::eof)
228 template<
class T,
class U>
232 return m_hasBeenUsedRecently;
235 template<
class T,
class U>
239 m_hasBeenUsedRecently =
false;
242 template<
class T,
class U>
252 #endif // NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP void handleSend(const boost::system::error_code &error, size_t nBytesSent, const Block &payload)
Copyright (c) 2011-2015 Regents of the University of California.
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to construct block from Buffer.
Copyright (c) 2013-2015 Regents of the University of California.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
void handleReceive(const boost::system::error_code &error, size_t nBytesReceived)
stores a packet along with the remote endpoint
detail::SimulatorIo & getGlobalIoService()
#define NFD_LOG_INCLASS_DECLARE()
Class representing a wire element of NDN-TLV packet format.
#define DECL_OVERRIDE
expands to 'override' if compiler supports 'override' specifier, otherwise expands to nothing ...
Implements Transport for datagram-based protocols.
virtual void doClose() 1
performs Transport specific operations to close the transport
the transport is being closed due to a failure
static EndpointId makeEndpointId(const typename protocol::endpoint &ep)
void receiveDatagram(const uint8_t *buffer, size_t nBytesReceived, const boost::system::error_code &error)
Receive datagram, translate buffer into packet, deliver to parent class.
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
Copyright (c) 2011-2015 Regents of the University of California.
void processErrorCode(const boost::system::error_code &error)
EndpointId remoteEndpoint
identifies the remote endpoint
the transport is closed, and can be safely deallocated
void post(const std::function< void()> &callback)
the transport is requested to be closed
virtual void doSend(Transport::Packet &&packet) 1
performs Transport specific operations to send a packet
bool hasBeenUsedRecently() const
uint64_t EndpointId
identifies an endpoint on the link
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size