Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 Methods

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

char * reset_put_buffer (char *newBuffer=NULL, u_int _streambuf_size=0, u_int _pptr=0)
u_int put_avail (void)
 Return the number of bytes to be 'put' onto the stream media. pbase + put_avail = pptr. More...

char * reset_get_buffer (char *newBuffer=NULL, u_int _streambuf_size=0, u_int _gptr=0, u_int _egptr=0)
u_int get_waiting (void)
 Return the number of bytes not yet gotten. eback + get_waiting = gptr. More...

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

u_int streambuf_size (void)
 Query the streambuf for the size of its buffers. More...

u_char timeout (void)
 Did we take an error because of an IO operation timeout? Note: Invoking this resets the flag. More...


Protected Methods

 ACE_Streambuf (u_int streambuf_size, int io_mode)
virtual int sync (void)
 Sync both input and output. See syncin/syncout below for descriptions. More...

virtual int underflow (void)
virtual int overflow (int=EOF)
 The overflow function receives the character which caused the overflow. More...

void reset_base (void)
 Resets the <base> pointer and streambuf mode. This is used internally when get/put buffers are allocatd. More...

int syncin (void)
int syncout (void)
 syncout is called when the output needs to be flushed. This is easily done by calling the peer's send_n function. More...

int flushbuf (void)
 flushbuf is the worker of syncout. It is a separate function because it gets used sometimes in different context. More...

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=NULL)=0
virtual ssize_t recv (char *buf, ssize_t len, int flags, ACE_Time_Value *tv=NULL)=0
virtual ssize_t recv_n (char *buf, ssize_t len, int flags=0, ACE_Time_Value *tv=NULL)=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_
 mode tells us if we're working for an istream, ostream, or iostream. More...

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

u_char timeout_
 Did we take an error because of an IO operation timeout? More...

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

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 144 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 645 of file IOStream.cpp.

References eback_saved_, and pbase_saved_.

00646 {
00647   delete [] this->eback_saved_;
00648   delete [] this->pbase_saved_;
00649 }

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

Definition at line 474 of file IOStream.cpp.

References reset_get_buffer, and reset_put_buffer.

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


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 442 of file IOStream.cpp.

References ETIME, get_one_byte, recv, and timeout_.

Referenced by underflow.

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

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 361 of file IOStream.cpp.

References send.

Referenced by syncout.

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

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 506 of file IOStream.cpp.

References eback_saved_, and egptr_saved_.

00507 {
00508   return this->egptr_saved_ - this->eback_saved_;
00509 }

ACE_HANDLE ACE_Streambuf::get_handle void    [protected, virtual]
 

Reimplemented in ACE_Streambuf_T.

Definition at line 88 of file IOStream.cpp.

00089 {
00090   return 0;
00091 }

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 418 of file IOStream.cpp.

References ETIME, recv_n, and timeout_.

Referenced by fillbuf.

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

u_int ACE_Streambuf::get_waiting void   
 

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

Definition at line 497 of file IOStream.cpp.

References eback_saved_, and gptr_saved_.

00498 {
00499   return this->gptr_saved_ - this->eback_saved_;
00500 }

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

The overflow function receives the character which caused the overflow.

Definition at line 233 of file IOStream.cpp.

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

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

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 515 of file IOStream.cpp.

References pbase_saved_, and pptr_saved_.

00516 {
00517   return this->pptr_saved_ - this->pbase_saved_;
00518 }

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

Implemented in ACE_Streambuf_T.

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

Implemented in ACE_Streambuf_T.

Referenced by fillbuf.

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

Implemented in ACE_Streambuf_T.

Referenced by get_one_byte.

ACE_Time_Value * ACE_Streambuf::recv_timeout ACE_Time_Value   tv = NULL
 

Get the current Time_Value pointer and provide a new one.

Definition at line 94 of file IOStream.cpp.

References recv_timeout_, and recv_timeout_value_.

00095 {
00096   ACE_Time_Value * rval = recv_timeout_;
00097   if (tv)
00098     {
00099       recv_timeout_value_ = *tv;
00100       recv_timeout_ = &recv_timeout_value_;
00101     }
00102   else
00103     recv_timeout_ = 0;
00104 
00105   return rval;
00106 }

void ACE_Streambuf::reset_base void    [protected]
 

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

Definition at line 627 of file IOStream.cpp.

References cur_mode_.

Referenced by reset_get_buffer, and reset_put_buffer.

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

char * ACE_Streambuf::reset_get_buffer char *    newBuffer = NULL,
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 531 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.

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

char * ACE_Streambuf::reset_put_buffer char *    newBuffer = NULL,
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 584 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.

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

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.

Referenced by flushbuf.

u_int ACE_Streambuf::streambuf_size void   
 

Query the streambuf for the size of its buffers.

Definition at line 488 of file IOStream.cpp.

References streambuf_size_.

00489 {
00490   return streambuf_size_;
00491 }

int ACE_Streambuf::sync void    [protected, virtual]
 

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

Definition at line 341 of file IOStream.cpp.

References syncin, and syncout.

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

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

Definition at line 317 of file IOStream.cpp.

Referenced by sync.

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

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 328 of file IOStream.cpp.

References flushbuf.

Referenced by overflow, sync, and underflow.

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

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 651 of file IOStream.cpp.

References timeout_.

00652 {
00653   u_char rval = this->timeout_;
00654   this->timeout_ = 0;
00655   return rval;
00656 }

int ACE_Streambuf::underflow void    [protected, virtual]
 

Definition at line 109 of file IOStream.cpp.

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

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


Member Data Documentation

u_char ACE_Streambuf::cur_mode_ [protected]
 

Definition at line 236 of file IOStream.h.

Referenced by overflow, reset_base, and underflow.

char* ACE_Streambuf::eback_saved_ [protected]
 

Definition at line 226 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 228 of file IOStream.h.

Referenced by get_avail, overflow, and reset_get_buffer.

char* ACE_Streambuf::epptr_saved_ [protected]
 

Definition at line 231 of file IOStream.h.

Referenced by reset_put_buffer, and underflow.

const u_char ACE_Streambuf::get_mode_ [protected]
 

Definition at line 237 of file IOStream.h.

Referenced by overflow, and underflow.

char* ACE_Streambuf::gptr_saved_ [protected]
 

Definition at line 227 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 242 of file IOStream.h.

Referenced by overflow, and underflow.

char* ACE_Streambuf::pbase_saved_ [protected]
 

Definition at line 229 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 230 of file IOStream.h.

Referenced by put_avail, reset_put_buffer, and underflow.

const u_char ACE_Streambuf::put_mode_ [protected]
 

Definition at line 238 of file IOStream.h.

Referenced by overflow, and underflow.

ACE_Time_Value* ACE_Streambuf::recv_timeout_ [protected]
 

Definition at line 254 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 253 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 246 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 249 of file IOStream.h.

Referenced by fillbuf, get_one_byte, ACE_Streambuf_T::recv, ACE_Streambuf_T::recv_n, and timeout.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:56:59 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002