22 #ifndef NDN_TRANSPORT_STREAM_TRANSPORT_IMPL_HPP 23 #define NDN_TRANSPORT_STREAM_TRANSPORT_IMPL_HPP 27 #include <boost/asio/deadline_timer.hpp> 28 #include <boost/asio/write.hpp> 39 template<
typename BaseTransport,
typename Protocol>
40 class StreamTransportImpl :
public enable_shared_from_this<StreamTransportImpl<BaseTransport, Protocol>>
57 connect(
const typename Protocol::endpoint& endpoint)
77 boost::system::error_code error;
116 sequence.push_back(wire);
117 send(std::move(sequence));
124 sequence.push_back(header);
125 sequence.push_back(payload);
126 send(std::move(sequence));
147 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while connecting to the forwarder"));
158 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while connecting to the forwarder"));
186 if (error == boost::system::errc::operation_canceled) {
192 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while sending data to socket"));
218 if (error == boost::system::errc::operation_canceled) {
224 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while receiving data from socket"));
230 std::size_t offset = 0;
235 "input buffer full, but a valid TLV cannot be " 255 while (offset < nBytesAvailable) {
258 std::tie(isOk, element) =
Block::fromBuffer(buffer + offset, nBytesAvailable - offset);
263 offset += element.
size();
283 #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) 2011-2015 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.
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)
Table::const_iterator iterator
StreamTransportImpl< BaseTransport, Protocol > Impl
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