ACE_Streambuf Class Reference

Create your custom streambuf by providing and ACE_*_Stream object to this template. I have tested it with ACE_SOCK_Stream and it should work fine for others as well. More...

#include <IOStream.h>

Inheritance diagram for ACE_Streambuf:

Inheritance graph
[legend]
Collaboration diagram for ACE_Streambuf:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual ~ACE_Streambuf (void)
ACE_Time_Valuerecv_timeout (ACE_Time_Value *tv=0)
 Get the current Time_Value pointer and provide a new one.

char * reset_put_buffer (char *newBuffer=0, u_int _streambuf_size=0, u_int _pptr=0)
u_int put_avail (void)
char * reset_get_buffer (char *newBuffer=0, u_int _streambuf_size=0, u_int _gptr=0, u_int _egptr=0)
u_int get_waiting (void)
u_int get_avail (void)
u_int streambuf_size (void)
 Query the streambuf for the size of its buffers.

u_char timeout (void)

Protected Member Functions

 ACE_Streambuf (u_int streambuf_size, int io_mode)
virtual int sync (void)
virtual int underflow (void)
virtual int overflow (int c=EOF)
void reset_base (void)
int syncin (void)
int syncout (void)
int flushbuf (void)
int fillbuf (void)
virtual int get_one_byte (void)
virtual ssize_t send (char *buf, ssize_t len)=0
virtual ssize_t recv (char *buf, ssize_t len, ACE_Time_Value *tv=0)=0
virtual ssize_t recv (char *buf, ssize_t len, int flags, ACE_Time_Value *tv=0)=0
virtual ssize_t recv_n (char *buf, ssize_t len, int flags=0, ACE_Time_Value *tv=0)=0
virtual ACE_HANDLE get_handle (void)

Protected Attributes

char * eback_saved_
char * gptr_saved_
char * egptr_saved_
char * pbase_saved_
char * pptr_saved_
char * epptr_saved_
u_char cur_mode_
const u_char get_mode_
const u_char put_mode_
int mode_
const u_int streambuf_size_
u_char timeout_
 Did we take an error because of an IO operation timeout?

ACE_Time_Value recv_timeout_value_
ACE_Time_Valuerecv_timeout_

Detailed Description

Create your custom streambuf by providing and ACE_*_Stream object to this template. I have tested it with ACE_SOCK_Stream and it should work fine for others as well.

For any iostream object, the real work is done by the underlying streambuf class. That is what we create here. A streambuf has an internal buffer area into which data is read and written as the iostream requests and provides data. At some point during the read process, the iostream will realize that the streambuf has no more data. The underflow function of the streambuf is then called. Likewise, during the write process, the iostream will eventually notice that the streabuf's buffer has become full and will invoke the overflow function. The empty/full state of the read/write "buffers" are controled by two sets pointers. One set is dedicated to read, the other to write. These pointers, in turn, reference a common buffer that is to be shared by both read and write operations. It is this common buffer to which data is written and from which it is read. The common buffer is used by functions of the streambuf as well as the iostream. Because of this and the fact that it is "shared" by both read and write operators, there is a danger of data corruption if read and write operations are allowed to take place "at the same time". To prevent data corruption, we manipulate the read and write pointer sets so that the streambuf is in either a read-mode or write-mode at all times and can never be in both modes at the same time. In the constructor: set the read and write sets to NULL This causes the underflow or overflow operators to be invoked at the first IO activity of the iostream. In the underflow function we arrange for the common buffer to reference our read buffer and for the write pointer set to be disabled. If a write operation is performed by the iostream this will cause the overflow function to be invoked. In the overflow function we arrange for the common buffer to reference our write buffer and for the read pointer set to be disabled. This causes the underflow function to be invoked when the iostream "changes our mode". The overflow function will also invoke the send_n function to flush the buffered data to our peer. Similarly, the sync and syncout functions will cause send_n to be invoked to send the data. Since socket's and the like do not support seeking, there can be no method for "syncing" the input. However, since we maintain separate read/write buffers, no data is lost by "syncing" the input. It simply remains buffered.

Definition at line 162 of file IOStream.h.


Constructor & Destructor Documentation

ACE_Streambuf::~ACE_Streambuf void   )  [virtual]
 

If the default allocation strategey were used the common buffer would be deleted when the object destructs. Since we are providing separate read/write buffers, it is up to us to manage their memory.

Definition at line 649 of file IOStream.cpp.

References eback_saved_, and pbase_saved_.

00650 {
00651   delete [] this->eback_saved_;
00652   delete [] this->pbase_saved_;
00653 }

ACE_Streambuf::ACE_Streambuf u_int  streambuf_size,
int  io_mode
[protected]
 

Definition at line 478 of file IOStream.cpp.

References reset_get_buffer(), and reset_put_buffer().

00479   : eback_saved_ (0),  // to avoid Purify UMR
00480     pbase_saved_ (0),  // to avoid Purify UMR
00481     get_mode_ (1),
00482     put_mode_ (2),
00483     mode_ (io_mode),
00484     streambuf_size_ (streambuf_size),
00485     recv_timeout_ (0)
00486 {
00487  (void)reset_get_buffer ();
00488  (void)reset_put_buffer ();
00489 }


Member Function Documentation

int ACE_Streambuf::fillbuf void   )  [protected]
 

fillbuf is called in a couple of places. This is the worker of underflow. It will attempt to fill the read buffer from the peer.

Definition at line 446 of file IOStream.cpp.

References ETIME, get_one_byte(), recv(), and timeout_.

Referenced by underflow().

00447 {
00448   // Invoke recv_n to get exactly one byte from the remote.  This will
00449   // block until something shows up.
00450 
00451   if (get_one_byte () == EOF)
00452     return EOF;
00453 
00454   // Now, get whatever else may be in the buffer.  This will return if
00455   // there is nothing in the buffer.
00456 
00457   int bc = this->recv (base (), blen (), this->recv_timeout_);
00458 
00459   // recv will give us -1 if there was a problem.  If there was
00460   // nothing waiting to be read, it will give us 0.  That isn't an
00461   // error.
00462 
00463   if (bc < 0)
00464     {
00465       if (errno == ETIME)
00466         this->timeout_ = 1;
00467       return EOF;
00468     }
00469 
00470   // Move the get pointer to reflect the number of bytes we just read.
00471 
00472   setg (base (), base (), base () + bc);
00473 
00474   // Return the byte-read-count including the one from <get_one_byte>.
00475   return bc;
00476 }

int ACE_Streambuf::flushbuf void   )  [protected]
 

flushbuf is the worker of syncout. It is a separate function because it gets used sometimes in different context.

Definition at line 365 of file IOStream.cpp.

References send().

Referenced by syncout().

00366 {
00367   // pptr () is one character beyond the last character put into the
00368   // buffer.  pbase () points to the beginning of the put buffer.
00369   // Unless pptr () is greater than pbase () there is nothing to be
00370   // sent to the peer.
00371 
00372   if (pptr () <= pbase ())
00373     return 0;
00374 
00375   // 4/12/97 -- JCEJ
00376   // Kludge!!!
00377   // If the remote side shuts down the connection, an attempt to send
00378   // () to the remote will result in the message 'Broken Pipe' I think
00379   // this is an OS message, I've tracked it down to the ACE_OS::write
00380   // () function.  That's the last one to be called before the
00381   // message.  I can only test this on Linux though, so I don't know
00382   // how other systems will react.
00383   //
00384   // To get around this gracefully, I do a PEEK recv () with an
00385   // immediate (nearly) timeout.  recv () is much more graceful on
00386   // it's failure.  If we get -1 from recv () not due to timeout then
00387   // we know we're SOL.
00388   //
00389   // Q:  Is 'errno' threadsafe?  Should the section below be a
00390   //     critical section?
00391   //
00392   // char tbuf[1];
00393   // ACE_Time_Value to (0,1);
00394   // if (this->recv (tbuf, 1, MSG_PEEK, &to) == -1)
00395   // {
00396   //    if (errno != ETIME)
00397   //    {
00398   //            perror ("OOPS preparing to send to peer");
00399   //            return EOF;
00400   //    }
00401   // }
00402   //
00403   // The correct way to handle this is for the application to trap
00404   // (and ignore?) SIGPIPE.  Thanks to Amos Shapira for reminding me
00405   // of this.
00406 
00407   // Starting at the beginning of the buffer, send as much data as
00408   // there is waiting.  send guarantees that all of the data will be
00409   // sent or an error will be returned.
00410 
00411   if (this->send (pbase (), pptr () - pbase ()) == -1)
00412     return EOF;
00413 
00414   // Now that we've sent everything in the output buffer, we reset the
00415   // buffer pointers to appear empty.
00416   setp (base (), ebuf ());
00417 
00418   return 0;
00419 }

u_int ACE_Streambuf::get_avail void   ) 
 

Return the number of bytes in the get area (includes some already gotten); eback + get_avail = egptr

Definition at line 510 of file IOStream.cpp.

References eback_saved_, and egptr_saved_.

00511 {
00512   return this->egptr_saved_ - this->eback_saved_;
00513 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_HANDLE ACE_Streambuf::get_handle void   )  [protected, virtual]
 

Reimplemented in ACE_Streambuf_T< STREAM >.

Definition at line 92 of file IOStream.cpp.

00093 {
00094   return 0;
00095 }

int ACE_Streambuf::get_one_byte void   )  [protected, virtual]
 

Used by fillbuf and others to get exactly one byte from the peer. recv_n is used to be sure we block until something is available. It is virtual because we really need to override it for datagram-derived objects.

Definition at line 422 of file IOStream.cpp.

References ETIME, recv_n(), and timeout_.

Referenced by fillbuf().

00423 {
00424   this->timeout_ = 0;
00425 
00426   // The recv function will return immediately if there is no data
00427   // waiting.  So, we use recv_n to wait for exactly one byte to come
00428   // from the peer.  Later, we can use recv to see if there is
00429   // anything else in the buffer. (Ok, we could use flags to tell it
00430   // to block but I like this better.)
00431 
00432   if (this->recv_n (base (), 1, MSG_PEEK, this->recv_timeout_) != 1)
00433     {
00434       if (errno == ETIME)
00435         this->timeout_ = 1;
00436       return EOF;
00437     }
00438   else
00439     return 1;
00440 }

u_int ACE_Streambuf::get_waiting void   ) 
 

Return the number of bytes not yet gotten. eback + get_waiting = gptr

Definition at line 501 of file IOStream.cpp.

References eback_saved_, and gptr_saved_.

00502 {
00503   return this->gptr_saved_ - this->eback_saved_;
00504 }

int ACE_Streambuf::overflow int  c = EOF  )  [protected, virtual]
 

The overflow function receives the character which caused the overflow.

Definition at line 237 of file IOStream.cpp.

References cur_mode_, eback_saved_, egptr_saved_, get_mode_, gptr_saved_, pbase_saved_, put_mode_, reset_get_buffer(), streambuf_size_, and syncout().

00238 {
00239   // Check to see if output is allowed at all.
00240   if (! (mode_ & ios::out))
00241     return EOF;
00242 
00243   if (!base ())
00244     {
00245       // Set base () to use put's private buffer.
00246       //
00247       setb (this->pbase_saved_,
00248             this->pbase_saved_ + streambuf_size_, 0);
00249 
00250       // Set the mode for optimization.
00251       this->cur_mode_ = this->put_mode_;
00252       // Set the put area using the new base () values.
00253       setp (base (), ebuf ());
00254 
00255       // Disable the get area.
00256       setg (0, 0, 0);
00257     }
00258   else  // We're already reading or writing
00259     {
00260       // If we're coming out of get mode...
00261       if (this->cur_mode_ == this->get_mode_)
00262         {
00263           // --> JCEJ 6/6/98
00264           if (! eback())
00265             {
00266               /* Something has happened to cause the streambuf
00267                  to get rid of our get area.
00268                  We could probably do this a bit cleaner but
00269                  this method is sure to cleanup the bits and
00270                  pieces.
00271               */
00272               delete [] eback_saved_;
00273               (void) reset_get_buffer();
00274             }
00275           else
00276             {
00277               // Save the current get mode values
00278               this->eback_saved_ = eback ();
00279               this->gptr_saved_  = gptr ();
00280               this->egptr_saved_ = egptr ();
00281             }
00282           // <-- JCEJ 6/6/98
00283 
00284           // then disable the get buffer
00285           setg (0, 0, 0);
00286 
00287           // Reconfigure base () and restore the put pointers.
00288           setb (pbase_saved_, pbase_saved_ + streambuf_size_, 0);
00289           setp (base (), ebuf ());
00290 
00291           // Save the new mode.
00292           this->cur_mode_ = this->put_mode_;
00293         }
00294 
00295       // If there is output to be flushed, do so now.  We shouldn't
00296       // get here unless this is the case...
00297 
00298       if (out_waiting () && EOF == syncout ())
00299         return EOF;
00300     }
00301 
00302   // If we're not putting EOF, then we have to deal with the character
00303   // that is being put.  Perhaps we should do something special with EOF???
00304 
00305   if (c != EOF)
00306     {
00307       // We've already written any data that may have been in the
00308       // buffer, so we're guaranteed to have room in the buffer for
00309       // this new information.  So... we add it to the buffer and
00310       // adjust our 'next' pointer acordingly.
00311       *pptr () = (char) c;
00312       pbump (1);
00313     }
00314 
00315   return 0;
00316 }

u_int ACE_Streambuf::put_avail void   ) 
 

Return the number of bytes to be 'put' onto the stream media. pbase + put_avail = pptr

Definition at line 519 of file IOStream.cpp.

References pbase_saved_, and pptr_saved_.

00520 {
00521   return this->pptr_saved_ - this->pbase_saved_;
00522 }

virtual ssize_t ACE_Streambuf::recv char *  buf,
ssize_t  len,
int  flags,
ACE_Time_Value tv = 0
[protected, pure virtual]
 

Implemented in ACE_Streambuf_T< STREAM >.

virtual ssize_t ACE_Streambuf::recv char *  buf,
ssize_t  len,
ACE_Time_Value tv = 0
[protected, pure virtual]
 

Implemented in ACE_Streambuf_T< STREAM >.

Referenced by fillbuf().

virtual ssize_t ACE_Streambuf::recv_n char *  buf,
ssize_t  len,
int  flags = 0,
ACE_Time_Value tv = 0
[protected, pure virtual]
 

Implemented in ACE_Streambuf_T< STREAM >.

Referenced by get_one_byte().

ACE_Time_Value * ACE_Streambuf::recv_timeout ACE_Time_Value tv = 0  ) 
 

Get the current Time_Value pointer and provide a new one.

Definition at line 98 of file IOStream.cpp.

References recv_timeout_, and recv_timeout_value_.

00099 {
00100   ACE_Time_Value * rval = recv_timeout_;
00101   if (tv)
00102     {
00103       recv_timeout_value_ = *tv;
00104       recv_timeout_ = &recv_timeout_value_;
00105     }
00106   else
00107     recv_timeout_ = 0;
00108 
00109   return rval;
00110 }

void ACE_Streambuf::reset_base void   )  [protected]
 

Resets the pointer and streambuf mode. This is used internally when get/put buffers are allocatd.

Definition at line 631 of file IOStream.cpp.

References cur_mode_.

Referenced by reset_get_buffer(), and reset_put_buffer().

00632 {
00633   // Until we experience the first get or put operation, we do not
00634   // know what our current IO mode is.
00635   this->cur_mode_ = 0;
00636 
00637   // The common area used for reading and writting is called "base".
00638   // We initialize it this way so that the first get/put operation
00639   // will have to "allocate" base.  This allocation will set base to
00640   // the appropriate specific buffer and set the mode to the correct
00641   // value.
00642   setb (0, 0);
00643 }

char * ACE_Streambuf::reset_get_buffer char *  newBuffer = 0,
u_int  _streambuf_size = 0,
u_int  _gptr = 0,
u_int  _egptr = 0
 

Use this to allocate a new/different buffer for get operations. If you do not provide a buffer pointer, one will be allocated. That is the preferred method. If you do provide a buffer, the size must match that being used by the put buffer. If successful, you will receive a pointer to the current get buffer. It is your responsibility to delete this memory when you are done with it.

Definition at line 535 of file IOStream.cpp.

References ACE_NEW_RETURN, eback_saved_, egptr_saved_, gptr_saved_, reset_base(), and streambuf_size_.

Referenced by ACE_Streambuf(), and overflow().

00539 {
00540   char * rval = this->eback_saved_;
00541 
00542   // The get area is where the iostream will get data from.  This is
00543   // our read buffer.  There are three pointers which describe the
00544   // read buffer:
00545   //
00546   //    eback () - The beginning of the buffer.  Also the furthest
00547   //              point at which putbacks can be done.  Hence the name.
00548   //
00549   //    gptr ()  - Where the next character is to be got from.
00550   //
00551   //    egptr () - One position beyond the last get-able character.
00552   //
00553   // So that we can switch quicky from read to write mode without
00554   // any data copying, we keep copies of these three pointers in
00555   // the variables below.  Initially, they all point to the beginning
00556   // of our read-dedicated buffer.
00557   //
00558   if (newBuffer)
00559     {
00560       if (streambuf_size_ != _streambuf_size)
00561         return 0;
00562       this->eback_saved_ = newBuffer;
00563     }
00564   else
00565     ACE_NEW_RETURN (this->eback_saved_,
00566                     char[streambuf_size_],
00567                     0);
00568 
00569   this->gptr_saved_ = this->eback_saved_ + _gptr;
00570   this->egptr_saved_ = this->eback_saved_ + _egptr;
00571 
00572   // Disable the get area initially.  This will cause underflow to be
00573   // invoked on the first get operation.
00574   setg (0, 0, 0);
00575 
00576   reset_base ();
00577 
00578   return rval;
00579 }

char * ACE_Streambuf::reset_put_buffer char *  newBuffer = 0,
u_int  _streambuf_size = 0,
u_int  _pptr = 0
 

Use this to allocate a new/different buffer for put operations. If you do not provide a buffer pointer, one will be allocated. That is the preferred method. If you do provide a buffer, the size must match that being used by the get buffer. If successful, you will receive a pointer to the current put buffer. It is your responsibility to delete this memory when you are done with it.

Definition at line 588 of file IOStream.cpp.

References ACE_NEW_RETURN, epptr_saved_, pbase_saved_, pptr_saved_, reset_base(), and streambuf_size_.

Referenced by ACE_Streambuf(), and underflow().

00591 {
00592   char *rval = this->pbase_saved_;
00593 
00594   // The put area is where the iostream will put data that needs to be
00595   // sent to the peer.  This becomes our write buffer.  The three
00596   // pointers which maintain this area are:
00597   //
00598   //    pbase () - The beginning of the put area.
00599   //
00600   //    pptr ()  - Where the next character is to be put.
00601   //
00602   //    epptr () - One beyond the last valid position for putting.
00603   //
00604   // Again to switch quickly between modes, we keep copies of
00605   // these three pointers.
00606   //
00607   if (newBuffer)
00608     {
00609       if (streambuf_size_ != _streambuf_size)
00610         return 0;
00611       this->pbase_saved_ = newBuffer;
00612     }
00613   else
00614     ACE_NEW_RETURN (this->pbase_saved_,
00615                     char[streambuf_size_],
00616                     0);
00617 
00618   this->pptr_saved_ = this->pbase_saved_ + _pptr;
00619   this->epptr_saved_ = this->pbase_saved_ + streambuf_size_;
00620 
00621   // Disable the put area.  Overflow will be called by the first call
00622   // to any put operator.
00623   setp (0, 0);
00624 
00625   reset_base ();
00626 
00627   return rval;
00628 }

virtual ssize_t ACE_Streambuf::send char *  buf,
ssize_t  len
[protected, pure virtual]
 

Stream connections and "unconnected connections" (ie -- datagrams) need to work just a little differently. We derive custom Streambuf objects for them and provide these functions at that time.

Implemented in ACE_Streambuf_T< STREAM >.

Referenced by flushbuf().

u_int ACE_Streambuf::streambuf_size void   ) 
 

Query the streambuf for the size of its buffers.

Definition at line 492 of file IOStream.cpp.

References streambuf_size_.

00493 {
00494   return streambuf_size_;
00495 }

int ACE_Streambuf::sync void   )  [protected, virtual]
 

Sync both input and output. See syncin/syncout below for descriptions.

Definition at line 345 of file IOStream.cpp.

References syncin(), and syncout().

00346 {
00347   // sync () is fairly traditional in that it syncs both input and
00348   // output.  We could have omitted the call to syncin () but someday,
00349   // we may want it to do something.
00350 
00351   syncin ();
00352 
00353   // Don't bother syncing the output unless there is data to be
00354   // sent...
00355 
00356   if (out_waiting ())
00357     return syncout ();
00358   else
00359     return 0;
00360 }

int ACE_Streambuf::syncin void   )  [protected]
 

syncin is called when the input needs to be synced with the source file. In a filebuf, this results in the system call being used. We can't do that on socket-like connections, so this does basically nothing. That's safe because we have a separate read buffer to maintain the already-read data. In a filebuf, the single common buffer is used forcing the call.

Definition at line 321 of file IOStream.cpp.

Referenced by sync().

00322 {
00323   // As discussed, there really isn't any way to sync input from a
00324   // socket-like device.  We specifially override this base-class
00325   // function so that it won't do anything evil to us.
00326   return 0;
00327 }

int ACE_Streambuf::syncout void   )  [protected]
 

syncout is called when the output needs to be flushed. This is easily done by calling the peer's send_n function.

Definition at line 332 of file IOStream.cpp.

References flushbuf().

Referenced by overflow(), sync(), and underflow().

00333 {
00334   // Unlike syncin, syncout is a doable thing.  All we have to do is
00335   // write whatever is in the output buffer to the peer.  flushbuf ()
00336   // is how we do it.
00337 
00338   if (flushbuf () == EOF)
00339     return EOF;
00340   else
00341     return 0;
00342 }

u_char ACE_Streambuf::timeout void   ) 
 

Did we take an error because of an IO operation timeout?

Note:
Invoking this resets the flag.

Definition at line 655 of file IOStream.cpp.

References timeout_.

00656 {
00657   u_char rval = this->timeout_;
00658   this->timeout_ = 0;
00659   return rval;
00660 }

int ACE_Streambuf::underflow void   )  [protected, virtual]
 

Definition at line 113 of file IOStream.cpp.

References ACE_BIT_DISABLED, cur_mode_, epptr_saved_, fillbuf(), get_mode_, pbase_saved_, pptr_saved_, put_mode_, reset_put_buffer(), streambuf_size_, and syncout().

00114 {
00115   // If input mode is not set, any attempt to read from the stream is
00116   // a failure.
00117 
00118   if (ACE_BIT_DISABLED (mode_, ios::in))
00119     return EOF;
00120 
00121   // If base () is empty then this is the first time any get/put
00122   // operation has been attempted on the stream.
00123 
00124   if (!this->base ())
00125     {
00126       // Set base () to use our private read buffer.  The arguments are:
00127       //        beginning of the buffer (base ())
00128       //        one-beyond the end of the buffer (ebase ())
00129       //        should base () be deleted on destruction
00130       //
00131       // We have to say "no" to the third parameter because we want to
00132       // explicitly handle deletion of the TWO buffers at destruction.
00133 
00134       setb (this->eback_saved_,
00135             this->eback_saved_ + streambuf_size_, 0);
00136 
00137       // Remember that we are now in getMode.  This will help us if
00138       // we're called prior to a mode change as well as helping us
00139       // when the mode does change.
00140       this->cur_mode_ = this->get_mode_;
00141       // Using the new values for base (), initialize the get area.
00142       // This simply sets eback (), gptr () and egptr () described
00143       // earlier.
00144       setg (base (), base (), base ());
00145 
00146       // Set the put buffer such that puts will be disabled.  Any
00147       // attempt to put data will now cause overflow to be invoked.
00148       setp (0, 0);
00149     }
00150   else  // base () has been initialized already...
00151     {
00152       // If we are in put_mode_ now, then it is time to switch to get_mode_
00153       //
00154       // 1. get rid of any pending output
00155       // 2. rearrange base () to use our half of the buffer
00156       // 3. reset the mode
00157       //
00158       if (this->cur_mode_ == this->put_mode_)
00159         {
00160           // Dump any pending output to the peer.  This is not really
00161           // necessary because of the dual-buffer arrangement we've
00162           // set up but intuitively it makes sense to send the pending
00163           // data before we request data since the peer will probably
00164           // need what we're sending before it can respond.
00165           if (out_waiting () && syncout () == EOF)
00166             return EOF;
00167 
00168           if( ! pbase() )
00169             {
00170               delete [] pbase_saved_;
00171               (void) reset_put_buffer();
00172             }
00173           else
00174             {
00175               // We're about to disable put mode but before we do
00176               // that, we want to preserve it's state.
00177               this->pbase_saved_ = pbase ();
00178               this->pptr_saved_  = pptr ();
00179               this->epptr_saved_ = epptr ();
00180             }
00181 
00182           // Disable put mode as described in the constructor.
00183           setp (0, 0);
00184 
00185           // Like the case where base () is false, we now point base
00186           // () to use our private get buffer.
00187           setb (this->eback_saved_,
00188                 this->eback_saved_ + streambuf_size_,
00189                 0);
00190 
00191           // And restore the previous state of the get pointers.
00192 
00193           setg (this->eback_saved_, this->gptr_saved_,
00194                 this->egptr_saved_);
00195 
00196           // Finally, set our mode so that we don't get back into this
00197           // if () and so that overflow can operate correctly.
00198           cur_mode_ = get_mode_;
00199         }
00200 
00201       // There could be data in the input buffer if we switched to put
00202       // mode before reading everything.  In that case, we take this
00203       // opportunity to feed it back to the iostream.
00204       if (in_avail ())
00205         // Remember that we return an int so that we can give back
00206         // EOF.  The explicit cast prevents us from returning a signed
00207         // char when we're not returning EOF.
00208         return (u_char) *gptr ();
00209     }
00210 
00211   // We really shouldn't be here unless there is a lack of data in the
00212   // read buffer.  So... go get some more data from the peer.
00213 
00214   int result = fillbuf ();
00215 
00216   // Fillbuf will give us EOF if there was an error with the peer.  In
00217   // that case, we can do no more input.
00218 
00219   if (EOF == result)
00220     {
00221       // Disable ourselves and return failure to the iostream.  That
00222       // should result in a call to have oursleves closed.
00223       setg (0, 0, 0);
00224       return EOF;
00225     }
00226 
00227   // Return the next available character in the input buffer.  Again,
00228   // we protect against sign extension.
00229 
00230   return (u_char) *gptr ();
00231 }


Member Data Documentation

u_char ACE_Streambuf::cur_mode_ [protected]
 

Definition at line 254 of file IOStream.h.

Referenced by overflow(), reset_base(), and underflow().

char* ACE_Streambuf::eback_saved_ [protected]
 

Definition at line 244 of file IOStream.h.

Referenced by get_avail(), get_waiting(), overflow(), reset_get_buffer(), and ~ACE_Streambuf().

char* ACE_Streambuf::egptr_saved_ [protected]
 

Definition at line 246 of file IOStream.h.

Referenced by get_avail(), overflow(), and reset_get_buffer().

char* ACE_Streambuf::epptr_saved_ [protected]
 

Definition at line 249 of file IOStream.h.

Referenced by reset_put_buffer(), and underflow().

const u_char ACE_Streambuf::get_mode_ [protected]
 

Definition at line 255 of file IOStream.h.

Referenced by overflow(), and underflow().

char* ACE_Streambuf::gptr_saved_ [protected]
 

Definition at line 245 of file IOStream.h.

Referenced by get_waiting(), overflow(), and reset_get_buffer().

int ACE_Streambuf::mode_ [protected]
 

mode tells us if we're working for an istream, ostream, or iostream.

Definition at line 260 of file IOStream.h.

char* ACE_Streambuf::pbase_saved_ [protected]
 

Definition at line 247 of file IOStream.h.

Referenced by overflow(), put_avail(), reset_put_buffer(), underflow(), and ~ACE_Streambuf().

char* ACE_Streambuf::pptr_saved_ [protected]
 

Definition at line 248 of file IOStream.h.

Referenced by put_avail(), reset_put_buffer(), and underflow().

const u_char ACE_Streambuf::put_mode_ [protected]
 

Definition at line 256 of file IOStream.h.

Referenced by overflow(), and underflow().

ACE_Time_Value* ACE_Streambuf::recv_timeout_ [protected]
 

Definition at line 272 of file IOStream.h.

Referenced by recv_timeout().

ACE_Time_Value ACE_Streambuf::recv_timeout_value_ [protected]
 

We want to allow the user to provide Time_Value pointers to prevent infinite blocking while waiting to receive data.

Definition at line 271 of file IOStream.h.

Referenced by recv_timeout().

const u_int ACE_Streambuf::streambuf_size_ [protected]
 

This defines the size of the input and output buffers. It can be set by the object constructor.

Definition at line 264 of file IOStream.h.

Referenced by overflow(), reset_get_buffer(), reset_put_buffer(), streambuf_size(), and underflow().

u_char ACE_Streambuf::timeout_ [protected]
 

Did we take an error because of an IO operation timeout?

Definition at line 267 of file IOStream.h.

Referenced by fillbuf(), get_one_byte(), and timeout().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:30:23 2006 for ACE by doxygen 1.3.6