22 #ifndef NDN_TRANSPORT_STREAM_TRANSPORT_HPP 23 #define NDN_TRANSPORT_STREAM_TRANSPORT_HPP 27 #include <boost/asio.hpp> 32 template<
class BaseTransport,
class Protocol>
72 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while connecting to the forwarder"));
83 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while connecting to the forwarder"));
87 connect(
const typename Protocol::endpoint& endpoint)
108 boost::system::error_code error;
152 BlockSequence sequence;
153 sequence.push_back(wire);
169 BlockSequence sequence;
170 sequence.push_back(header);
171 sequence.push_back(payload);
190 if (error == boost::system::errc::operation_canceled) {
196 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while sending data to socket"));
213 processAll(uint8_t* buffer,
size_t& offset,
size_t nBytesAvailable)
215 while (offset < nBytesAvailable) {
218 std::tie(isOk, element) =
Block::fromBuffer(buffer + offset, nBytesAvailable - offset);
223 offset += element.
size();
233 if (error == boost::system::errc::operation_canceled) {
239 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while receiving data from socket"));
245 std::size_t offset = 0;
251 "input buffer full, but a valid TLV cannot be " 288 template<
class BaseTransport,
class Protocol>
302 const shared_ptr<typename Protocol::resolver>&)
306 if (error == boost::system::errc::operation_canceled)
309 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"Error during resolution of host or port"));
316 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"Unable to resolve because host or port"));
319 this->
m_socket.async_connect(*endpoint,
324 connect(
const typename Protocol::resolver::query& query)
331 this->
m_connectTimer.expires_from_now(boost::posix_time::seconds(4));
335 shared_ptr<typename Protocol::resolver> resolver =
336 make_shared<typename Protocol::resolver>(ref(this->
m_socket.get_io_service()));
338 resolver->async_resolve(query, bind(&Impl::resolveHandler,
this, _1, _2, resolver));
346 #endif // NDN_TRANSPORT_STREAM_TRANSPORT_HPP
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 construct block from Buffer.
StreamTransportImpl(BaseTransport &transport, boost::asio::io_service &ioService)
BaseTransport & m_transport
Class representing a wire element of NDN-TLV packet format.
StreamTransportImpl< BaseTransport, Protocol > Impl
TransmissionQueue m_transmissionQueue
void handleAsyncReceive(const boost::system::error_code &error, std::size_t nBytesRecvd)
void send(const Block &wire)
Table::const_iterator iterator
void connect(const typename Protocol::resolver::query &query)
void connect(const typename Protocol::endpoint &endpoint)
void handleAsyncWrite(const boost::system::error_code &error, TransmissionQueue::iterator queueItem)
void resolveHandler(const boost::system::error_code &error, typename Protocol::resolver::iterator endpoint, const shared_ptr< typename Protocol::resolver > &)
bool m_connectionInProgress
Protocol::socket m_socket
uint8_t m_inputBuffer[MAX_NDN_PACKET_SIZE]
StreamTransportWithResolverImpl< BaseTransport, Protocol > Impl
void send(const Block &header, const Block &payload)
boost::asio::deadline_timer m_connectTimer
bool processAll(uint8_t *buffer, size_t &offset, size_t nBytesAvailable)
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
StreamTransportWithResolverImpl(BaseTransport &transport, boost::asio::io_service &ioService)