sptk2 logo
SPTK Home Page
Public Member Functions | List of all members
sptk::TCPSocketReader Class Reference

#include <TCPSocket.h>

Inheritance diagram for sptk::TCPSocketReader:
sptk::Buffer sptk::BufferStorage

Public Member Functions

 TCPSocketReader (BaseSocket &socket, size_t bufferSize=16384)
 
void open ()
 
void close () noexcept
 
size_t read (uint8_t *destination, size_t sz, char delimiter, bool read_line, struct sockaddr_in *from=nullptr)
 
size_t readLine (Buffer &dest, char delimiter)
 
size_t availableBytes () const
 
void readMoreFromSocket (int availableBytes)
 
- Public Member Functions inherited from sptk::Buffer
 Buffer (const String &str)
 
 Buffer (const Buffer &other)=default
 
 Buffer (Buffer &&other) noexcept=default
 
 ~Buffer () noexcept override=default
 
Bufferoperator= (Buffer &&other) DOESNT_THROW=default
 
Bufferoperator= (const Buffer &other)=default
 
void append (char ch) override
 
void append (const char *data, size_t sz=0) override
 
void append (const uint8_t *data, size_t sz) override
 
template<class T >
void append (T val)
 
void append (const std::string &str)
 
void append (const String &str)
 
void append (const Buffer &buffer)
 
uint8_t & operator[] (size_t index)
 
const uint8_t & operator[] (size_t index) const
 
bool operator== (const Buffer &other) const
 
bool operator!= (const Buffer &other) const
 
void loadFromFile (const fs::path &fileName)
 
void saveToFile (const fs::path &fileName) const
 
Bufferoperator= (const String &str)
 
Bufferoperator= (const char *str)
 
 operator String () const
 
 BufferStorage ()
 
 BufferStorage (size_t sz)
 
 BufferStorage (const BufferStorage &bufferStorage)=default
 
 BufferStorage (BufferStorage &&bufferStorage) noexcept=default
 
template<typename T >
 BufferStorage (const T *data, size_t sz)
 
- Public Member Functions inherited from sptk::BufferStorage
 BufferStorage ()
 
 BufferStorage (size_t sz)
 
 BufferStorage (const BufferStorage &bufferStorage)=default
 
 BufferStorage (BufferStorage &&bufferStorage) noexcept=default
 
virtual ~BufferStorage ()=default
 
BufferStorageoperator= (const BufferStorage &bufferStorage)=default
 
BufferStorageoperator= (BufferStorage &&bufferStorage) noexcept=default
 
template<typename T >
 BufferStorage (const T *data, size_t sz)
 
uint8_t * data ()
 
const uint8_t * data () const
 
const char * c_str () const
 
bool empty () const
 
virtual void checkSize (size_t sz)
 
template<typename T >
void set (const T *data, size_t sz)
 
void set (const BufferStorage &data)
 
void set (const String &data)
 
size_t capacity () const
 
size_t length () const
 
size_t bytes () const
 
void bytes (size_t b)
 
virtual void append (char ch)
 
virtual void append (const char *data, size_t sz=0)
 
virtual void append (const uint8_t *data, size_t sz)
 
void reset (size_t sz=0)
 
void fill (char ch, size_t count)
 
void erase (size_t offset, size_t length)
 

Additional Inherited Members

- Protected Member Functions inherited from sptk::BufferStorage
void adjustSize (size_t sz)
 
void allocate (size_t size)
 
void allocate (const uint8_t *data, size_t size)
 
void reallocate (size_t size)
 
void deallocate () noexcept
 
void init (const uint8_t *data, size_t size, size_t bytes)
 

Detailed Description

Buffered Socket reader.

Constructor & Destructor Documentation

◆ TCPSocketReader()

sptk::TCPSocketReader::TCPSocketReader ( BaseSocket socket,
size_t  bufferSize = 16384 
)
explicit

Constructor

Parameters
socketSocket to work with
bufferSizeThe desirable size of the internal buffer

Member Function Documentation

◆ availableBytes()

size_t sptk::TCPSocketReader::availableBytes ( ) const

Returns number of bytes available to read

◆ close()

void sptk::TCPSocketReader::close ( )
noexcept

Disconnects the reader from the socket handle, and compacts allocated memory

◆ open()

void sptk::TCPSocketReader::open ( )

Connects the reader to the socket handle

◆ read()

size_t sptk::TCPSocketReader::read ( uint8_t *  destination,
size_t  sz,
char  delimiter,
bool  read_line,
struct sockaddr_in *  from = nullptr 
)

Performs the buffered read

Parameters
destinationDestination buffer
szSize of the destination buffer
delimiterLine delimiter
read_lineTrue if we want to read one line (ended with CRLF) only
fromAn optional structure for source address
Returns
bytes read from the internal buffer

◆ readLine()

size_t sptk::TCPSocketReader::readLine ( Buffer dest,
char  delimiter 
)

Performs the buffered read of LF-terminated string

Parameters
destDestination buffer
delimiterLine delimiter
Returns
bytes read from the internal buffer

◆ readMoreFromSocket()

void sptk::TCPSocketReader::readMoreFromSocket ( int  availableBytes)

Read more (as much as we can) from socket into buffer

Parameters
availableBytesNumber of bytes already available in buffer

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

Fri Oct 14 2022 09:58:46: SPTK 5.4.1