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,
76 size_t nBytesSent,
const Block& payload);
79 handleReceive(
const boost::system::error_code& error,
80 size_t nBytesReceived);
83 processErrorCode(
const boost::system::error_code& error);
86 hasRecentlyReceived()
const;
89 resetRecentlyReceived();
92 makeEndpointId(
const typename protocol::endpoint& ep);
101 std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
102 bool m_hasRecentlyReceived;
106 template<
class T,
class U>
108 : m_socket(
std::move(socket))
109 , m_hasRecentlyReceived(false)
111 boost::asio::socket_base::send_buffer_size sendBufferSizeOption;
112 boost::system::error_code error;
113 m_socket.get_option(sendBufferSizeOption, error);
115 NFD_LOG_FACE_WARN(
"Failed to obtain send queue capacity from socket: " << error.message());
124 boost::asio::placeholders::error,
125 boost::asio::placeholders::bytes_transferred));
128 template<
class T,
class U>
134 NFD_LOG_FACE_WARN(
"Failed to obtain send queue length from socket: " << std::strerror(errno));
139 template<
class T,
class U>
148 boost::system::error_code error;
160 template<
class T,
class U>
166 m_socket.async_send(boost::asio::buffer(packet.packet),
168 boost::asio::placeholders::error,
169 boost::asio::placeholders::bytes_transferred,
173 template<
class T,
class U>
176 const boost::system::error_code& error)
185 std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
191 if (element.size() != nBytesReceived) {
192 NFD_LOG_FACE_WARN(
"Received datagram size and decoded element size don't match");
196 m_hasRecentlyReceived =
true;
203 template<
class T,
class U>
206 size_t nBytesReceived)
213 boost::asio::placeholders::error,
214 boost::asio::placeholders::bytes_transferred));
217 template<
class T,
class U>
220 size_t nBytesSent,
const Block& payload)
229 template<
class T,
class U>
238 error == boost::asio::error::operation_aborted) {
253 template<
class T,
class U>
257 return m_hasRecentlyReceived;
260 template<
class T,
class U>
264 m_hasRecentlyReceived =
false;
267 template<
class T,
class U>
277 #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_INCLASS_DECLARE()
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
void handleSend(const boost::system::error_code &error, size_t nBytesSent, const Block &payload)
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 processErrorCode(const boost::system::error_code &error)
boost::asio::io_service & getGlobalIoService()