26 #ifndef NFD_DAEMON_FACE_STREAM_FACE_HPP 27 #define NFD_DAEMON_FACE_STREAM_FACE_HPP 38 template<
class Protocol,
class FaceBase = Face>
45 typename protocol::socket socket,
bool isOnDemand);
55 close() DECL_OVERRIDE;
70 size_t nBytesReceived);
85 size_t m_inputBufferSize;
103 template<class Protocol, class U>
113 template<
class T,
class FaceBase>
116 typename StreamFace::protocol::socket socket,
bool isOnDemand)
117 : FaceBase(remoteUri, localUri)
119 , m_inputBufferSize(0)
128 boost::asio::placeholders::error,
129 boost::asio::placeholders::bytes_transferred));
133 template<
class Protocol,
class FaceBase,
class Packet>
139 bool wasQueueEmpty = face.m_sendQueue.empty();
140 face.m_sendQueue.push(packet.wireEncode());
148 template<
class Protocol,
class Packet>
154 bool wasQueueEmpty = face.m_sendQueue.empty();
156 if (!face.isEmptyFilteredLocalControlHeader(packet.getLocalControlHeader()))
158 face.m_sendQueue.push(face.filterAndEncodeLocalControlHeader(packet));
160 face.m_sendQueue.push(packet.wireEncode());
168 template<
class T,
class U>
177 template<
class T,
class U>
186 template<
class T,
class U>
196 this->fail(
"Face closed");
199 template<
class T,
class U>
203 if (error == boost::asio::error::operation_aborted ||
204 error == boost::asio::error::shut_down)
209 this->fail(
"Connection closed");
213 if (error != boost::asio::error::eof)
218 if (error == boost::asio::error::eof)
219 this->fail(
"Connection closed");
221 this->fail(error.message());
224 template<
class T,
class U>
228 boost::asio::async_write(
m_socket, boost::asio::buffer(m_sendQueue.front()),
230 boost::asio::placeholders::error,
231 boost::asio::placeholders::bytes_transferred));
234 template<
class T,
class U>
242 BOOST_ASSERT(!m_sendQueue.empty());
245 this->getMutableCounters().getNOutBytes() += nBytesSent;
248 if (!m_sendQueue.empty())
252 template<
class T,
class U>
255 size_t nBytesReceived)
261 this->getMutableCounters().getNInBytes() += nBytesReceived;
263 m_inputBufferSize += nBytesReceived;
269 while (m_inputBufferSize - offset > 0) {
270 std::tie(isOk, element) =
Block::fromBuffer(m_inputBuffer + offset, m_inputBufferSize - offset);
274 offset += element.
size();
276 BOOST_ASSERT(offset <= m_inputBufferSize);
278 if (!this->decodeAndDispatchInput(element)) {
286 NFD_LOG_FACE_WARN(
"Failed to parse incoming packet or packet too large to process");
288 this->fail(
"Failed to parse incoming packet or packet too large to process");
294 if (offset != m_inputBufferSize)
296 std::copy(m_inputBuffer + offset, m_inputBuffer + m_inputBufferSize,
298 m_inputBufferSize -= offset;
302 m_inputBufferSize = 0;
306 m_socket.async_receive(boost::asio::buffer(m_inputBuffer + m_inputBufferSize,
309 boost::asio::placeholders::error,
310 boost::asio::placeholders::bytes_transferred));
313 template<
class T,
class U>
322 boost::system::error_code error;
324 m_socket.shutdown(protocol::socket::shutdown_both, error);
329 this, this->shared_from_this()));
344 template<
class T,
class U>
351 std::queue<Block> emptyQueue;
352 std::swap(emptyQueue, m_sendQueue);
355 boost::system::error_code error;
361 #endif // NFD_DAEMON_FACE_STREAM_FACE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
void handleReceive(const boost::system::error_code &error, size_t nBytesReceived)
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.
represents the underlying protocol and address used by a Face
NFD_LOG_INCLASS_DECLARE()
Class representing a wire element of NDN-TLV packet format.
represents an Interest packet
static void send(StreamFace< Protocol, LocalFace > &face, const Packet &packet)
void sendData(const Data &data) 1
StreamFace(const FaceUri &remoteUri, const FaceUri &localUri, typename protocol::socket socket, bool isOnDemand)
#define DECL_OVERRIDE
expands to 'override' if compiler supports this feature, otherwise expands to nothing ...
Class allowing validation of the StreamFace use.
#define emitSignal(...)
(implementation detail)
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
Copyright (c) 2011-2015 Regents of the University of California.
static void validateSocket(const typename Protocol::socket &socket)
void deferredClose(const shared_ptr< Face > &face)
protocol::socket m_socket
void sendInterest(const Interest &interest) 1
void handleSend(const boost::system::error_code &error, size_t nBytesSent)
boost::asio::io_service & getGlobalIoService()
void processErrorCode(const boost::system::error_code &error)
static void send(StreamFace< Protocol, FaceBase > &face, const Packet &packet)
#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