Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

atoms::BufferedStreamFilter Class Reference
[IO Subsystem]

#include <buffered_stream.hh>

Inheritance diagram for atoms::BufferedStreamFilter:

Inheritance graph
[legend]
Collaboration diagram for atoms::BufferedStreamFilter:

Collaboration graph
[legend]
List of all members.

Detailed Description

Buffered stream based on a raw stream instance.

If you wrap a raw stream in this way, you must be careful to not confuse the buffering:

Definition at line 331 of file buffered_stream.hh.

Public Member Functions

bool isOpen () const
bool isClosed () const
bool isReadable () const
bool isWritable () const
void flushOnce (const boost::shared_ptr< IOPoller > &poller, const boost::function< void()> &onSuccess, const boost::function< void(const IOError &)> &onError)
 Flushes the output buffer asynchronously.

virtual void pollForReadAvailability (const boost::shared_ptr< IOPoller > &, const boost::function< void()> &, const boost::function< void(const IOError &)> &)
 Notifies via a callback when it becomes possible to read.

virtual void readOnce (void *buf, size_t min, size_t max, const boost::shared_ptr< IOPoller > &, const boost::function< void(int)> &, const boost::function< void(const IOError &)> &)
 Reads data from the stream asynchronously.

bool usingAutoflush () const
 Returns true iff the stream will be automatically flushed on read.

void setAutoflush (bool autoflush)
 Sets if the output buffer should be flushed on any read.

Endian getEndian () const
 Gets the endianness.

void setEndian (Endian e)
 Sets the endianness.

virtual size_t read (void *buf, size_t min, size_t max=0)=0
 Reads data from the stream.

virtual void write (const void *buf, size_t size)=0
 Writes data to the stream.

virtual bool flush ()=0
 Attempts to flush the output buffer.

void setLocale (const std::locale &l)
 Sets the locale to use for character encoding conversion.

virtual bool isSeekable () const=0
BufferedStreamoperator>> (uint8_t &t)
BufferedStreamoperator>> (int8_t &t)
BufferedStreamoperator>> (uint16_t &t)
BufferedStreamoperator>> (int16_t &t)
BufferedStreamoperator>> (uint32_t &t)
BufferedStreamoperator>> (int32_t &t)
BufferedStreamoperator>> (uint64_t &t)
BufferedStreamoperator>> (int64_t &t)
BufferedStreamoperator<< (uint8_t t)
BufferedStreamoperator<< (int8_t t)
BufferedStreamoperator<< (uint16_t t)
BufferedStreamoperator<< (int16_t t)
BufferedStreamoperator<< (uint32_t t)
BufferedStreamoperator<< (int32_t t)
BufferedStreamoperator<< (uint64_t t)
BufferedStreamoperator<< (int64_t t)
virtual BufferedStreamoperator<< (const char *)=0
virtual BufferedStreamoperator<< (const std::basic_string< char > &)=0
virtual BufferedStreamoperator<< (const std::basic_string< wchar_t > &)=0

Static Public Member Functions

boost::shared_ptr< BufferedStreamFiltercreate (const boost::shared_ptr< Stream > &)
 Returns either a SeekableBufferedStreamFilter or a NonseekableBufferedStreamFilter based on the stream.


Protected Member Functions

 BufferedStreamFilter (const boost::shared_ptr< Stream > &s)

Protected Attributes

boost::shared_ptr< Streams
 The raw stream we're buffering.

bool autoflush
 If the stream should be automatically flushed on read.

std::locale locale
std::mbstate_t state
Endian endian
 The endianness for input and output of binary arithmetic types.

boost::weak_ptr< IOHandlethisWeak
 A weak pointer to 'this' for source in IOError.


Private Member Functions

void tryFlush (bool polling, const boost::shared_ptr< IOPoller > &poller, const boost::function< void()> &onSuccess, const boost::function< void(const IOError &)> &onError)
 Part of the implementation of flushOnce.

void pollForReadAvailability2 (const boost::shared_ptr< IOPoller > &, const boost::function< void()> &, const boost::function< void(const IOError &)> &)
void tryRead (const boost::shared_ptr< ReadRequest > &)
 Part of the implementation of tryRead.


Static Private Attributes

DebugLogger LOGGER


Constructor & Destructor Documentation

atoms::BufferedStreamFilter::BufferedStreamFilter const boost::shared_ptr< Stream > &  s  )  [inline, protected]
 

Definition at line 333 of file buffered_stream.hh.


Member Function Documentation

shared_ptr< BufferedStreamFilter > atoms::BufferedStreamFilter::create const boost::shared_ptr< Stream > &   )  [static]
 

Returns either a SeekableBufferedStreamFilter or a NonseekableBufferedStreamFilter based on the stream.

Definition at line 31 of file buffered_stream.cc.

References atoms::NonseekableBufferedStreamFilter().

Here is the call graph for this function:

virtual bool atoms::BufferedStream::flush  )  [pure virtual, inherited]
 

Attempts to flush the output buffer.

If the buffer can not be flushed successfully, an exception will be thrown, unless the error is due to non-blocking IO.

Precondition:
Stream is opened and writable.
Returns:
True if the flush succeeded, false if it was not due to non-blocking IO.
Exceptions:
IOError for other errors.

Referenced by tryFlush().

void atoms::BufferedStreamFilter::flushOnce const boost::shared_ptr< IOPoller > &  poller,
const boost::function< void()> &  onSuccess,
const boost::function< void(const IOError &)> &  onError
[inline, virtual]
 

Flushes the output buffer asynchronously.

Note:
This may be a redundant operation if autoflush is enabled. Read operations will automatically flush in that case.
See also:
flush(), getAutoflush()

Implements atoms::BufferedStream.

Definition at line 348 of file buffered_stream.hh.

Referenced by pollForReadAvailability().

Endian atoms::BufferedStream::getEndian  )  const [inline, inherited]
 

Gets the endianness.

Defaults to eNetwork.

Definition at line 73 of file buffered_stream.hh.

bool atoms::BufferedStreamFilter::isClosed  )  const [inline, virtual]
 

See also:
Stream::isOpen

Implements atoms::BufferedStream.

Definition at line 344 of file buffered_stream.hh.

bool atoms::BufferedStreamFilter::isOpen  )  const [inline, virtual]
 

See also:
Stream::isOpen

Implements atoms::BufferedStream.

Definition at line 343 of file buffered_stream.hh.

bool atoms::BufferedStreamFilter::isReadable  )  const [inline, virtual]
 

See also:
Stream::isOpen

Implements atoms::BufferedStream.

Definition at line 345 of file buffered_stream.hh.

virtual bool atoms::BufferedStream::isSeekable  )  const [pure virtual, inherited]
 

See also:
Stream::isSeekable

bool atoms::BufferedStreamFilter::isWritable  )  const [inline, virtual]
 

See also:
Stream::isOpen

Implements atoms::BufferedStream.

Definition at line 346 of file buffered_stream.hh.

virtual BufferedStream& atoms::BufferedStream::operator<< const std::basic_string< wchar_t > &   )  [pure virtual, inherited]
 

virtual BufferedStream& atoms::BufferedStream::operator<< const std::basic_string< char > &   )  [pure virtual, inherited]
 

virtual BufferedStream& atoms::BufferedStream::operator<< const char *   )  [pure virtual, inherited]
 

BufferedStream& atoms::BufferedStream::operator<< int64_t  t  )  [inline, inherited]
 

See also:
write(const void*, size_t)

Definition at line 192 of file buffered_stream.hh.

BufferedStream& atoms::BufferedStream::operator<< uint64_t  t  )  [inline, inherited]
 

See also:
write(const void*, size_t)

Definition at line 191 of file buffered_stream.hh.

References atoms::BufferedStream::writeIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator<< int32_t  t  )  [inline, inherited]
 

See also:
write(const void*, size_t)

Definition at line 190 of file buffered_stream.hh.

References atoms::BufferedStream::writeIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator<< uint32_t  t  )  [inline, inherited]
 

See also:
write(const void*, size_t)

Definition at line 189 of file buffered_stream.hh.

References atoms::BufferedStream::writeIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator<< int16_t  t  )  [inline, inherited]
 

See also:
write(const void*, size_t)

Definition at line 188 of file buffered_stream.hh.

References atoms::BufferedStream::writeIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator<< uint16_t  t  )  [inline, inherited]
 

See also:
write(const void*, size_t)

Definition at line 187 of file buffered_stream.hh.

References atoms::BufferedStream::writeIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator<< int8_t  t  )  [inline, inherited]
 

See also:
write(const void*, size_t)

Definition at line 186 of file buffered_stream.hh.

References atoms::BufferedStream::writeIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator<< uint8_t  t  )  [inline, inherited]
 

See also:
write(const void*, size_t)

Definition at line 185 of file buffered_stream.hh.

References atoms::BufferedStream::writeIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator>> int64_t &  t  )  [inline, inherited]
 

Note:
These read operations should not be chained if they may throw an exception for which you care how many completed successfully. In particular, you shouldn't chain them when using non-blocking IO.
See also:
read(void*,size_t,size_t)

Definition at line 163 of file buffered_stream.hh.

BufferedStream& atoms::BufferedStream::operator>> uint64_t &  t  )  [inline, inherited]
 

Note:
These read operations should not be chained if they may throw an exception for which you care how many completed successfully. In particular, you shouldn't chain them when using non-blocking IO.
See also:
read(void*,size_t,size_t)

Definition at line 162 of file buffered_stream.hh.

References atoms::BufferedStream::readIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator>> int32_t &  t  )  [inline, inherited]
 

Note:
These read operations should not be chained if they may throw an exception for which you care how many completed successfully. In particular, you shouldn't chain them when using non-blocking IO.
See also:
read(void*,size_t,size_t)

Definition at line 161 of file buffered_stream.hh.

References atoms::BufferedStream::readIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator>> uint32_t &  t  )  [inline, inherited]
 

Note:
These read operations should not be chained if they may throw an exception for which you care how many completed successfully. In particular, you shouldn't chain them when using non-blocking IO.
See also:
read(void*,size_t,size_t)

Definition at line 160 of file buffered_stream.hh.

References atoms::BufferedStream::readIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator>> int16_t &  t  )  [inline, inherited]
 

Note:
These read operations should not be chained if they may throw an exception for which you care how many completed successfully. In particular, you shouldn't chain them when using non-blocking IO.
See also:
read(void*,size_t,size_t)

Definition at line 159 of file buffered_stream.hh.

References atoms::BufferedStream::readIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator>> uint16_t &  t  )  [inline, inherited]
 

Note:
These read operations should not be chained if they may throw an exception for which you care how many completed successfully. In particular, you shouldn't chain them when using non-blocking IO.
See also:
read(void*,size_t,size_t)

Definition at line 158 of file buffered_stream.hh.

References atoms::BufferedStream::readIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator>> int8_t &  t  )  [inline, inherited]
 

Note:
These read operations should not be chained if they may throw an exception for which you care how many completed successfully. In particular, you shouldn't chain them when using non-blocking IO.
See also:
read(void*,size_t,size_t)

Definition at line 157 of file buffered_stream.hh.

References atoms::BufferedStream::readIntegralType().

Here is the call graph for this function:

BufferedStream& atoms::BufferedStream::operator>> uint8_t &  t  )  [inline, inherited]
 

Note:
These read operations should not be chained if they may throw an exception for which you care how many completed successfully. In particular, you shouldn't chain them when using non-blocking IO.
See also:
read(void*,size_t,size_t)

Definition at line 156 of file buffered_stream.hh.

References atoms::BufferedStream::readIntegralType().

Here is the call graph for this function:

void atoms::BufferedStreamFilter::pollForReadAvailability const boost::shared_ptr< IOPoller > &  ,
const boost::function< void()> &  ,
const boost::function< void(const IOError &)> & 
[virtual]
 

Notifies via a callback when it becomes possible to read.

Honors autoflush first.

Implements atoms::BufferedStream.

Definition at line 71 of file buffered_stream.cc.

References flushOnce().

Referenced by readOnce().

Here is the call graph for this function:

void atoms::BufferedStreamFilter::pollForReadAvailability2 const boost::shared_ptr< IOPoller > &  ,
const boost::function< void()> &  ,
const boost::function< void(const IOError &)> & 
[private]
 

Definition at line 84 of file buffered_stream.cc.

References atoms::UNIXDescriptor::pollForReadAvailability(), and s.

Here is the call graph for this function:

virtual size_t atoms::BufferedStream::read void buf,
size_t  min,
size_t  max = 0
[pure virtual, inherited]
 

Reads data from the stream.

If autoflush is set (default), flushes the output before reading.

Parameters:
buf Is where the data will be stored.
min Is the minimum number of bytes to read
max Is the maximum number of bytes to read. For convenience, 0 (the default) will be replaced with min
Precondition:
The stream is opened and readable

0 < min <= max || (0 < min && max == 0)

Exceptions:
IOError if thrown by the underlying stream. Any successfully read data are kept in the input buffer to be retrieved on the next call.
StreamEndError if min bytes will never be available.
IOBlockError if non-blocking mode is selected and min bytes are not available.
Returns:
The number of bytes successfully stored in buf.
See also:
write, unread, setAutoflush, usingAutoflush

Referenced by tryRead().

void atoms::BufferedStreamFilter::readOnce void buf,
size_t  min,
size_t  max,
const boost::shared_ptr< IOPoller > &  ,
const boost::function< void(int)> &  ,
const boost::function< void(const IOError &)> & 
[virtual]
 

Reads data from the stream asynchronously.

This is similar to read(void*,size_t,size_t), but automatically registers the stream with a poller to arrange for the callback when complete.

Note:
Don't change the autoflush behavior while this is pending.

Deprecated:
I'm not sure this is as useful as I'd originally imagined, as you need to have the buffer around in advance and such. Tell me if you find it helpful.

Implements atoms::BufferedStream.

Definition at line 96 of file buffered_stream.cc.

References std::max(), std::min(), and pollForReadAvailability().

Here is the call graph for this function:

void atoms::BufferedStream::setAutoflush bool  autoflush  )  [inline, inherited]
 

Sets if the output buffer should be flushed on any read.

Precondition:
autoflush is true if this is a seekable stream. Disabling autoflush on such a stream is not allowed, as it would throw off positioning of mixed reads and writes.

Definition at line 64 of file buffered_stream.hh.

void atoms::BufferedStream::setEndian Endian  e  )  [inline, inherited]
 

Sets the endianness.

Defaults to eNetwork.

Definition at line 79 of file buffered_stream.hh.

References atoms::BufferedStream::endian.

void atoms::BufferedStream::setLocale const std::locale &  l  )  [inline, inherited]
 

Sets the locale to use for character encoding conversion.

Defaults to the global locale at time of BufferedStream creation.

Todo:
What should happen with the state here?

Definition at line 245 of file buffered_stream.hh.

void atoms::BufferedStreamFilter::tryFlush bool  polling,
const boost::shared_ptr< IOPoller > &  poller,
const boost::function< void()> &  onSuccess,
const boost::function< void(const IOError &)> &  onError
[private]
 

Part of the implementation of flushOnce.

Definition at line 43 of file buffered_stream.cc.

References atoms::UNIXDescriptor::cancelPoll(), atoms::BufferedStream::flush(), atoms::UNIXDescriptor::pollForWriteAvailability(), and s.

Here is the call graph for this function:

void atoms::BufferedStreamFilter::tryRead const boost::shared_ptr< ReadRequest > &   )  [private]
 

Part of the implementation of tryRead.

Definition at line 113 of file buffered_stream.cc.

References atoms::BufferedStream::read().

Here is the call graph for this function:

bool atoms::BufferedStream::usingAutoflush  )  const [inline, inherited]
 

Returns true iff the stream will be automatically flushed on read.

Definition at line 52 of file buffered_stream.hh.

References atoms::BufferedStream::autoflush.

virtual void atoms::BufferedStream::write const void buf,
size_t  size
[pure virtual, inherited]
 

Writes data to the stream.

No data are written until the next time flush() succeeds. Never throws IOError.

Exceptions:
MemoryError if there is no available storage space. The state of the stream will be as before.
Precondition:
Stream is open and writable.
Parameters:
buf Holds the data to write.
size The number of bytes contained in buf.


Member Data Documentation

bool atoms::BufferedStream::autoflush [protected, inherited]
 

If the stream should be automatically flushed on read.

Definition at line 275 of file buffered_stream.hh.

Referenced by atoms::BufferedStream::usingAutoflush().

Endian atoms::BufferedStream::endian [protected, inherited]
 

The endianness for input and output of binary arithmetic types.

Definition at line 291 of file buffered_stream.hh.

Referenced by atoms::BufferedStream::BufferedStream(), and atoms::BufferedStream::setEndian().

std::locale atoms::BufferedStream::locale [protected, inherited]
 

Definition at line 287 of file buffered_stream.hh.

DebugLogger atoms::BufferedStreamFilter::LOGGER [static, private]
 

boost::shared_ptr<Stream> atoms::BufferedStreamFilter::s [protected]
 

The raw stream we're buffering.

Definition at line 366 of file buffered_stream.hh.

Referenced by pollForReadAvailability2(), and tryFlush().

std::mbstate_t atoms::BufferedStream::state [protected, inherited]
 

Definition at line 288 of file buffered_stream.hh.

boost::weak_ptr<IOHandle> atoms::IOHandle::thisWeak [protected, inherited]
 

A weak pointer to 'this' for source in IOError.

Definition at line 175 of file gen.hh.


The documentation for this class was generated from the following files:
Generated on Wed Jun 15 01:20:43 2005 for atoms++ by doxygen 1.3.5