26 #ifndef NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP 27 #define NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP 41 template<
class Protocol>
68 handleSend(
const boost::system::error_code& error,
76 size_t nBytesReceived);
82 handleError(
const boost::system::error_code& error);
96 uint8_t m_receiveBuffer[ndn::MAX_NDN_PACKET_SIZE];
97 size_t m_receiveBufferSize;
98 std::queue<Block> m_sendQueue;
105 , m_receiveBufferSize(0)
120 boost::system::error_code error;
122 m_socket.shutdown(protocol::socket::shutdown_both, error);
151 boost::system::error_code error;
166 bool wasQueueEmpty = m_sendQueue.empty();
167 m_sendQueue.push(packet.packet);
177 boost::asio::async_write(
m_socket, boost::asio::buffer(m_sendQueue.front()),
179 boost::asio::placeholders::error,
180 boost::asio::placeholders::bytes_transferred));
193 BOOST_ASSERT(!m_sendQueue.empty());
196 if (!m_sendQueue.empty())
206 m_socket.async_receive(boost::asio::buffer(m_receiveBuffer + m_receiveBufferSize,
207 ndn::MAX_NDN_PACKET_SIZE - m_receiveBufferSize),
209 boost::asio::placeholders::error,
210 boost::asio::placeholders::bytes_transferred));
216 size_t nBytesReceived)
223 m_receiveBufferSize += nBytesReceived;
226 while (m_receiveBufferSize - offset > 0) {
228 std::tie(isOk, element) = Block::fromBuffer(m_receiveBuffer + offset, m_receiveBufferSize - offset);
232 offset += element.size();
233 BOOST_ASSERT(offset <= m_receiveBufferSize);
238 if (!isOk && m_receiveBufferSize == ndn::MAX_NDN_PACKET_SIZE && offset == 0) {
246 if (offset != m_receiveBufferSize) {
247 std::copy(m_receiveBuffer + offset, m_receiveBuffer + m_receiveBufferSize, m_receiveBuffer);
248 m_receiveBufferSize -= offset;
251 m_receiveBufferSize = 0;
267 error == boost::asio::error::operation_aborted ||
268 error == boost::asio::error::shut_down)
279 if (error == boost::asio::error::eof) {
293 m_receiveBufferSize = 0;
300 std::queue<Block> emptyQueue;
301 std::swap(emptyQueue, m_sendQueue);
307 #endif // NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP void resetReceiveBuffer()
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
void receive(Packet &&packet)
receive a link-layer packet
NFD_LOG_INCLASS_DECLARE()
stores a packet along with the remote endpoint
the transport is being closed due to a failure
Implements Transport for stream-based protocols.
void handleReceive(const boost::system::error_code &error, size_t nBytesReceived)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void doSend(Transport::Packet &&packet) override
performs Transport specific operations to send a packet
the transport is closed, and can be safely deallocated
StreamTransport(typename protocol::socket &&socket)
Construct stream transport.
the transport is being closed gracefully, either by the peer or by a call to close() ...
void processErrorCode(const boost::system::error_code &error)
TransportState getState() const
void doClose() override
performs Transport specific operations to close the transport
void setState(TransportState newState)
set transport state
the transport is up and can transmit packets
#define NFD_LOG_FACE_ERROR(msg)
Log a message at ERROR level.
void handleSend(const boost::system::error_code &error, size_t nBytesSent)
virtual void handleError(const boost::system::error_code &error)
protocol::socket m_socket
boost::asio::io_service & getGlobalIoService()