ZStreamRW_FlushOnRead Class Reference

A RW stream that ensures the write stream is flushed when the read stream is read. More...

#include <ZStreamRW_FlushOnRead.h>

Inheritance diagram for ZStreamRW_FlushOnRead:

ZStreamR ZStreamW List of all members.

Public Member Functions

virtual size_t Imp_CountReadable ()
 Returns the number of bytes guaranteed to be readable without blocking.
virtual void Imp_CopyToDispatch (const ZStreamW &iStreamW, uint64 iCount, uint64 *oCountRead, uint64 *oCountWritten)
 Invoke iStreamW's Imp_CopyFrom method.
virtual void Imp_CopyTo (const ZStreamW &iStreamW, uint64 iCount, uint64 *oCountRead, uint64 *oCountWritten)
 Actually copy data from this stream to iStreamW.
virtual void Imp_Skip (uint64 iCount, uint64 *oCountSkipped)
 Read and discard iCount bytes.
virtual void Imp_CopyFromDispatch (const ZStreamR &iStreamR, uint64 iCount, uint64 *oCountRead, uint64 *oCountWritten)
 Invoke iStreamR's Imp_CopyTo method.
virtual void Imp_CopyFrom (const ZStreamR &iStreamR, uint64 iCount, uint64 *oCountRead, uint64 *oCountWritten)
 Actually copy data to this stream from iStreamR.

Detailed Description

A RW stream that ensures the write stream is flushed when the read stream is read.

ZStreamRW_FlushOnRead wraps a read stream and a write stream. It tracks the last operation applied to it, so that when a write is followed by a read Flush is called on the real write stream first. Why would you need to use this? Imagine that the write stream is buffering a network endpoint stream. If you were to write to it then read from the endpoint's read stream there's no guarantee that what you wrote has been seen by the other end yet, and thus there may be nothing to read and never will be as the info that would cause the far end to write to you is still sitting in our local write buffer. By placing a ZStreamRW_FlushOnRead between you and the endpoint's read stream and the buffered write stream we're able to ensure that anytime we read from it the write stream will have been flushed.

Note:
Calls that are nominally read calls can also cause writes to occur. This makes the read and write aspects of this stream dependent in a way that's not usually the case for ZStreamRW variants. To protected against weirdness (that took me a couple of hours to track down) we track the last operation with a thread safe variable, and all write calls are protected by a mutex.


Member Function Documentation

size_t ZStreamRW_FlushOnRead::Imp_CountReadable (  )  [virtual]

Returns the number of bytes guaranteed to be readable without blocking.

If the stream does not or cannot know this information it should return zero. A zero return thus does not mean no data is available, simply that a subsequent Read or Skip may block indefinitely.

Reimplemented from ZStreamR.

void ZStreamRW_FlushOnRead::Imp_CopyToDispatch ( const ZStreamW iStreamW,
uint64  iCount,
uint64 oCountRead,
uint64 oCountWritten 
) [virtual]

Invoke iStreamW's Imp_CopyFrom method.

The first part of the two-stage dispatch initiated by ZStreamR::CopyTo and ZStreamR::CopyAllTo. Override this method if your stream's data is in memory and thus can be written to iStreamW by a single call to its Write method.

Reimplemented from ZStreamR.

void ZStreamRW_FlushOnRead::Imp_CopyTo ( const ZStreamW iStreamW,
uint64  iCount,
uint64 oCountRead,
uint64 oCountWritten 
) [virtual]

Actually copy data from this stream to iStreamW.

The second part of the two-stage dispatch initiated by ZStreamW::CopyFrom and ZStreamW::CopyAllFrom. The default implementation calls sCopyReadToWrite. Override this method if your stream's data is in memory and thus can be written to iStreamW by a single call to its Write method.

See also:
sCopyReadToWrite

Reimplemented from ZStreamR.

void ZStreamRW_FlushOnRead::Imp_Skip ( uint64  iCount,
uint64 oCountSkipped 
) [virtual]

Read and discard iCount bytes.

Override this method if your stream implementation can skip past bytes in the stream without actually reading them.

Parameters:
iCount Count of bytes to be skipped.
oCountSkipped Number of bytes that were actually skipped. If iCount is non zero and oCountSkipped is set to zero then this indicates that the stream has reached its end.

Reimplemented from ZStreamR.

void ZStreamRW_FlushOnRead::Imp_CopyFromDispatch ( const ZStreamR iStreamR,
uint64  iCount,
uint64 oCountRead,
uint64 oCountWritten 
) [virtual]

Invoke iStreamR's Imp_CopyTo method.

The first part of the two-stage dispatch initiated by ZStreamW::CopyFrom and ZStreamW::CopyAllFrom. Override if your stream's data is in memory and thus iStreamR can have its Read method called with your stream's data as its destination.

Reimplemented from ZStreamW.

void ZStreamRW_FlushOnRead::Imp_CopyFrom ( const ZStreamR iStreamR,
uint64  iCount,
uint64 oCountRead,
uint64 oCountWritten 
) [virtual]

Actually copy data to this stream from iStreamR.

The second part of the two-stage dispatch initiated by ZStreamR::CopyTo and ZStreamR::CopyAllTo. The default implementation calls sCopyReadToWrite. Override this method if your stream's data is in memory and thus can be modified by calling iStreamR's Read method.

See also:
sCopyReadToWrite

Reimplemented from ZStreamW.


The documentation for this class was generated from the following files:
Generated on Thu Jul 26 11:22:04 2007 for ZooLib by  doxygen 1.4.7