22 #ifndef NDN_TRANSPORT_DETAIL_STREAM_TRANSPORT_IMPL_HPP 23 #define NDN_TRANSPORT_DETAIL_STREAM_TRANSPORT_IMPL_HPP 27 #include <boost/asio/steady_timer.hpp> 28 #include <boost/asio/write.hpp> 40 template<
typename BaseTransport,
typename Protocol>
41 class StreamTransportImpl :
public std::enable_shared_from_this<StreamTransportImpl<BaseTransport, Protocol>>
56 connect(
const typename Protocol::endpoint& endpoint)
66 m_connectTimer.async_wait([
self = this->shared_from_this()] (
const auto& error) {
67 self->connectTimeoutHandler(error);
71 m_socket.async_connect(endpoint, [
self = this->shared_from_this()] (
const auto& error) {
72 self->connectHandler(error);
81 boost::system::error_code error;
120 sequence.push_back(wire);
128 sequence.push_back(header);
129 sequence.push_back(payload);
187 handleAsyncWrite(
const boost::system::error_code& error, TransmissionQueue::iterator queueItem)
190 if (error == boost::system::errc::operation_canceled) {
221 if (error == boost::system::errc::operation_canceled) {
232 std::size_t offset = 0;
255 while (offset < nBytesAvailable) {
258 std::tie(isOk, element) =
Block::fromBuffer(buffer + offset, nBytesAvailable - offset);
263 offset += element.
size();
283 #endif // NDN_TRANSPORT_DETAIL_STREAM_TRANSPORT_IMPL_HPP
void connectHandler(const boost::system::error_code &error)
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to parse Block from a wire buffer.
void handleAsyncWrite(const boost::system::error_code &error, TransmissionQueue::iterator queueItem)
std::list< Block > BlockSequence
StreamTransportImpl(BaseTransport &transport, boost::asio::io_service &ioService)
void send(const Block &header, const Block &payload)
Represents a TLV element of NDN packet format.
Implementation detail of a Boost.Asio-based stream-oriented transport.
void send(BlockSequence &&sequence)
size_t size() const
Return the size of the encoded wire, i.e.
Protocol::socket m_socket
boost::asio::steady_timer m_connectTimer
void handleAsyncReceive(const boost::system::error_code &error, std::size_t nBytesRecvd)
void send(const Block &wire)
void connectTimeoutHandler(const boost::system::error_code &error)
std::list< BlockSequence > TransmissionQueue
uint8_t m_inputBuffer[MAX_NDN_PACKET_SIZE]
TransmissionQueue m_transmissionQueue
bool processAllReceived(uint8_t *buffer, size_t &offset, size_t nBytesAvailable)
BaseTransport & m_transport
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size
void connect(const typename Protocol::endpoint &endpoint)