Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
Public Member Functions | List of all members
transport::interface::ConsumerSocket::ReadCallback Class Referenceabstract

#include <socket_consumer.h>

Inheritance diagram for transport::interface::ConsumerSocket::ReadCallback:
Inheritance graph
[legend]

Public Member Functions

virtual bool isBufferMovable () noexcept
 
virtual void getReadBuffer (uint8_t **application_buffer, size_t *max_length)=0
 
virtual void readDataAvailable (size_t length) noexcept=0
 
virtual size_t maxBufferSize () const
 
virtual void readBufferAvailable (std::unique_ptr< utils::MemBuf > &&buffer) noexcept
 
virtual void readError (const std::error_code ec) noexcept=0
 
virtual void readSuccess (std::size_t total_size) noexcept=0
 

Detailed Description

The ReadCallback is a class which can be used by the transport for both querying the application needs and notifying events.

Beware that the methods of this class will be called synchronously while the transport is working, so the operations the application is performing on the data retrieved should be executed in another thread in an asynchronous manner. Blocking one of these callbacks means blocking the transport.

Member Function Documentation

◆ getReadBuffer()

virtual void transport::interface::ConsumerSocket::ReadCallback::getReadBuffer ( uint8_t **  application_buffer,
size_t *  max_length 
)
pure virtual

This method will be called by the transport when the content is available. The application can then allocate its own buffer and provide the address to the transport, which will use it for writing the data. Note that if the application won't allocate enough memory this method will be called several times, until the internal read buffer will be emptied. For ensuring this method will be called once, applications should allocate at least maxBufferSize() bytes.

Parameters
application_buffer- Pointer to the application's buffer.
max_length- The length of the application buffer.

◆ isBufferMovable()

virtual bool transport::interface::ConsumerSocket::ReadCallback::isBufferMovable ( )
inlinevirtualnoexcept

This API will specify to the transport whether the buffer should be allocated by the application (and then the retrieved content will be copied there) or the transport should allocate the buffer and "move" it to the application. In other words, if isBufferMovable return true, the transport will transfer the ownership of the read buffer to the application, without performing an additional copy, while if it returns false the transport will use the getReadBuffer API.

By default this method returns true.

◆ maxBufferSize()

virtual size_t transport::interface::ConsumerSocket::ReadCallback::maxBufferSize ( ) const
inlinevirtual

This method will be called by the transport for understanding how many bytes it should read before notifying the application.

By default it reads 64 KB.

◆ readBufferAvailable()

virtual void transport::interface::ConsumerSocket::ReadCallback::readBufferAvailable ( std::unique_ptr< utils::MemBuf > &&  buffer)
inlinevirtualnoexcept

This method will be called by the transport iff (isBufferMovable == true). The unique_ptr underlines the fact that the ownership of the buffer is being transferred to the application.

Parameters
buffer- The buffer

◆ readDataAvailable()

virtual void transport::interface::ConsumerSocket::ReadCallback::readDataAvailable ( size_t  length)
pure virtualnoexcept

This method will be called by the transport after calling getReadBuffer, in order to notify the application that length bytes are available in the buffer. The max_length size of the buffer could be larger than the actual amount of bytes written.

Parameters
length- The number of bytes placed in the buffer.

◆ readError()

virtual void transport::interface::ConsumerSocket::ReadCallback::readError ( const std::error_code  ec)
pure virtualnoexcept

readError() will be invoked if an error occurs reading from the transport.

Parameters
ec- An error code describing the error.

◆ readSuccess()

virtual void transport::interface::ConsumerSocket::ReadCallback::readSuccess ( std::size_t  total_size)
pure virtualnoexcept

This callback will be invoked when the whole content is retrieved. The transport itself knows when a content is retrieved (since it is not an opaque bytestream like TCP), and the transport itself is able to tell the application when the transfer is done.


The documentation for this class was generated from the following file: