logo top
Main Page   Widgets   glibmm Namespaces   Book  

Gio::InputStream Class Reference

Base class for implementing streaming input. More...

Inheritance diagram for Gio::InputStream:

Inheritance graph
[legend]
List of all members.

Public Member Functions

virtual ~InputStream ()
GInputStream* gobj ()
 Provides access to the underlying C GObject.
const GInputStream* gobj () const
 Provides access to the underlying C GObject.
GInputStream* gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
gssize read (void* buffer, gsize count, const Glib::RefPtr<Cancellable>& cancellable)
 Tries to read count bytes from the stream into the buffer starting at buffer .
bool read_all (void* buffer, gsize count, gsize& bytes_read, const Glib::RefPtr<Cancellable>& cancellable)
 Tries to read count bytes from the stream into the buffer starting at buffer .
gssize skip (gsize count, const Glib::RefPtr<Cancellable>& cancellable)
 Tries to skip count bytes from the stream.
bool close (const Glib::RefPtr<Cancellable>& cancellable)
 Closes the stream, releasing resources related to it.
void read_async (void* buffer, gsize count, const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int io_priority=G_PRIORITY_DEFAULT)
gssize read_finish (const Glib::RefPtr<AsyncResult>& result)
 Finishes an asynchronous stream read operation.
void skip_async (gsize count, const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int io_priority=G_PRIORITY_DEFAULT)
gssize skip_finish (const Glib::RefPtr<AsyncResult>& result)
 Finishes a stream skip operation.
void close_async (const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int io_priority=G_PRIORITY_DEFAULT)
gboolean close_finish (const Glib::RefPtr<AsyncResult>& result)
 Finishes closing a stream asynchronously, started from g_input_stream_close_async().

Related Functions

(Note that these are not member functions.)

Glib::RefPtr<Gio::InputStreamwrap (GInputStream* object, bool take_copy=false)
 A Glib::wrap() method for this object.

Detailed Description

Base class for implementing streaming input.

Since glibmm 2.16:


Constructor & Destructor Documentation

virtual Gio::InputStream::~InputStream (  )  [virtual]


Member Function Documentation

GInputStream* Gio::InputStream::gobj (  )  [inline]

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

Reimplemented in Gio::FileInputStream.

const GInputStream* Gio::InputStream::gobj (  )  const [inline]

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

Reimplemented in Gio::FileInputStream.

GInputStream* Gio::InputStream::gobj_copy (  ) 

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

Reimplemented in Gio::FileInputStream.

gssize Gio::InputStream::read ( void *  buffer,
gsize  count,
const Glib::RefPtr<Cancellable>&  cancellable 
)

Tries to read count bytes from the stream into the buffer starting at buffer .

Will block during this read.

If count is zero returns zero and does nothing. A value of count larger than G::MAXSSIZE will cause a G::IO_ERROR_INVALID_ARGUMENT error.

On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if count is zero), but never otherwise.

If cancellable is not 0, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error -1 is returned and error is set accordingly.

Parameters:
buffer A buffer to read data into (which should be at least count bytes long).
count The number of bytes that will be read from the stream.
cancellable Optional G::Cancellable object, 0 to ignore.
error Location to store the error occuring, or 0 to ignore.
Returns:
Number of bytes read, or -1 on error.

bool Gio::InputStream::read_all ( void *  buffer,
gsize  count,
gsize &  bytes_read,
const Glib::RefPtr<Cancellable>&  cancellable 
)

Tries to read count bytes from the stream into the buffer starting at buffer .

Will block during this read.

This function is similar to g_input_stream_read(), except it tries to read as many bytes as requested, only stopping on an error or end of stream.

On a successful read of count bytes, or if we reached the end of the stream, true is returned, and bytes_read is set to the number of bytes read into buffer .

If there is an error during the operation false is returned and error is set to indicate the error status, bytes_read is updated to contain the number of bytes read into buffer before the error occured.

Parameters:
buffer A buffer to read data into (which should be at least count bytes long).
count The number of bytes that will be read from the stream.
bytes_read Location to store the number of bytes that was read from the stream.
cancellable Optional G::Cancellable object, 0 to ignore.
error Location to store the error occuring, or 0 to ignore.
Returns:
true on success, false if there was an error.

gssize Gio::InputStream::skip ( gsize  count,
const Glib::RefPtr<Cancellable>&  cancellable 
)

Tries to skip count bytes from the stream.

Will block during the operation.

This is identical to g_input_stream_read(), from a behaviour standpoint, but the bytes that are skipped are not returned to the user. Some streams have an implementation that is more efficient than reading the data.

This function is optional for inherited classes, as the default implementation emulates it using read.

If cancellable is not 0, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G::IO_ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

Parameters:
count The number of bytes that will be skipped from the stream.
cancellable Optional G::Cancellable object, 0 to ignore.
error Location to store the error occuring, or 0 to ignore.
Returns:
Number of bytes skipped, or -1 on error.

bool Gio::InputStream::close ( const Glib::RefPtr<Cancellable>&  cancellable  ) 

Closes the stream, releasing resources related to it.

Once the stream is closed, all other operations will return G::IO_ERROR_CLOSED. Closing a stream multiple times will not return an error.

Streams will be automatically closed when the last reference is dropped, but you might want to call make sure resources are released as early as possible.

Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details.

On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still return G::IO_ERROR_CLOSED all operations. Still, it is important to check and report the error to the user.

If cancellable is not 0, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G::IO_ERROR_CANCELLED will be returned. Cancelling a close will still leave the stream closed, but some streams can use a faster close that doesn't block to e.g. check errors.

Parameters:
cancellable Optional G::Cancellable object, 0 to ignore.
error Location to store the error occuring, or 0 to ignore.
Returns:
true on success, false on failure.

void Gio::InputStream::read_async ( void *  buffer,
gsize  count,
const SlotAsyncReady slot,
const Glib::RefPtr<Cancellable>&  cancellable,
int  io_priority = G_PRIORITY_DEFAULT 
)

gssize Gio::InputStream::read_finish ( const Glib::RefPtr<AsyncResult>&  result  ) 

Finishes an asynchronous stream read operation.

Parameters:
result A G::AsyncResult.
error A G::Error location to store the error occuring, or 0 to ignore.
Returns:
Number of bytes read in, or -1 on error.

void Gio::InputStream::skip_async ( gsize  count,
const SlotAsyncReady slot,
const Glib::RefPtr<Cancellable>&  cancellable,
int  io_priority = G_PRIORITY_DEFAULT 
)

gssize Gio::InputStream::skip_finish ( const Glib::RefPtr<AsyncResult>&  result  ) 

Finishes a stream skip operation.

Parameters:
result A G::AsyncResult.
error A G::Error location to store the error occuring, or 0 to ignore.
Returns:
The size of the bytes skipped, or -1 on error.

void Gio::InputStream::close_async ( const SlotAsyncReady slot,
const Glib::RefPtr<Cancellable>&  cancellable,
int  io_priority = G_PRIORITY_DEFAULT 
)

gboolean Gio::InputStream::close_finish ( const Glib::RefPtr<AsyncResult>&  result  ) 

Finishes closing a stream asynchronously, started from g_input_stream_close_async().

Parameters:
result A G::AsyncResult.
error A G::Error location to store the error occuring, or 0 to ignore.
Returns:
true if the stream was closed successfully.


Friends And Related Function Documentation

Glib::RefPtr<Gio::InputStream> wrap ( GInputStream *  object,
bool  take_copy = false 
) [related]

A Glib::wrap() method for this object.

Parameters:
object The C instance.
take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns:
A C++ instance that wraps this C instance.


The documentation for this class was generated from the following file:

Generated for glibmm 2.4 by Doxygen 1.5.1 © 1997-2001