26 #ifndef NFD_DAEMON_FACE_DATAGRAM_FACE_HPP 27 #define NFD_DAEMON_FACE_DATAGRAM_FACE_HPP 37 template<
class Protocol,
class Addressing = Unicast>
48 typename protocol::socket socket);
58 close() DECL_OVERRIDE;
61 receiveDatagram(const uint8_t* buffer,
62 size_t nBytesReceived,
63 const
boost::system::error_code& error);
67 processErrorCode(const
boost::system::error_code& error);
70 handleSend(const
boost::system::error_code& error,
72 const
Block& payload);
75 handleReceive(const
boost::system::error_code& error,
76 size_t nBytesReceived);
79 keepFaceAliveUntilAllHandlersExecuted(const shared_ptr<
Face>& face);
85 hasBeenUsedRecently() const;
94 typename protocol::socket m_socket;
96 NFD_LOG_INCLASS_DECLARE();
100 bool m_hasBeenUsedRecently;
104 template<class T, class U>
109 , m_socket(
std::move(socket))
115 boost::asio::placeholders::error,
116 boost::asio::placeholders::bytes_transferred));
119 template<
class T,
class U>
128 m_socket.async_send(boost::asio::buffer(payload.
wire(), payload.
size()),
130 boost::asio::placeholders::error,
131 boost::asio::placeholders::bytes_transferred,
135 template<
class T,
class U>
144 m_socket.async_send(boost::asio::buffer(payload.
wire(), payload.
size()),
146 boost::asio::placeholders::error,
147 boost::asio::placeholders::bytes_transferred,
151 template<
class T,
class U>
155 if (!m_socket.is_open())
161 this->fail(
"Face closed");
164 template<
class T,
class U>
168 if (error == boost::asio::error::operation_aborted)
176 if (!m_socket.is_open()) {
177 this->fail(
"Tunnel closed");
181 if (error != boost::asio::error::eof)
186 if (error == boost::asio::error::eof)
187 this->fail(
"Tunnel closed");
189 this->fail(error.message());
192 template<
class T,
class U>
196 const Block& payload)
200 return processErrorCode(error);
203 this->getMutableCounters().getNOutBytes() += nBytesSent;
206 template<
class T,
class U>
209 size_t nBytesReceived)
211 receiveDatagram(m_inputBuffer, nBytesReceived, error);
213 if (m_socket.is_open())
216 boost::asio::placeholders::error,
217 boost::asio::placeholders::bytes_transferred));
220 template<
class T,
class U>
223 size_t nBytesReceived,
224 const boost::system::error_code& error)
227 return processErrorCode(error);
230 this->getMutableCounters().getNInBytes() += nBytesReceived;
242 if (element.
size() != nBytesReceived)
244 NFD_LOG_FACE_WARN(
"Received datagram size and decoded element size don't match");
249 if (!this->decodeAndDispatchInput(element))
256 m_hasBeenUsedRecently =
true;
259 template<
class T,
class U>
266 template<
class T,
class U>
273 boost::system::error_code error;
274 m_socket.shutdown(protocol::socket::shutdown_both, error);
275 m_socket.close(error);
281 this, this->shared_from_this()));
284 template<
class T,
class U>
288 return m_hasBeenUsedRecently;
291 template<
class T,
class U>
295 m_hasBeenUsedRecently =
false;
300 #endif // NFD_DAEMON_FACE_DATAGRAM_FACE_HPP void processErrorCode(const boost::system::error_code &error)
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.
bool hasBeenUsedRecently() const
Copyright (c) 2013-2015 Regents of the University of California.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
represents the underlying protocol and address used by a Face
void sendData(const Data &data) 1
send a Data
Class representing a wire element of NDN-TLV packet format.
represents an Interest packet
#define DECL_OVERRIDE
expands to 'override' if compiler supports this feature, otherwise expands to nothing ...
void sendInterest(const Interest &interest) 1
send an Interest
void handleReceive(const boost::system::error_code &error, size_t nBytesReceived)
#define emitSignal(...)
(implementation detail)
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Fast encoding or block size estimation.
void close() 1
Close the face.
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
Copyright (c) 2011-2015 Regents of the University of California.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
void handleSend(const boost::system::error_code &error, size_t nBytesSent, const Block &payload)
void keepFaceAliveUntilAllHandlersExecuted(const shared_ptr< Face > &face)
const uint8_t * wire() const
void receiveDatagram(const uint8_t *buffer, size_t nBytesReceived, const boost::system::error_code &error)
boost::asio::io_service & getGlobalIoService()
#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
void resetRecentUsage()
Set m_hasBeenUsedRecently to false.