Loading...
Searching...
No Matches
ASSA::Streambuf Class Reference

Streambuf class. More...

`#include <Streambuf.h>`

Inheritance diagram for ASSA::Streambuf:

## Public Member Functions

virtual | ~Streambuf ()
Streambuf * | pubsetbuf (char *s_, int n_)
| Set buffer.
int | pubsync ()
int | in_avail ()
| This function returns the number of characters immediately available in the get area.
int | snextc ()
| This function moves the get pointer forward one position, then returns the character after the get pointer's new position.
int | sgetc ()
| This function should probably have been called ``sgetc''.
int | sgetn (char *b_, int len_)
| This function gets the next len_ characters following the get pointer, copying them to the char array pointed to by b_; it advances the get pointer past the last character fetched.
int | sputc (char c_)
| This function stores c just after the put pointer, and advances the pointer one position, possibly extending the sequence.
int | sputn (char *b_, int len_)
| From the location pointed to by ptr, stores exactly len characters after the put pointer, advancing the put pointer just past the last character.
void | unbuffered (int i_)
| If i_ is non-zero, then all IO operations are buffered.
int | unbuffered ()
Public Member Functions inherited from ASSA::io_ptrs
| io_ptrs ()
void | dump () const

## Static Public Attributes

static const int | MAXTCPFRAMESZ = 65536
| Size of the internal input/output buffer.

## Protected Member Functions

| Streambuf ()
| The default constructor is protected for class Streambuf to asssure that only objects for classes derived from this class may be constructed.
| Streambuf (const Streambuf &)
Streambuf & | operator= (const Streambuf &)
char * | base () const
| Returns the lowest possible value for gptr() - the beginning of the get area.
char * | gptr () const
| Returns a pointer to the beginning of the get area, and thus to the next character to be fetched (if there are any).
char * | egptr () const
| Returns a pointer just past the end of the get area, the maximum possible value for gptr().
void | setg (char *gbeg_, char *gnext_, char *gend_)
| Set get area pointers.
char * | pbase () const
| Returns a pointer to the beginning fo the space available for the put area, the lowest possible value for pptr().
char * | pptr () const
| Returns a pointer to the beginning of the put area, and thus to the location of the next character that is stored (if possible).
char * | epptr () const
| Returns a pointer just past the end of the put area, the maximum possible value for pptr().
void | setp (char *pbeg_, char *pend_)
| Set put area pointers.
void | pbump (int n_)
| Advances the next pointer for the output sequence by n_.
void | setb (char *b_, char *eb_, int del_)
| Establish the reserve area (buffer).
void | init ()
virtual Streambuf * | setbuf (char *p_, int len_)
| Performs an operation that is defined separately for each class derived from Streambuf.
virtual int | sync ()
| This function synchronizes the streambuf with its actual stream of characters.
virtual int | xsgetn (char *b_, int len_)
| The morphemes of showmanyc are "es-how-many-see", not "show-man-ic".
virtual int | underflow ()
| This function is called to supply characters for input (from some source) when the get area is empty, although it may be called at other times.
virtual int | uflow ()
| Reads the characters from the input sequence, if possible, and moves the stream position past it, as follows:
virtual int | xsputn (const char *b_, int len_)
| Writes up to len_ characters to the output sequence as if by repeated calls to sputc (c).
virtual int | overflow (int c=EOF)
| This function is called to consume characters (flush them to output), typically when the put area is full and an attempt is made to store another character.
virtual int | doallocate ()
| This function is called by allocate when unbuffered() is zero and base() is zero.

## Additional Inherited Members

Public Types inherited from ASSA::io_ptrs
enum | { USER_BUF = 1 , UNBUFFERED = 2 , EOF_SEEN = 4 , ERR_SEEN = 8 }
Public Attributes inherited from ASSA::io_ptrs
char * | m_read_base
char * | m_read_ptr
char * | m_read_end
char * | m_write_base
char * | m_write_ptr
char * | m_write_end
char * | m_buf_base
char * | m_buf_end
int | m_flags
char | m_shortbuf [1]

## Detailed Description

Streambuf class.

Streambuf class is based on Standard C++ iostream streambuf class.

Extending std::streambuf is always pain due to the obscurity and complexity of its interface, and in general, lack of the source code needed to efficiently understand its implementation.

I wrote my own Streambuf that implements a subset of std::streambuf functions - a bare minimum to get by for Socket buffering.

The buffer of a Streambuf may be considered to have three parts: the get area, the put area, and the reserve area (which is the same as the buffer area).

The get area contains the characters immediately available for input.

The put area holds characters stored for output but not yet consumed by (flushed to) their ultimate destination. The get and put areas may be disjoint or may overlap (in my implementation they are two disjoined buffers). The reserve area is the entire buffer, overlapped by the get and put areas (in my implementation, reserve area covers get area only).
The get and put areas may expand into the remainder of the reserve area. In the course of input and output operations, the sizes of the get and put areas expand and shrink, always bounded by the total buffer size.

Definition at line 90 of file Streambuf.h.

## Constructor & Destructor Documentation

## ~Streambuf()

ASSA::Streambuf::~Streambuf | ( |  | ) |

inline virtual

Definition at line 451 of file Streambuf.h.

{
trace_with_mask("Streambuf::~Streambuf",STRMBUFTRACE);
if (!(m_flags & USER_BUF)) {
delete [] m_buf_base;
m_buf_base = m_buf_end = 0;
}
}
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
ASSA::io_ptrs::m_buf_base
char * m_buf_base
Definition Streambuf.h:41
ASSA::io_ptrs::m_buf_end
char * m_buf_end
Definition Streambuf.h:42
ASSA::io_ptrs::USER_BUF
@ USER_BUF
Definition Streambuf.h:44
ASSA::io_ptrs::m_flags
int m_flags
Definition Streambuf.h:46
ASSA::STRMBUFTRACE
@ STRMBUFTRACE
Extended Streambuf & friends messages.
Definition LogMask.h:46

References ASSA::io_ptrs::m_buf_base, ASSA::io_ptrs::m_buf_end, ASSA::io_ptrs::m_flags, ASSA::STRMBUFTRACE, trace_with_mask, and ASSA::io_ptrs::USER_BUF.

## Streambuf() [1/2]

ASSA::Streambuf::Streambuf | ( |  | ) |

inline protected

The default constructor is protected for class Streambuf to asssure that only objects for classes derived from this class may be constructed.

Definition at line 428 of file Streambuf.h.

{
trace_with_mask("Streambuf::Streambuf",STRMBUFTRACE);
init ();
}
ASSA::Streambuf::init
void init()
Definition Streambuf.h:438

References init(), ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by operator=(), and Streambuf().

## Streambuf() [2/2]

ASSA::Streambuf::Streambuf | ( | const Streambuf & |  | ) |

protected

References Streambuf().

## Member Function Documentation

## base()

char * ASSA::Streambuf::base | ( |  | ) | const

inline protected

Returns the lowest possible value for gptr() - the beginning of the get area.

Definition at line 463 of file Streambuf.h.

{
trace_with_mask("Streambuf::base",STRMBUFTRACE);
return m_read_base;
}
ASSA::io_ptrs::m_read_base
char * m_read_base
Definition Streambuf.h:33

References ASSA::io_ptrs::m_read_base, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::underflow().

## doallocate()

int Streambuf::doallocate | ( |  | ) |

protected virtual

This function is called by allocate when unbuffered() is zero and base() is zero.

It attempts to make a buffer of suitable size available. On success it must call setb to establish the reserve area, then return a value greater than zero. On failure it returns EOF. The default behavior is to allocate a buffer using new.

Reimplemented in ASSA::Socketbuf.

Definition at line 234 of file Streambuf.cpp.

{
trace_with_mask("Streambuf::doallocate",STRMBUFTRACE);
char* buf;
buf = new char [1024];
if (buf == NULL) {
return EOF;
}
setb (buf, buf+1024, 1);
return 1;
}
ASSA::Streambuf::setb
void setb(char *b_, char *eb_, int del_)
Establish the reserve area (buffer).
Definition Streambuf.cpp:80

References setb(), ASSA::STRMBUFTRACE, and trace_with_mask.

## egptr()

char * ASSA::Streambuf::egptr | ( |  | ) | const

inline protected

Returns a pointer just past the end of the get area, the maximum possible value for gptr().

Definition at line 481 of file Streambuf.h.

{
trace_with_mask("Streambuf::egptr",STRMBUFTRACE);
return m_read_end;
}
ASSA::io_ptrs::m_read_end
char * m_read_end
Definition Streambuf.h:35

References ASSA::io_ptrs::m_read_end, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::underflow().

## epptr()

char * ASSA::Streambuf::epptr | ( |  | ) | const

inline protected

Returns a pointer just past the end of the put area, the maximum possible value for pptr().

The space from pptr() through epptr() is immediately available for storing characters without a flush operation.

Definition at line 506 of file Streambuf.h.

{
trace_with_mask("Streambuf::epptr",STRMBUFTRACE);
return m_write_end;
}
ASSA::io_ptrs::m_write_end
char * m_write_end
Definition Streambuf.h:39

References ASSA::io_ptrs::m_write_end, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::flush_output(), and ASSA::Socketbuf::overflow().

## gptr()

char * ASSA::Streambuf::gptr | ( |  | ) | const

inline protected

Returns a pointer to the beginning of the get area, and thus to the next character to be fetched (if there are any).

The characters immediately available are from gptr() through egptr()-1. If egptr()<=gptr(), no char- acters are available.

Definition at line 472 of file Streambuf.h.

{
trace_with_mask("Streambuf::gptr",STRMBUFTRACE);
return m_read_ptr;
}
ASSA::io_ptrs::m_read_ptr
char * m_read_ptr
Definition Streambuf.h:34

References ASSA::io_ptrs::m_read_ptr, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::underflow().

## in_avail()

int ASSA::Streambuf::in_avail | ( |  | ) |

inline

This function returns the number of characters
immediately available in the get area.

It is certain that i characters may be fetched without error, and without accessing any external device.

Definition at line 398 of file Streambuf.h.

{
trace_with_mask("Streambuf::in_avail",STRMBUFTRACE);
return m_read_end - m_read_ptr;
}

References ASSA::io_ptrs::m_read_end, ASSA::io_ptrs::m_read_ptr, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socket::getBytesAvail().

## init()

void ASSA::Streambuf::init | ( |  | ) |

inline protected

Definition at line 437 of file Streambuf.h.

{
trace_with_mask("Streambuf::init", STRMBUFTRACE);
m_read_base = m_read_ptr = m_read_end = 0;
m_write_base = m_write_ptr = m_write_end = 0;
m_buf_base = m_buf_end = 0;
m_flags = 0;
m_shortbuf[0] = 0;
}
ASSA::io_ptrs::m_write_base
char * m_write_base
Definition Streambuf.h:37
ASSA::io_ptrs::m_shortbuf
char m_shortbuf[1]
Definition Streambuf.h:47
ASSA::io_ptrs::m_write_ptr
char * m_write_ptr
Definition Streambuf.h:38

References ASSA::io_ptrs::m_buf_base, ASSA::io_ptrs::m_buf_end, ASSA::io_ptrs::m_flags, ASSA::io_ptrs::m_read_base, ASSA::io_ptrs::m_read_end, ASSA::io_ptrs::m_read_ptr, ASSA::io_ptrs::m_shortbuf, ASSA::io_ptrs::m_write_base, ASSA::io_ptrs::m_write_end, ASSA::io_ptrs::m_write_ptr, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by Streambuf().

## operator=()

Streambuf & ASSA::Streambuf::operator= | ( | const Streambuf & |  | ) |

protected

References Streambuf().

## overflow()

int ASSA::Streambuf::overflow | ( | int | c = EOF | ) |

inline protected virtual

This function is called to consume characters (flush them to output), typically when the put area is full and an attempt is made to store another character.

If c is not EOF, overflow must either store or consume the character, following those already in the put area. It returns EOF on error, any other value on success. The default behavior of the base class version is undefined, so each derived class must define its own overflow. The normal action for a derived class version is to consume the characters in the put area (those between pbase() and pptr()), call setp() to set up a new put area, then store c (using sputc()) if it is not EOF.

Reimplemented in ASSA::Socketbuf.

Definition at line 606 of file Streambuf.h.

{
trace_with_mask("Streambuf::overflow",STRMBUFTRACE);
return (EOF);
}

References ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by sputc(), and xsputn().

## pbase()

char * ASSA::Streambuf::pbase | ( |  | ) | const

inline protected

Returns a pointer to the beginning fo the space available for the put area, the lowest possible value for pptr().

The area from pbase() through pptr()-1 represents characters which have been stored int the buffer but not yet consumed.

Definition at line 490 of file Streambuf.h.

{
trace_with_mask("Streambuf::pbase",STRMBUFTRACE);
return m_write_base;
}

References ASSA::io_ptrs::m_write_base, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::flush_output(), and ASSA::Socketbuf::overflow().

## pbump()

void ASSA::Streambuf::pbump | ( | int | n_ | ) |

inline protected

Advances the next pointer for the output sequence by n_.

Definition at line 514 of file Streambuf.h.

{
trace_with_mask("Streambuf::pbump",STRMBUFTRACE);
m_write_ptr += n_;
}

References ASSA::io_ptrs::m_write_ptr, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::flush_output(), and ASSA::Socketbuf::xput_char().

## pptr()

char * ASSA::Streambuf::pptr | ( |  | ) | const

inline protected

Returns a pointer to the beginning of the put area, and thus to the location of the next character that is stored (if possible).

Definition at line 498 of file Streambuf.h.

{
trace_with_mask("Streambuf::pptr",STRMBUFTRACE);
return m_write_ptr;
}

References ASSA::io_ptrs::m_write_ptr, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::flush_output(), ASSA::Socketbuf::overflow(), and ASSA::Socketbuf::xput_char().

## pubsetbuf()

Streambuf * ASSA::Streambuf::pubsetbuf | ( | char * | s_,
|  | int | n_ )

inline

Set buffer.

Returns
  setbuf(s_, n_)

Definition at line 380 of file Streambuf.h.

{
trace_with_mask("Streambuf::pubsetbuf",STRMBUFTRACE);
return setbuf (s_, n_);
}
ASSA::Streambuf::setbuf
virtual Streambuf * setbuf(char *p_, int len_)
Performs an operation that is defined separately for each class derived from Streambuf.
Definition Streambuf.cpp:100

References setbuf(), ASSA::STRMBUFTRACE, and trace_with_mask.

## pubsync()

int ASSA::Streambuf::pubsync | ( |  | ) |

inline

See also
  sync

Returns
  sync()

Definition at line 389 of file Streambuf.h.

{
trace_with_mask("Streambuf::pubsync",STRMBUFTRACE);
return sync ();
}
ASSA::Streambuf::sync
virtual int sync()
This function synchronizes the streambuf with its actual stream of characters.
Definition Streambuf.h:523

References ASSA::STRMBUFTRACE, sync(), and trace_with_mask.

## setb()

void Streambuf::setb | ( | char * | b_,
|  | char * | eb_,
|  | int | del_ )

protected

Establish the reserve area (buffer).

Set base() to b_, ebuf() to eb_. If del_ is non-zero, the buffer will be deleted whenever base() is changed by another call to setb(), or when Streambuf destructor is invoked. If del_ is zero, the buffer will not be deleted automatically.

Parameters

  b_ | pointer to the buffer's first byte
  eb_ | pointer to the byte one past the buffer's last byte
  del_ | 0 - external memory management, 1 - delete on swap/destruction

Definition at line 79 of file Streambuf.cpp.

{
trace_with_mask("Streambuf::setb",STRMBUFTRACE);
if (m_buf_base && !(m_flags & USER_BUF))
delete m_buf_base;
m_buf_base = b_;
m_buf_end = eb_;
if (del_)
m_flags &= ~ USER_BUF; // clear bit
else
m_flags |= USER_BUF; // set bit
dump ();
}
ASSA::io_ptrs::dump
void dump() const
Definition Streambuf.cpp:23

References ASSA::io_ptrs::dump(), ASSA::io_ptrs::m_buf_base, ASSA::io_ptrs::m_buf_end, ASSA::io_ptrs::m_flags, ASSA::STRMBUFTRACE, trace_with_mask, and ASSA::io_ptrs::USER_BUF.

Referenced by ASSA::Socketbuf::doallocate(), doallocate(), and setbuf().

## setbuf()

Streambuf * Streambuf::setbuf | ( | char * | p_,
|  | int | len_ )

protected virtual

Performs an operation that is defined separately for each class derived from Streambuf.

Default behavior is to set internal buffer to p_. If p_ is NULL or len_ is 0, then unbuffered I/O (one byte at a time) is assumed.

Parameters

  p_ | buffer to use
  len_ | length of the buffer

Definition at line 99 of file Streambuf.cpp.

{
trace_with_mask("Streambuf::setb",STRMBUFTRACE);
if (sync () == EOF) // Flush out all pending bytes before
return NULL; // resetting buffer. Also, first time around,
// calling sync() suppose to set put area
// pointers.
if (p_ == NULL || len_ == 0) {
DL((STRMBUF,"Unbuffered IO set.\n"));
unbuffered (1);
// We do it from doalloc instead - vlg
// setb (m_shortbuf, m_shortbuf+1, 0);
}
else {
DL((STRMBUF,"Buffered IO set.\n"));
unbuffered (0);
setb (p_, p_ + len_, 0);
}
setp (0, 0);
setg (0, 0, 0);
return this;
}
DL
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273
ASSA::Streambuf::setp
void setp(char *pbeg_, char *pend_)
Set put area pointers.
Definition Streambuf.h:588
ASSA::Streambuf::unbuffered
int unbuffered()
Definition Streambuf.h:408
ASSA::Streambuf::setg
void setg(char *gbeg_, char *gnext_, char *gend_)
Set get area pointers.
Definition Streambuf.cpp:69
ASSA::STRMBUF
@ STRMBUF
Class Streambuf & friends messages.
Definition LogMask.h:45

References DL, setb(), setg(), setp(), ASSA::STRMBUF, ASSA::STRMBUFTRACE, sync(), trace_with_mask, and unbuffered().

Referenced by pubsetbuf().

## setg()

void Streambuf::setg | ( | char * | gbeg_,
|  | char * | gnext_,
|  | char * | gend_ )

protected

Set get area pointers.

Definition at line 68 of file Streambuf.cpp.

{
trace_with_mask("Streambuf::setg",STRMBUFTRACE);
m_read_base = gbeg_;
m_read_ptr = gnext_;
m_read_end = gend_;
}

References ASSA::io_ptrs::m_read_base, ASSA::io_ptrs::m_read_end, ASSA::io_ptrs::m_read_ptr, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::doallocate(), setbuf(), and ASSA::Socketbuf::underflow().

## setp()

void ASSA::Streambuf::setp | ( | char * | pbeg_,
|  | char * | pend_ )

inline protected

Set put area pointers.

Definition at line 587 of file Streambuf.h.

{
trace_with_mask("Streambuf::setp",STRMBUFTRACE);
m_write_base = m_write_ptr = pbeg_;
m_write_end = pend_;
}

References ASSA::io_ptrs::m_write_base, ASSA::io_ptrs::m_write_end, ASSA::io_ptrs::m_write_ptr, ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by ASSA::Socketbuf::doallocate(), ASSA::Socketbuf::flush_output(), and setbuf().

## sgetc()

int ASSA::Streambuf::sgetc | ( |  | ) |

inline

This function should probably have been called ``sgetc''.

It moves the get pointer forward one posi- tion and returns the character it moved past. If the get pointer is currently at the end of the sequence, this function returns EOF. */ int sbumpc ();

/** This function returns the character after the get pointer, or EOF if the get pointer is at the end of the sequence. Despite its name, this function does NOT move the get pointer.

Definition at line 548 of file Streambuf.h.

{
trace_with_mask("Streambuf::sgetc",STRMBUFTRACE);
return (m_read_ptr >= m_read_end && underflow () == EOF
? EOF : *(unsigned char*) m_read_ptr);
}
ASSA::Streambuf::underflow
virtual int underflow()
This function is called to supply characters for input (from some source) when the get area is empty,...
Definition Streambuf.h:598

References ASSA::io_ptrs::m_read_end, ASSA::io_ptrs::m_read_ptr, ASSA::STRMBUFTRACE, trace_with_mask, and underflow().

Referenced by snextc().

## sgetn()

int ASSA::Streambuf::sgetn | ( | char * | b_,
|  | int | len_ )

inline

This function gets the next len_ characters following the get pointer, copying them to the char array pointed to by b_; it advances the get pointer past the last character fetched.

If fewer than len characters are left, it gets as many as are available.

Returns
  the number of characters fetched.

Definition at line 558 of file Streambuf.h.

{
trace_with_mask("Streambuf::sgetn",STRMBUFTRACE);
return xsgetn (data_, len_);
}
ASSA::Streambuf::xsgetn
virtual int xsgetn(char *b_, int len_)
The morphemes of showmanyc are "es-how-many-see", not "show-man-ic".
Definition Streambuf.cpp:128

References ASSA::STRMBUFTRACE, trace_with_mask, and xsgetn().

## snextc()

int Streambuf::snextc | ( |  | ) |

This function moves the get pointer forward one
position, then returns the character after the get pointer's new position.

If the get pointer is at the end of the sequence before or after the call to this function (no character is available), this function returns EOF. Example: Suppose the input buffer looks like this: abc|def where |' marks the position of the get pointer. This function will advance the get pointer and return e'.

Definition at line 56 of file Streambuf.cpp.

{
trace_with_mask("Streambuf::snextc",STRMBUFTRACE);
if (m_read_ptr >= m_read_end && underflow () == EOF) {
return EOF;
}
return m_read_ptr++, sgetc ();
}
ASSA::Streambuf::sgetc
int sgetc()
This function should probably have been called ``sgetc''.
Definition Streambuf.h:549

References ASSA::io_ptrs::m_read_end, ASSA::io_ptrs::m_read_ptr, sgetc(), ASSA::STRMBUFTRACE, trace_with_mask, and underflow().

## sputc()

int ASSA::Streambuf::sputc | ( | char | c_ | ) |

inline

This function stores c just after the put pointer, and advances the pointer one position, possibly extending the sequence.

It returns c, or EOF on error. What constitutes an error depends on the actual derived buffer class.

Definition at line 567 of file Streambuf.h.

{
trace_with_mask("Streambuf::sputc",STRMBUFTRACE);
return (m_write_ptr >= m_write_end
? overflow (c_)
: (unsigned char) (*m_write_ptr++ = c_));
}
ASSA::Streambuf::overflow
virtual int overflow(int c=EOF)
This function is called to consume characters (flush them to output), typically when the put area is ...
Definition Streambuf.h:607

References ASSA::io_ptrs::m_write_end, ASSA::io_ptrs::m_write_ptr, overflow(), ASSA::STRMBUFTRACE, and trace_with_mask.

## sputn()

int ASSA::Streambuf::sputn | ( | char * | b_,
|  | int | len_ )

inline

From the location pointed to by ptr, stores exactly len characters after the put pointer, advancing the put pointer just past the last character.

It returns the number of characters stored, which ought to be len. Fewer than len characters stored indicates some sort of error.

Definition at line 578 of file Streambuf.h.

{
trace_with_mask("Streambuf::sputn",STRMBUFTRACE);
return xsputn (b_, len_);
}
ASSA::Streambuf::xsputn
virtual int xsputn(const char *b_, int len_)
Writes up to len_ characters to the output sequence as if by repeated calls to sputc (c).
Definition Streambuf.cpp:184

References ASSA::STRMBUFTRACE, trace_with_mask, and xsputn().

## sync()

int ASSA::Streambuf::sync | ( |  | ) |

inline protected virtual

This function synchronizes the streambuf with its actual stream of characters.

The derived class version should flush any characters in the put area to their final destination, and if possible give back any characters in the input buffer to their source. It should return EOF on any error, zero on success. The default behavior of the base class version is to return zero if there are no pending input or output characters (in_avail() and out_waiting() are both zero), and return EOF otherwise.

Reimplemented in ASSA::Socketbuf.

Definition at line 522 of file Streambuf.h.

{
trace_with_mask("Streambuf::sync",STRMBUFTRACE);
return 0;
}

References ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by pubsync(), and setbuf().

## uflow()

int Streambuf::uflow | ( |  | ) |

protected virtual

Reads the characters from the input sequence, if possible, and moves the stream position past it, as follows:

1) If the input sequence has a read position available the function signals success by returning (unsigned char)*gnext++.

2) Otherwise, if the function can read the character x directly from the associated input sequence, it signals succes by returning (unsigned char) x. If the function makes a read position available, it also assigns x to *gnext.

The default behavior is to call underflow () and, if that function returns EOF or fails to make a read position available, return EOF. Otherwise, the function signals success by returning (unsigned char)*gnext++.

Definition at line 171 of file Streambuf.cpp.

{
trace_with_mask("Streambuf::uflow",STRMBUFTRACE);
if (underflow () == EOF)
return EOF;
dump ();
return *(unsigned char *) m_read_ptr++;
}

References ASSA::io_ptrs::dump(), ASSA::io_ptrs::m_read_ptr, ASSA::STRMBUFTRACE, trace_with_mask, and underflow().

## unbuffered() [1/2]

int ASSA::Streambuf::unbuffered | ( |  | ) |

inline

Returns
  true if unbuffered, false otherwise

Definition at line 407 of file Streambuf.h.

{
trace_with_mask("Streambuf::unbuffered",STRMBUFTRACE);
return m_flags & UNBUFFERED ? 1 : 0;
}
ASSA::io_ptrs::UNBUFFERED
@ UNBUFFERED
Definition Streambuf.h:44

References ASSA::io_ptrs::m_flags, ASSA::STRMBUFTRACE, trace_with_mask, and ASSA::io_ptrs::UNBUFFERED.

Referenced by setbuf(), ASSA::Socketbuf::Socketbuf(), and ASSA::Socketbuf::underflow().

## unbuffered() [2/2]

void ASSA::Streambuf::unbuffered | ( | int | i_ | ) |

inline

If i_ is non-zero, then all IO operations are buffered.

If i_ is zero, then unbuffered IO is performed (one character at a time.

Definition at line 416 of file Streambuf.h.

{
trace_with_mask("Streambuf::unbuffered",STRMBUFTRACE);
if (i_)
m_flags |= UNBUFFERED; // set
else
m_flags &= ~ UNBUFFERED; // unset
}

References ASSA::io_ptrs::m_flags, ASSA::STRMBUFTRACE, trace_with_mask, and ASSA::io_ptrs::UNBUFFERED.

Referenced by ASSA::Socketbuf::flush_output(), and ASSA::Socketbuf::overflow().

## underflow()

int ASSA::Streambuf::underflow | ( |  | ) |

inline protected virtual

This function is called to supply characters for input (from some source) when the get area is empty, although it may be called at other times.

If the get area is not empty, it should just return the first character (without advancing the get pointer). If the get area is empty, it should establish a new get area, aquire new input, and return the first character, if any. If no input characters are available, it should leave an empty get area and return EOF. The default behavior of the base class version is undefined, so each derived class must define its own underflow.

Reimplemented in ASSA::Socketbuf.

Definition at line 597 of file Streambuf.h.

{
trace_with_mask("Streambuf::underflow",STRMBUFTRACE);
return (EOF);
}

References ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by sgetc(), snextc(), uflow(), and xsgetn().

## xsgetn()

int Streambuf::xsgetn | ( | char * | b_,
|  | int | len_ )

protected virtual

The morphemes of showmanyc are "es-how-many-see",
not "show-man-ic".

Return an estimate of the number of characters available in the sequence, or -1. If it returns a positive value,
then successive calls to underflow() will not return EOF until at least that number of characters have been supplied.
If showmanyc() returns -1, then calls to underflow() or uflow() will fail. The intention is not only that these calls will not return EOF, but that they will return ``immediately.'' */ virtual int showmanyc ();

/** Assigns up to len_ characters to successive elements of the array whose first element is designated by b_. The characters assigned are read from the input sequence as if by repeated calls to sbumpc(). Assigning stops when either len_ characters have been assigned or a call to sbumpc() would return EOF.

Returns
  The number of characters assigned.

Definition at line 127 of file Streambuf.cpp.

{
trace_with_mask("Streambuf::xsgetn",STRMBUFTRACE);
/*
Get area is empty and nothing is on the socket.
*/
int count = m_read_end - m_read_ptr; // Bytes in Get area
if (count == 0 && underflow () == EOF) {
DL((STRMBUFTRACE,"returning %d. count: %d\n", EOF));
return EOF;
}
count = m_read_end - m_read_ptr; // Adjusted bytes in Get area
DL((STRMBUFTRACE,"Adjusted bytes in Get Area: %d\n",count));
if (count > len_) {
count = len_;
}
if (count <= 0) {
count = 0; // Peer closed connection
}
else if (count > 20) {
memcpy (data_, m_read_ptr, count);
m_read_ptr += count;
}
else {
char* s = data_;
char* p = m_read_ptr;
int i = count;
while (i-- > 0) {
*s++ = *p++;
}
m_read_ptr = p;
}
DL((STRMBUFTRACE,"Transferred %d bytes to user-space buffer\n", count));
return (count);
}

References DL, ASSA::io_ptrs::m_read_end, ASSA::io_ptrs::m_read_ptr, ASSA::STRMBUFTRACE, trace_with_mask, and underflow().

Referenced by sgetn().

## xsputn()

int Streambuf::xsputn | ( | const char * | b_,
|  | int | len_ )

protected virtual

Writes up to len_ characters to the output sequence as if by repeated calls to sputc (c).

The characters written are obtained from successive elements of the array whose first element is designated by b_. Writing stops when either len_ characters have been written or a call to sputc(c) would return EOF.

Returns
  The number of characters written.

Definition at line 183 of file Streambuf.cpp.

{
trace_with_mask("Streambuf::xsputn",STRMBUFTRACE);
const char* s = data_;
int more = len_;
if (more <= 0) {
return 0;
}
for (;;) {
int count = m_write_end - m_write_ptr; // Space available
if (count > 0) {
if (count > more) // Enough buffer space
count = more;
if (count > 20) {
memcpy (m_write_ptr, s, count);
s += count;
m_write_ptr += count;
}
else if (count <= 0) {
count = 0;
}
else {
char* p = m_write_ptr;
int i;
for (i=count; --i >= 0;) {
*p++ = *s++;
}
m_write_ptr = p;
}
more -= count;
} // if (count>0)
if (more == 0 || overflow ((unsigned char) *s++) == EOF) {
break;
}
more--;
} // for (;;)
return (len_ - more);
}

References ASSA::io_ptrs::m_write_end, ASSA::io_ptrs::m_write_ptr, overflow(), ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by sputn().

## Member Data Documentation

## MAXTCPFRAMESZ

const int ASSA::Streambuf::MAXTCPFRAMESZ = 65536

static

Size of the internal input/output buffer.

You can use this constant to do application code read/writes to the socket.

Definition at line 106 of file Streambuf.h.

Referenced by ASSA::Socketbuf::doallocate(), ASSA::Socketbuf::flush_output(), and ASSA::Socketbuf::underflow().

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

- Streambuf.h
- Streambuf.cpp