Changeset 2254


Ignore:
Timestamp:
21/08/2008 12:05:38 (3 years ago)
Author:
chris
Message:

Add a Flush() method to IOStream to read and discard all remaining data,
and a SelfFlushingStream? class which can be used to ensure that protocol
streams are always flushed, to avoid breaking protocol.

Location:
box/trunk/lib/common
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/common/IOStream.cpp

    r217 r2254  
    239239} 
    240240 
    241  
     241// -------------------------------------------------------------------------- 
     242// 
     243// Function 
     244//              Name:    IOStream::Flush(int Timeout) 
     245//              Purpose: Read and discard all remaining data in stream. 
     246//                       Useful for protocol streams which must be flushed 
     247//                       to avoid breaking the protocol. 
     248//              Created: 2008/08/20 
     249// 
     250// -------------------------------------------------------------------------- 
     251void IOStream::Flush(int Timeout) 
     252{ 
     253        char buffer[4096]; 
     254 
     255        while(StreamDataLeft()) 
     256        { 
     257                Read(buffer, sizeof(buffer), Timeout); 
     258        } 
     259} 
     260 
     261 
  • box/trunk/lib/common/IOStream.h

    r217 r2254  
    5858        bool ReadFullBuffer(void *pBuffer, int NBytes, int *pNBytesRead, int Timeout = IOStream::TimeOutInfinite); 
    5959        bool CopyStreamTo(IOStream &rCopyTo, int Timeout = IOStream::TimeOutInfinite, int BufferSize = 1024); 
     60        void Flush(int Timeout = IOStream::TimeOutInfinite); 
    6061         
    6162        static int ConvertSeekTypeToOSWhence(int SeekType); 
Note: See TracChangeset for help on using the changeset viewer.