26 #ifndef NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP 27 #define NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP 45 template<
class Protocol,
class Addressing = Unicast>
59 getSendQueueLength()
override;
64 receiveDatagram(
const uint8_t* buffer,
size_t nBytesReceived,
65 const boost::system::error_code& error);
75 handleSend(
const boost::system::error_code& error,
size_t nBytesSent);
78 handleReceive(
const boost::system::error_code& error,
size_t nBytesReceived);
81 processErrorCode(
const boost::system::error_code& error);
84 hasRecentlyReceived()
const;
87 resetRecentlyReceived();
90 makeEndpointId(
const typename protocol::endpoint& ep);
99 std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
100 bool m_hasRecentlyReceived;
104 template<
class T,
class U>
106 : m_socket(
std::move(socket))
107 , m_hasRecentlyReceived(false)
109 boost::asio::socket_base::send_buffer_size sendBufferSizeOption;
110 boost::system::error_code error;
111 m_socket.get_option(sendBufferSizeOption, error);
113 NFD_LOG_FACE_WARN(
"Failed to obtain send queue capacity from socket: " << error.message());
121 [
this] (
auto&&... args) {
126 template<
class T,
class U>
132 NFD_LOG_FACE_WARN(
"Failed to obtain send queue length from socket: " << std::strerror(errno));
137 template<
class T,
class U>
146 boost::system::error_code error;
158 template<
class T,
class U>
164 m_socket.async_send(boost::asio::buffer(packet.packet),
166 [
this, p = packet.packet] (
auto&&... args) {
167 this->handleSend(std::forward<decltype(args)>(args)...);
171 template<
class T,
class U>
174 const boost::system::error_code& error)
183 std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
189 if (element.size() != nBytesReceived) {
190 NFD_LOG_FACE_WARN(
"Received datagram size and decoded element size don't match");
194 m_hasRecentlyReceived =
true;
201 template<
class T,
class U>
209 [
this] (
auto&&... args) {
210 this->handleReceive(std::forward<decltype(args)>(args)...);
214 template<
class T,
class U>
224 template<
class T,
class U>
233 error == boost::asio::error::operation_aborted) {
248 template<
class T,
class U>
252 return m_hasRecentlyReceived;
255 template<
class T,
class U>
259 m_hasRecentlyReceived =
false;
262 template<
class T,
class U>
272 #endif // NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP void setSendQueueCapacity(ssize_t sendQueueCapacity)
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.
void doClose() override
performs Transport specific operations to close the transport
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
void resetRecentlyReceived()
protocol::socket m_socket
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
const ssize_t QUEUE_ERROR
indicates that the transport was unable to retrieve the queue capacity/length
#define NFD_LOG_MEMBER_DECL()
bool hasRecentlyReceived() const
void receive(Packet &&packet)
receive a link-layer packet
stores a packet along with the remote endpoint
the transport is being closed due to a failure
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
ssize_t getSendQueueLength() override
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
the transport is closed, and can be safely deallocated
static EndpointId makeEndpointId(const typename protocol::endpoint &ep)
uint64_t EndpointId
identifies an endpoint on the link
ssize_t getTxQueueLength(int fd)
obtain send queue length from a specified system socket
the transport is being closed gracefully, either by the peer or by a call to close() ...
ndn::nfd::FacePersistency getPersistency() const
Implements Transport for datagram-based protocols.
TransportState getState() const
EndpointId remoteEndpoint
identifies the remote endpoint
void setState(TransportState newState)
set transport state
void doSend(Transport::Packet &&packet) override
performs Transport specific operations to send a packet
void handleReceive(const boost::system::error_code &error, size_t nBytesReceived)
#define NFD_LOG_FACE_ERROR(msg)
Log a message at ERROR level.
protocol::endpoint m_sender
DatagramTransport(typename protocol::socket &&socket)
Construct datagram transport.
void handleSend(const boost::system::error_code &error, size_t nBytesSent)
void processErrorCode(const boost::system::error_code &error)
boost::asio::io_service & getGlobalIoService()