22 #ifndef NDN_TRANSPORT_STREAM_TRANSPORT_IMPL_HPP 23 #define NDN_TRANSPORT_STREAM_TRANSPORT_IMPL_HPP 27 #include <boost/asio.hpp> 37 template<
typename BaseTransport,
typename Protocol>
38 class StreamTransportImpl :
public enable_shared_from_this<StreamTransportImpl<BaseTransport, Protocol>>
55 connect(
const typename Protocol::endpoint& endpoint)
75 boost::system::error_code error;
113 BlockSequence sequence;
114 sequence.push_back(wire);
115 send(std::move(sequence));
121 BlockSequence sequence;
122 sequence.push_back(header);
123 sequence.push_back(payload);
124 send(std::move(sequence));
145 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while connecting to the forwarder"));
156 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while connecting to the forwarder"));
181 handleAsyncWrite(
const boost::system::error_code& error, TransmissionQueue::iterator queueItem)
184 if (error == boost::system::errc::operation_canceled) {
190 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while sending data to socket"));
216 if (error == boost::system::errc::operation_canceled) {
222 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while receiving data from socket"));
228 std::size_t offset = 0;
233 "input buffer full, but a valid TLV cannot be " 253 while (offset < nBytesAvailable) {
256 std::tie(isOk, element) =
Block::fromBuffer(buffer + offset, nBytesAvailable - offset);
261 offset += element.
size();
281 #endif // NDN_TRANSPORT_STREAM_TRANSPORT_IMPL_HPP
bool processAllReceived(uint8_t *buffer, size_t &offset, size_t nBytesAvailable)
void connectTimeoutHandler(const boost::system::error_code &error)
Copyright (c) 2013-2017 Regents of the University of California.
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to parse Block from a wire buffer.
void send(BlockSequence &&sequence)
StreamTransportImpl(BaseTransport &transport, boost::asio::io_service &ioService)
BaseTransport & m_transport
Represents a TLV element of NDN packet format.
StreamTransportImpl< BaseTransport, Protocol > Impl
TransmissionQueue m_transmissionQueue
implementation detail of a Boost.Asio-based stream-oriented transport
void handleAsyncReceive(const boost::system::error_code &error, std::size_t nBytesRecvd)
void send(const Block &wire)
size_t size() const
Get size of encoded wire, including Type-Length-Value.
void connect(const typename Protocol::endpoint &endpoint)
void handleAsyncWrite(const boost::system::error_code &error, TransmissionQueue::iterator queueItem)
Protocol::socket m_socket
uint8_t m_inputBuffer[MAX_NDN_PACKET_SIZE]
void send(const Block &header, const Block &payload)
boost::asio::deadline_timer m_connectTimer
std::list< Block > BlockSequence
std::list< BlockSequence > TransmissionQueue
void connectHandler(const boost::system::error_code &error)
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size