26 #ifndef NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP 27 #define NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP 41 template<
class Protocol>
73 size_t nBytesReceived);
85 size_t m_receiveBufferSize;
92 : m_socket(
std::move(socket))
93 , m_receiveBufferSize(0)
97 boost::asio::placeholders::error,
98 boost::asio::placeholders::bytes_transferred));
111 boost::system::error_code error;
113 m_socket.shutdown(protocol::socket::shutdown_both, error);
140 std::queue<Block> emptyQueue;
141 std::swap(emptyQueue, m_sendQueue);
144 boost::system::error_code error;
156 bool wasQueueEmpty = m_sendQueue.empty();
157 m_sendQueue.push(packet.packet);
167 boost::asio::async_write(
m_socket, boost::asio::buffer(m_sendQueue.front()),
169 boost::asio::placeholders::error,
170 boost::asio::placeholders::bytes_transferred));
183 BOOST_ASSERT(!m_sendQueue.empty());
186 if (!m_sendQueue.empty())
193 size_t nBytesReceived)
200 m_receiveBufferSize += nBytesReceived;
206 while (m_receiveBufferSize - offset > 0) {
207 std::tie(isOk, element) =
Block::fromBuffer(m_receiveBuffer + offset, m_receiveBufferSize - offset);
211 offset += element.
size();
212 BOOST_ASSERT(offset <= m_receiveBufferSize);
218 NFD_LOG_FACE_WARN(
"Failed to parse incoming packet or packet too large to process");
225 if (offset != m_receiveBufferSize) {
226 std::copy(m_receiveBuffer + offset, m_receiveBuffer + m_receiveBufferSize, m_receiveBuffer);
227 m_receiveBufferSize -= offset;
230 m_receiveBufferSize = 0;
234 m_socket.async_receive(boost::asio::buffer(m_receiveBuffer + m_receiveBufferSize,
237 boost::asio::placeholders::error,
238 boost::asio::placeholders::bytes_transferred));
250 error == boost::asio::error::operation_aborted ||
251 error == boost::asio::error::shut_down)
255 if (error != boost::asio::error::eof)
265 #endif // NFD_DAEMON_FACE_STREAM_TRANSPORT_HPP Copyright (c) 2011-2015 Regents of the University of California.
void processErrorCode(const boost::system::error_code &error)
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.
virtual void doSend(Transport::Packet &&packet) 1
performs Transport specific operations to send a packet
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
stores a packet along with the remote endpoint
detail::SimulatorIo & getGlobalIoService()
Class representing a wire element of NDN-TLV packet format.
#define DECL_OVERRIDE
expands to 'override' if compiler supports 'override' specifier, otherwise expands to nothing ...
Implements Transport for stream-based protocols.
protocol::socket m_socket
the transport is being closed due to a failure
NFD_LOG_INCLASS_DECLARE()
TransportState getState() const
Copyright (c) 2011-2015 Regents of the University of California.
the transport is closed, and can be safely deallocated
void post(const std::function< void()> &callback)
StreamTransport(typename protocol::socket &&socket)
Construct stream transport.
virtual void doClose() 1
performs Transport specific operations to close the transport
the transport is requested to be closed
void handleReceive(const boost::system::error_code &error, size_t nBytesReceived)
void handleSend(const boost::system::error_code &error, size_t nBytesSent)
void setState(TransportState newState)
set transport state
void receive(Packet &&packet)
receive a link-layer 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