SatCat5
satcat5::io::BufferedStream Class Referencefinal

Detailed Description

Copy bytes from a Readable source to a network address.

Given a buffered source of data and a maximum chunk size, read data in chunks and stream each chunk to a net::Address. The source is a byte-stream that ignores packet boundaries. For a similiar class that retains packet boundaries,

See also
BufferedPackets.

Usage is similar to BufferedCopy, but with improved controls for packetizing the raw stream. Two thresholds control the length of outgoing packets:

  • Threshold "max_chunk" is the absolute maximum length. i.e., Outgoing packets MUST NOT exceed max_chunk bytes.
  • Threshold "min_txnow" sets the preferred minimum length. i.e., Outgoing packets SHOULD be at least min_txnow bytes, but MAY be smaller if incoming data has slowed or stopped.

To prevent trailing data from becoming stuck, a timeout allows transmission of smaller chunks as follows. With N as the number of bytes available from the Readable source:

  • If N >= max_chunk: Transmit max_chunk bytes immediately.
  • Optionally, if N >= min_txnow: Transmit N bytes immediately. (This condition is ignored if min_txnow >= max_chunk.)
  • Otherwise: Wait for transmit timeout, then transmit N bytes. (This condition is ignored if the trantmit timeout is zero.)

Definition at line 124 of file io_buffer.h.

#include <io_buffer.h>

Inheritance diagram for satcat5::io::BufferedStream:
[legend]
Collaboration diagram for satcat5::io::BufferedStream:
[legend]

Public Member Functions

 BufferedStream (satcat5::io::Readable *src, satcat5::net::Address *dst, unsigned max_chunk=512, unsigned min_txnow=UINT_MAX)
 Set source, destination, APID, and chunk-size. More...
 
void set_timeout (unsigned msec)
 Set packetization timeout, in milliseconds. More...
 

Protected Member Functions

void data_rcvd (satcat5::io::Readable *src) override
 The data_rcvd() callback is polled whenever data is available. More...
 
void data_unlink (satcat5::io::Readable *src) override
 Unlink this EventListener from the designated source, because the designated Readable object is being destroyed. More...
 

Protected Attributes

satcat5::io::Readablem_src
 
satcat5::net::Address *const m_dst
 
const unsigned m_max_chunk
 
const unsigned m_min_txnow
 
unsigned m_timeout_msec
 
satcat5::util::TimeVal m_tref
 

Constructor & Destructor Documentation

◆ BufferedStream()

BufferedStream::BufferedStream ( satcat5::io::Readable src,
satcat5::net::Address dst,
unsigned  max_chunk = 512,
unsigned  min_txnow = UINT_MAX 
)

Set source, destination, APID, and chunk-size.

Default sets max_chunk to 512 bytes and ignores min_txnow.

Definition at line 51 of file io_buffer.cc.

Member Function Documentation

◆ data_rcvd()

void BufferedStream::data_rcvd ( satcat5::io::Readable src)
overrideprotectedvirtual

The data_rcvd() callback is polled whenever data is available.

A pointer is provided to assist handlers with multiple sources. Child objects of io::EventListener MUST override this method.

Implements satcat5::io::EventListener.

Definition at line 72 of file io_buffer.cc.

◆ data_unlink()

void BufferedStream::data_unlink ( satcat5::io::Readable src)
overrideprotectedvirtual

Unlink this EventListener from the designated source, because the designated Readable object is being destroyed.

Child objects of io::EventListener MAY override this method if action is required.

Reimplemented from satcat5::io::EventListener.

Definition at line 99 of file io_buffer.cc.

◆ set_timeout()

void satcat5::io::BufferedStream::set_timeout ( unsigned  msec)
inline

Set packetization timeout, in milliseconds.

If the timeout is zero, copy only full-size chunks.

Definition at line 139 of file io_buffer.h.


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