libassa 3.5.1
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
ASSA::Streambuf Class Reference

Streambuf class. More...

#include <Streambuf.h>

Inheritance diagram for ASSA::Streambuf:
ASSA::io_ptrs ASSA::Socketbuf

Public Member Functions

virtual ~Streambuf ()
 
Streambufpubsetbuf (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 sbumpc ()
 This function should probably have been called `‘sgetc’'.
 
int sgetc ()
 This function returns the character after the get pointer, or EOF if the get pointer is at the end of the sequence.
 
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 &)
 
Streambufoperator= (const Streambuf &)
 
charbase () const
 Returns the lowest possible value for gptr() - the beginning of the get area.
 
chargptr () const
 Returns a pointer to the beginning of the get area, and thus to the next character to be fetched (if there are any).
 
charegptr () 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.
 
charpbase () const
 Returns a pointer to the beginning fo the space available for the put area, the lowest possible value for pptr().
 
charpptr () 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).
 
charepptr () 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 Streambufsetbuf (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 showmanyc ()
 The morphemes of showmanyc are "es-how-many-see",
not "show-man-ic".
 
virtual int xsgetn (char *b_, int len_)
 Assigns up to len_ characters to successive elements of the array whose first element is designated by b_.
 
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
charm_read_base
 
charm_read_ptr
 
charm_read_end
 
charm_write_base
 
charm_write_ptr
 
charm_write_end
 
charm_buf_base
 
charm_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 ( )
inlinevirtual

Definition at line 451 of file Streambuf.h.

453{
454 trace_with_mask("Streambuf::~Streambuf",STRMBUFTRACE);
455
456 if (!(m_flags & USER_BUF)) {
457 delete [] m_buf_base;
458 m_buf_base = m_buf_end = 0;
459 }
460}
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
char * m_buf_base
Definition Streambuf.h:41
char * m_buf_end
Definition Streambuf.h:42
@ 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 ( )
inlineprotected

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.

430{
431 trace_with_mask("Streambuf::Streambuf",STRMBUFTRACE);
432
433 init ();
434}

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

◆ Streambuf() [2/2]

ASSA::Streambuf::Streambuf ( const Streambuf )
protected

Member Function Documentation

◆ base()

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

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

Definition at line 463 of file Streambuf.h.

465{
466 trace_with_mask("Streambuf::base",STRMBUFTRACE);
467
468 return m_read_base;
469}
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 ( )
protectedvirtual

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.

235{
236 trace_with_mask("Streambuf::doallocate",STRMBUFTRACE);
237
238 char* buf;
239 buf = new char [1024];
240 if (buf == NULL) {
241 return EOF;
242 }
243 setb (buf, buf+1024, 1);
244
245 return 1;
246}
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
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
inlineprotected

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.

483{
484 trace_with_mask("Streambuf::egptr",STRMBUFTRACE);
485
486 return m_read_end;
487}
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
inlineprotected

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.

508{
509 trace_with_mask("Streambuf::epptr",STRMBUFTRACE);
510 return m_write_end;
511}
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
inlineprotected

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.

474{
475 trace_with_mask("Streambuf::gptr",STRMBUFTRACE);
476
477 return m_read_ptr;
478}
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.

400{
401 trace_with_mask("Streambuf::in_avail",STRMBUFTRACE);
402
403 return m_read_end - m_read_ptr;
404}

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

Referenced by ASSA::IPv4Socket::clone(), ASSA::IPv4Socket::close(), and ASSA::IPv4Socket::in_avail().

◆ init()

void ASSA::Streambuf::init ( )
inlineprotected

◆ operator=()

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

◆ overflow()

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

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.

608{
609 trace_with_mask("Streambuf::overflow",STRMBUFTRACE);
610
611 return (EOF);
612}

References ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by sputc(), and xsputn().

◆ pbase()

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

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.

492{
493 trace_with_mask("Streambuf::pbase",STRMBUFTRACE);
494 return m_write_base;
495}

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_)
inlineprotected

Advances the next pointer for the output sequence by n_.

Definition at line 514 of file Streambuf.h.

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

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
inlineprotected

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.

500{
501 trace_with_mask("Streambuf::pptr",STRMBUFTRACE);
502 return m_write_ptr;
503}

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.

382{
383 trace_with_mask("Streambuf::pubsetbuf",STRMBUFTRACE);
384
385 return setbuf (s_, n_);
386}
virtual Streambuf * setbuf(char *p_, int len_)
Performs an operation that is defined separately for each class derived from Streambuf.

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.

391{
392 trace_with_mask("Streambuf::pubsync",STRMBUFTRACE);
393
394 return sync ();
395}
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.

◆ sbumpc()

int ASSA::Streambuf::sbumpc ( )
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.

Definition at line 538 of file Streambuf.h.

540{
541 trace_with_mask("Streambuf::sbumpc",STRMBUFTRACE);
542
543 return (m_read_ptr >= m_read_end ? uflow ()
544 : *(unsigned char *) m_read_ptr++);
545}
virtual int uflow()
Reads the characters from the input sequence, if possible, and moves the stream position past it,...

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

Referenced by ASSA::IPv4Socket::close(), and ASSA::IPv4Socket::read().

◆ 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.

81{
82 trace_with_mask("Streambuf::setb",STRMBUFTRACE);
83
84 if (m_buf_base && !(m_flags & USER_BUF))
85 delete m_buf_base;
86
87 m_buf_base = b_;
88 m_buf_end = eb_;
89
90 if (del_)
91 m_flags &= ~ USER_BUF; // clear bit
92 else
93 m_flags |= USER_BUF; // set bit
94
95 dump ();
96}
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_ 
)
protectedvirtual

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.

101{
102 trace_with_mask("Streambuf::setb",STRMBUFTRACE);
103
104 if (sync () == EOF) // Flush out all pending bytes before
105 return NULL; // resetting buffer. Also, first time around,
106 // calling sync() suppose to set put area
107 // pointers.
108
109 if (p_ == NULL || len_ == 0) {
110 DL((STRMBUF,"Unbuffered IO set.\n"));
111 unbuffered (1);
112 // We do it from doalloc instead - vlg
113 // setb (m_shortbuf, m_shortbuf+1, 0);
114 }
115 else {
116 DL((STRMBUF,"Buffered IO set.\n"));
117 unbuffered (0);
118 setb (p_, p_ + len_, 0);
119 }
120 setp (0, 0);
121 setg (0, 0, 0);
122
123 return this;
124}
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273
void setp(char *pbeg_, char *pend_)
Set put area pointers.
Definition Streambuf.h:588
void setg(char *gbeg_, char *gnext_, char *gend_)
Set get area pointers.
Definition Streambuf.cpp:69
@ 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

◆ setp()

void ASSA::Streambuf::setp ( char pbeg_,
char pend_ 
)
inlineprotected

Set put area pointers.

Definition at line 587 of file Streambuf.h.

589{
590 trace_with_mask("Streambuf::setp",STRMBUFTRACE);
591
592 m_write_base = m_write_ptr = pbeg_;
593 m_write_end = pend_;
594}

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 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.

550{
551 trace_with_mask("Streambuf::sgetc",STRMBUFTRACE);
552
553 return (m_read_ptr >= m_read_end && underflow () == EOF
554 ? EOF : *(unsigned char*) m_read_ptr);
555}
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.

560{
561 trace_with_mask("Streambuf::sgetn",STRMBUFTRACE);
562
563 return xsgetn (data_, len_);
564}
virtual int xsgetn(char *b_, int len_)
Assigns up to len_ characters to successive elements of the array whose first element is designated b...

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

Referenced by ASSA::IPv4Socket::read().

◆ showmanyc()

int ASSA::Streambuf::showmanyc ( )
inlineprotectedvirtual

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.’'

Reimplemented in ASSA::Socketbuf.

Definition at line 530 of file Streambuf.h.

532{
533 trace_with_mask("Streambuf::showmanyc",STRMBUFTRACE);
534 return -1;
535}

References ASSA::STRMBUFTRACE, and trace_with_mask.

◆ 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.

58{
59 trace_with_mask("Streambuf::snextc",STRMBUFTRACE);
60
61 if (m_read_ptr >= m_read_end && underflow () == EOF) {
62 return EOF;
63 }
64 return m_read_ptr++, sgetc ();
65}
int sgetc()
This function returns the character after the get pointer, or EOF if the get pointer is at the end of...
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.

569{
570 trace_with_mask("Streambuf::sputc",STRMBUFTRACE);
571
572 return (m_write_ptr >= m_write_end
573 ? overflow (c_)
574 : (unsigned char) (*m_write_ptr++ = c_));
575}
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.

Referenced by ASSA::IPv4Socket::write().

◆ 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.

580{
581 trace_with_mask("Streambuf::sputn",STRMBUFTRACE);
582
583 return xsputn (b_, len_);
584}
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).

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

Referenced by ASSA::IPv4Socket::write().

◆ sync()

int ASSA::Streambuf::sync ( )
inlineprotectedvirtual

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.

524{
525 trace_with_mask("Streambuf::sync",STRMBUFTRACE);
526 return 0;
527}

References ASSA::STRMBUFTRACE, and trace_with_mask.

Referenced by pubsync(), and setbuf().

◆ uflow()

int Streambuf::uflow ( )
protectedvirtual

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.

173{
174 trace_with_mask("Streambuf::uflow",STRMBUFTRACE);
175
176 if (underflow () == EOF)
177 return EOF;
178 dump ();
179 return *(unsigned char *) m_read_ptr++;
180}

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

Referenced by sbumpc().

◆ unbuffered() [1/2]

int ASSA::Streambuf::unbuffered ( )
inline
Returns
true if unbuffered, false otherwise

Definition at line 407 of file Streambuf.h.

409{
410 trace_with_mask("Streambuf::unbuffered",STRMBUFTRACE);
411
412 return m_flags & UNBUFFERED ? 1 : 0;
413}

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

Referenced by ASSA::Socketbuf::flush_output(), ASSA::Socketbuf::overflow(), 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.

418{
419 trace_with_mask("Streambuf::unbuffered",STRMBUFTRACE);
420
421 if (i_)
422 m_flags |= UNBUFFERED; // set
423 else
424 m_flags &= ~ UNBUFFERED; // unset
425}

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

Referenced by ASSA::IPv4Socket::read(), and ASSA::IPv4Socket::write().

◆ underflow()

int ASSA::Streambuf::underflow ( )
inlineprotectedvirtual

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.

599{
600 trace_with_mask("Streambuf::underflow",STRMBUFTRACE);
601
602 return (EOF);
603}

References ASSA::STRMBUFTRACE, and trace_with_mask.

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

◆ xsgetn()

int Streambuf::xsgetn ( char b_,
int  len_ 
)
protectedvirtual

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.

129{
130 trace_with_mask("Streambuf::xsgetn",STRMBUFTRACE);
131
132 /*
133 Get area is empty and nothing is on the socket.
134 */
135 int count = m_read_end - m_read_ptr; // Bytes in Get area
136
137 if (count == 0 && underflow () == EOF) {
138 DL((STRMBUFTRACE,"returning %d. count: %d\n", EOF));
139 return EOF;
140 }
141 count = m_read_end - m_read_ptr; // Adjusted bytes in Get area
142
143 DL((STRMBUFTRACE,"Adjusted bytes in Get Area: %d\n",count));
144
145 if (count > len_) {
146 count = len_;
147 }
148
149 if (count <= 0) {
150 count = 0; // Peer closed connection
151 }
152 else if (count > 20) {
154 m_read_ptr += count;
155 }
156 else {
157 char* s = data_;
158 char* p = m_read_ptr;
159 int i = count;
160 while (i-- > 0) {
161 *s++ = *p++;
162 }
163 m_read_ptr = p;
164 }
165 DL((STRMBUFTRACE,"Transferred %d bytes to user-space buffer\n", count));
166
167 return (count);
168}

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_ 
)
protectedvirtual

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.

185{
186 trace_with_mask("Streambuf::xsputn",STRMBUFTRACE);
187
188 const char* s = data_;
189 int more = len_;
190 if (more <= 0) {
191 return 0;
192 }
193
194 for (;;) {
195 int count = m_write_end - m_write_ptr; // Space available
196
197 if (count > 0) {
198
199 if (count > more) // Enough buffer space
200 count = more;
201
202 if (count > 20) {
204 s += count;
206 }
207 else if (count <= 0) {
208 count = 0;
209 }
210 else {
211 char* p = m_write_ptr;
212 int i;
213
214 for (i=count; --i >= 0;) {
215 *p++ = *s++;
216 }
217 m_write_ptr = p;
218 }
219 more -= count;
220 } // if (count>0)
221
222 if (more == 0 || overflow ((unsigned char) *s++) == EOF) {
223 break;
224 }
225 more--;
226
227 } // for (;;)
228
229 return (len_ - more);
230}

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: