Loading...
Searching...
No Matches
Public Member Functions | List of all members
BDataIO Class Reference

Abstract interface for objects that provide read and write access to data. More...

Inherited by BAbstractSocket, BBufferedDataIO, BMemoryRingIO, and BPositionIO.

Public Member Functions

 BDataIO ()
 This constructor does nothing.
 
virtual ~BDataIO ()
 This destructor does nothing.
 
virtual status_t Flush ()
 Writes pending data to underlying storage.
 
virtual ssize_t Read (void *buffer, size_t size)
 Reads data from the object into a buffer.
 
status_t ReadExactly (void *buffer, size_t size, size_t *_bytesRead=NULL)
 Reads an exact amount of data from the object into a buffer.
 
virtual ssize_t Write (const void *buffer, size_t size)
 Writes data from a buffer to the object.
 
status_t WriteExactly (const void *buffer, size_t size, size_t *_bytesWritten=NULL)
 Writes an exact amount of data from a buffer to the object.
 

Detailed Description

Abstract interface for objects that provide read and write access to data.

The interface provided by this class applies to objects or data that are limited to reading and writing data. Classes derived from this class should re-implement the Read() or the Write() method from this class or both.

Candidates of types of data or objects that should be derived from this class are probably broadcasting media streams (which don't support reading at a certain point in the data) or network streams that output data continuously. Objects and data that support more advanced operations like seeking or reading at writing at defined positions should derive their classes from BPositionIO, which inherits this class.

Since
BeOS R3

Constructor & Destructor Documentation

◆ BDataIO()

BDataIO::BDataIO ( )

This constructor does nothing.

Since
BeOS R3

◆ ~BDataIO()

BDataIO::~BDataIO ( )
virtual

This destructor does nothing.

Since
BeOS R3

Member Function Documentation

◆ Flush()

status_t BDataIO::Flush ( )
virtual

Writes pending data to underlying storage.

This method is relevant for BDataIO implementations that buffer data passed to Write(). The Flush() implementation should make sure that all such data are written to the underlying storage.

The default implementation is a no-op returning B_OK.

Returns
An error code indicating whether flushing the buffered data succeeded.
Since
Haiku R1

Reimplemented in BBufferedDataIO, and BBufferIO.

◆ Read()

ssize_t BDataIO::Read ( void *  buffer,
size_t  size 
)
virtual

Reads data from the object into a buffer.

Your implementation should copy data into buffer, with the maximum size of size.

The default implementation is a no-op returning B_NOT_SUPPORTED.

Returns
You should return the amount of bytes actually read, or an error code in case of failure.
Since
BeOS R3

Reimplemented in BDatagramSocket, BFile, BBufferedDataIO, BPositionIO, and BMemoryRingIO.

◆ ReadExactly()

status_t BDataIO::ReadExactly ( void *  buffer,
size_t  size,
size_t *  _bytesRead = NULL 
)

Reads an exact amount of data from the object into a buffer.

This is a convenience wrapper method for Read() for code that expects the exact number of bytes requested to be read. This method calls Read() in a loop to read the data. It fails when Read() returns an error or fails to read any more data (i.e. returns 0).

Parameters
bufferPointer to pre-allocated storage of at least size bytes into which the data shall be read. Won't be dereferenced, when size is 0.
sizeThe number of bytes to be read.
_bytesReadOptional pointer to a pre-allocated size_t into which the number of bytes actually read will be written. When the method returns B_OK this will always be size. Can be NULL.
Returns
An error code indicating whether or not the method succeeded.
Return values
B_OKAll data have been read.
B_PARTIAL_READRead() didn't fail, but couldn't provide as many bytes as requested.
Since
Haiku R1

◆ Write()

ssize_t BDataIO::Write ( const void *  buffer,
size_t  size 
)
virtual

Writes data from a buffer to the object.

Your implementation should copy data from buffer, with the maximum size of size.

The default implementation is a no-op returning B_NOT_SUPPORTED.

Returns
You should return the amount of bytes actually written, or an error code in case of failure.
Since
BeOS R3

Reimplemented in BDatagramSocket, BFile, BBufferedDataIO, BPositionIO, and BMemoryRingIO.

◆ WriteExactly()

status_t BDataIO::WriteExactly ( const void *  buffer,
size_t  size,
size_t *  _bytesWritten = NULL 
)

Writes an exact amount of data from a buffer to the object.

This is a convenience wrapper method for Write() for code that expects the exact number of bytes given to be written. This method calls Write() in a loop to write the data. It fails when Write() returns an error or fails to write any more data (i.e. returns 0).

Parameters
bufferPointer to a buffer of at least size bytes containing the data to be written. Won't be dereferenced, when size is 0.
sizeThe number of bytes to be written.
_bytesWrittenOptional pointer to a pre-allocated size_t into which the number of bytes actually written will be written. When the method returns B_OK this will always be size. Can be NULL.
Returns
An error code indicated whether the method succeeded.
Return values
B_OKAll data have been written.
B_PARTIAL_READWrite() didn't fail, but couldn't write as many bytes as provided.
Since
Haiku R1