22 #ifndef NDN_TRANSPORT_STREAM_TRANSPORT_HPP 23 #define NDN_TRANSPORT_STREAM_TRANSPORT_HPP 31 template<
class BaseTransport,
class Protocol>
71 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while connecting to the forwarder"));
82 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while connecting to the forwarder"));
86 connect(
const typename Protocol::endpoint& endpoint)
107 boost::system::error_code error;
151 BlockSequence sequence;
152 sequence.push_back(wire);
168 BlockSequence sequence;
169 sequence.push_back(header);
170 sequence.push_back(payload);
189 if (error == boost::system::errc::operation_canceled) {
195 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while sending data to socket"));
212 processAll(uint8_t* buffer,
size_t& offset,
size_t nBytesAvailable)
214 while (offset < nBytesAvailable) {
217 std::tie(isOk, element) =
Block::fromBuffer(buffer + offset, nBytesAvailable - offset);
222 offset += element.
size();
232 if (error == boost::system::errc::operation_canceled) {
238 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"error while receiving data from socket"));
244 std::size_t offset = 0;
250 "input buffer full, but a valid TLV cannot be " 287 template<
class BaseTransport,
class Protocol>
301 const shared_ptr<typename Protocol::resolver>&)
305 if (error == boost::system::errc::operation_canceled)
308 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"Error during resolution of host or port"));
315 BOOST_THROW_EXCEPTION(
Transport::Error(error,
"Unable to resolve because host or port"));
318 this->
m_socket.async_connect(*endpoint,
323 connect(
const typename Protocol::resolver::query& query)
330 this->
m_connectTimer.expires_from_now(boost::posix_time::seconds(4));
334 shared_ptr<typename Protocol::resolver> resolver =
335 make_shared<typename Protocol::resolver>(ref(this->
m_socket.get_io_service()));
337 resolver->async_resolve(query, bind(&Impl::resolveHandler,
this, _1, _2, resolver));
345 #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)