glibmm: Gio::OutputStream Class Reference

Base class for implementing streaming output. More...

#include </home/kjell/checkout/gnome/glibmm/gio/giomm/outputstream.h>

Inheritance diagram for Gio::OutputStream:

Public Types

- Public Types inherited from Glib::Object
using DestroyNotify = void(*)(gpointer data)
 
- Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify func_destroy_notify
 
- Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify func_destroy_notify
 

Public Member Functions

 OutputStream (OutputStream&& src) noexcept
 
OutputStreamoperator= (OutputStream&& src) noexcept
 
 ~OutputStream () noexcept override
 
GOutputStream* gobj ()
 Provides access to the underlying C GObject. More...

 
const GOutputStream* gobj () const
 Provides access to the underlying C GObject. More...

 
GOutputStream* gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...

 
gssize write (const void* buffer, gsize count, const Glib::RefPtr< Cancellable >& cancellable)
 Tries to write count bytes from buffer into the stream. More...

 
gssize write (const void* buffer, gsize count)
 A write() convenience overload. More...

 
gssize write (const std::string& buffer, const Glib::RefPtr< Cancellable >& cancellable)
 Tries to write count bytes from buffer into the stream. More...

 
gssize write (const std::string& buffer)
 Tries to write count bytes from buffer into the stream. More...

 
bool write_all (const void* buffer, gsize count, gsize& bytes_written, const Glib::RefPtr< Cancellable >& cancellable)
 Tries to write count bytes from buffer into the stream. More...

 
bool write_all (const void* buffer, gsize count, gsize& bytes_written)
 A write_all() convenience overload. More...

 
bool write_all (const std::string& buffer, gsize& bytes_written, const Glib::RefPtr< Cancellable >& cancellable)
 Tries to write count bytes from buffer into the stream. More...

 
bool write_all (const std::string& buffer, gsize& bytes_written)
 Tries to write count bytes from buffer into the stream. More...

 
gssize write_bytes (const Glib::RefPtr< const Glib::Bytes >& bytes, const Glib::RefPtr< Cancellable >& cancellable)
 A wrapper function for g_output_stream_write() which takes a Bytes as input. More...

 
gssize write_bytes (const Glib::RefPtr< const Glib::Bytes >& bytes)
 A write_bytes() convenience overload. More...

 
void write_bytes_async (const Glib::RefPtr< const Glib::Bytes >& bytes, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous write of the data in bytes to the stream. More...

 
void write_bytes_async (const Glib::RefPtr< const Glib::Bytes >& bytes, const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous write of the data in bytes to the stream. More...

 
gssize write_bytes_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes a stream write-from-Bytes operation. More...

 
gssize splice (const Glib::RefPtr< InputStream >& source, const Glib::RefPtr< Cancellable >& cancellable, SpliceFlags flags=SpliceFlags::NONE)
 Splices an input stream into an output stream. More...

 
gssize splice (const Glib::RefPtr< InputStream >& source, SpliceFlags flags=SpliceFlags::NONE)
 Splices an input stream into an output stream. More...

 
bool flush (const Glib::RefPtr< Cancellable >& cancellable)
 Flushed any outstanding buffers in the stream. More...

 
bool flush ()
 A flush() convenience overload. More...

 
bool close (const Glib::RefPtr< Cancellable >& cancellable)
 Closes the stream, releasing resources related to it. More...

 
bool close ()
 A close() convenience overload. More...

 
void write_async (const void* buffer, gsize count, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous write of count bytes from buffer into the stream. More...

 
void write_async (const void* buffer, gsize count, const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous write of count bytes from buffer into the stream. More...

 
gssize write_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes a stream write operation. More...

 
void write_all_async (const void* buffer, gsize count, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous write of count bytes from buffer into the stream. More...

 
void write_all_async (const void* buffer, gsize count, const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Request an asynchronous write of count bytes from buffer into the stream. More...

 
bool write_all_finish (const Glib::RefPtr< AsyncResult >& result, gsize& bytes_written)
 Finishes an asynchronous stream write operation started with g_output_stream_write_all_async(). More...

 
void splice_async (const Glib::RefPtr< InputStream >& source, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, SpliceFlags flags=SpliceFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Splices a stream asynchronously. More...

 
void splice_async (const Glib::RefPtr< InputStream >& source, const SlotAsyncReady& slot, SpliceFlags flags=SpliceFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Splices a stream asynchronously. More...

 
gssize splice_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes an asynchronous stream splice operation. More...

 
void flush_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Flushes a stream asynchronously. More...

 
void flush_async (const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Flushes a stream asynchronously. More...

 
bool flush_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes flushing an output stream. More...

 
void close_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Requests an asynchronous close of the stream, releasing resources related to it. More...

 
void close_async (const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Requests an asynchronous close of the stream, releasing resources related to it. More...

 
bool close_finish (const Glib::RefPtr< AsyncResult >& result)
 Closes an output stream. More...

 
bool is_closed () const
 Checks if an output stream has already been closed. More...

 
bool is_closing () const
 Checks if an output stream is being closed. More...

 
bool has_pending () const
 Checks if an output stream has pending actions. More...

 
- Public Member Functions inherited from Glib::Object
 Object (const Object&)=delete
 
Objectoperator= (const Object&)=delete
 
 Object (Object&& src) noexcept
 
Objectoperator= (Object&& src) noexcept
 
void* get_data (const QueryQuark& key)
 
void set_data (const Quark& key, void* data)
 
void set_data (const Quark& key, void* data, DestroyNotify notify)
 
void remove_data (const QueryQuark& quark)
 
void* steal_data (const QueryQuark& quark)
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase&)=delete
 
ObjectBaseoperator= (const ObjectBase&)=delete
 
void set_property_value (const Glib::ustring& property_name, const Glib::ValueBase& value)
 You probably want to use a specific property_*() accessor method instead. More...

 
void get_property_value (const Glib::ustring& property_name, Glib::ValueBase& value) const
 You probably want to use a specific property_*() accessor method instead. More...

 
template<class PropertyType >
void set_property (const Glib::ustring& property_name, const PropertyType& value)
 You probably want to use a specific property_*() accessor method instead. More...

 
template<class PropertyType >
void get_property (const Glib::ustring& property_name, PropertyType& value) const
 You probably want to use a specific property_*() accessor method instead. More...

 
template<class PropertyType >
PropertyType get_property (const Glib::ustring& property_name) const
 You probably want to use a specific property_*() accessor method instead. More...

 
sigc::connection connect_property_changed (const Glib::ustring& property_name, const sigc::slot< void()>& slot)
 You can use the signal_changed() signal of the property proxy instead. More...

 
sigc::connection connect_property_changed (const Glib::ustring& property_name, sigc::slot< void()>&& slot)
 You can use the signal_changed() signal of the property proxy instead. More...

 
void freeze_notify ()
 Increases the freeze count on object. More...

 
void thaw_notify ()
 Reverts the effect of a previous call to freeze_notify(). More...

 
virtual void reference () const
 Increment the reference count for this object. More...

 
virtual void unreference () const
 Decrement the reference count for this object. More...

 
GObject* gobj ()
 Provides access to the underlying C GObject. More...

 
const GObject* gobj () const
 Provides access to the underlying C GObject. More...

 
GObject* gobj_copy () const
 Give a ref-ed copy to someone. Use for direct struct access. More...

 
- Public Member Functions inherited from sigc::trackable
 trackable () noexcept
 
 trackable (const trackable &src) noexcept
 
 trackable (trackable &&src) noexcept
 
 ~trackable ()
 
void add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
 
void notify_callbacks ()
 
trackableoperator= (const trackable &src)
 
trackableoperator= (trackable &&src) noexcept
 
void remove_destroy_notify_callback (notifiable *data) const
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...

 

Protected Member Functions

 OutputStream ()
 
bool set_pending ()
 Sets stream to have actions pending. More...

 
void clear_pending ()
 Clears the pending flag on stream. More...

 
virtual gssize write_vfunc (const void* buffer, gsize count, const Glib::RefPtr< Cancellable >& cancellable)
 
virtual gssize splice_vfunc (const Glib::RefPtr< InputStream >& source, const Glib::RefPtr< Cancellable >& cancellable, SpliceFlags flags)
 
virtual bool flush_vfunc (const Glib::RefPtr< Cancellable >& cancellable)
 
virtual bool close_vfunc (const Glib::RefPtr< Cancellable >& cancellable)
 
- Protected Member Functions inherited from Glib::Object
 Object ()
 
 Object (const Glib::ConstructParams& construct_params)
 
 Object (GObject* castitem)
 
 ~Object () noexcept override
 
- Protected Member Functions inherited from Glib::ObjectBase
 ObjectBase ()
 This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...

 
 ObjectBase (const char* custom_type_name)
 A derived constructor always overrides this choice. More...

 
 ObjectBase (const std::type_info& custom_type_info)
 This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...

 
 ObjectBase (ObjectBase&& src) noexcept
 
ObjectBaseoperator= (ObjectBase&& src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject* castitem)
 
void initialize_move (GObject* castitem, Glib::ObjectBase* previous_wrapper)
 

Related Functions

(Note that these are not member functions.)

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

 

Detailed Description

Base class for implementing streaming output.

Since glibmm 2.16:

Constructor & Destructor Documentation

Gio::OutputStream::OutputStream ( OutputStream&&  src)
noexcept
Gio::OutputStream::~OutputStream ( )
overridenoexcept
Gio::OutputStream::OutputStream ( )
protected

Member Function Documentation

void Gio::OutputStream::clear_pending ( )
protected

Clears the pending flag on stream.

Since glibmm 2.50:
bool Gio::OutputStream::close ( const Glib::RefPtr< Cancellable >&  cancellable)

Closes the stream, releasing resources related to it.

Once the stream is closed, all other operations will throw a Gio::Error with CLOSED. Closing a stream multiple times will not cause an error to be thrown.

Closing a stream will automatically flush any outstanding buffers in the stream.

Streams will be automatically closed when the last reference is dropped, but you might want to call this function to 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 throw a Gio::Error with CLOSED for all operations. Still, it is important to check and report the error to the user, otherwise there might be a loss of data as all data might not be written.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED. Cancelling a close will still leave the stream closed, but there some streams can use a faster close that doesn't block to e.g. check errors. On cancellation (as with any error) there is no guarantee that all written data will reach the target.

Parameters
cancellableCancellable object.
Returns
true on success, false on failure.
Exceptions
Glib::Error
bool Gio::OutputStream::close ( )

A close() convenience overload.

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

Requests an asynchronous close of the stream, releasing resources related to it.

When the operation is finished the slot will be called, giving the results. You can then call close_finish() to get the result of the operation. For behaviour details see close().

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters
slotCallback slot to call when the request is satisfied.
cancellableCancellable object.
io_priorityThe io priority of the request.
void Gio::OutputStream::close_async ( const SlotAsyncReady slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Requests an asynchronous close of the stream, releasing resources related to it.

When the operation is finished the slot will be called, giving the results. You can then call close_finish() to get the result of the operation. For behaviour details see close().

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters
slotCallback slot to call when the request is satisfied.
io_priorityThe io priority of the request.
bool Gio::OutputStream::close_finish ( const Glib::RefPtr< AsyncResult >&  result)

Closes an output stream.

Parameters
resultA AsyncResult.
Returns
true if stream was successfully closed, false otherwise.
Exceptions
Glib::Error
virtual bool Gio::OutputStream::close_vfunc ( const Glib::RefPtr< Cancellable >&  cancellable)
protectedvirtual
Exceptions
Glib::Error.
bool Gio::OutputStream::flush ( const Glib::RefPtr< Cancellable >&  cancellable)

Flushed any outstanding buffers in the stream.

Will block during the operation. Closing the stream will implicitly cause a flush.

This function is optional for inherited classes.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
cancellableCancellable object.
Returns
true on success, false on error.
Exceptions
Glib::Error
bool Gio::OutputStream::flush ( )

A flush() convenience overload.

void Gio::OutputStream::flush_async ( const SlotAsyncReady slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Flushes a stream asynchronously.

When the operation is finished the slot will be called, giving the results. You can then call flush_finish() to get the result of the operation. For behaviour details see flush().

Parameters
slotCallback slot to call when the request is satisfied.
cancellableCancellable object.
io_priorityThe io priority of the request.
void Gio::OutputStream::flush_async ( const SlotAsyncReady slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Flushes a stream asynchronously.

When the operation is finished the slot will be called, giving the results. You can then call flush_finish() to get the result of the operation. For behaviour details see flush().

Parameters
slotCallback slot to call when the request is satisfied.
io_priorityThe io priority of the request.
bool Gio::OutputStream::flush_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes flushing an output stream.

Parameters
resultA GAsyncResult.
Returns
true if flush operation succeeded, false otherwise.
Exceptions
Glib::Error
virtual bool Gio::OutputStream::flush_vfunc ( const Glib::RefPtr< Cancellable >&  cancellable)
protectedvirtual
Exceptions
Glib::Error.
static GType Gio::OutputStream::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

GOutputStream* Gio::OutputStream::gobj ( )
inline

Provides access to the underlying C GObject.

const GOutputStream* Gio::OutputStream::gobj ( ) const
inline

Provides access to the underlying C GObject.

GOutputStream* Gio::OutputStream::gobj_copy ( )

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

bool Gio::OutputStream::has_pending ( ) const

Checks if an output stream has pending actions.

Since glibmm 2.50:
Returns
true if stream has pending actions.
bool Gio::OutputStream::is_closed ( ) const

Checks if an output stream has already been closed.

Since glibmm 2.50:
Returns
true if stream is closed. false otherwise.
bool Gio::OutputStream::is_closing ( ) const

Checks if an output stream is being closed.

This can be used inside e.g. a flush implementation to see if the flush (or other i/o operation) is called from within the closing operation.

Since glibmm 2.50:
Returns
true if stream is being closed. false otherwise.
OutputStream& Gio::OutputStream::operator= ( OutputStream&&  src)
noexcept
bool Gio::OutputStream::set_pending ( )
protected

Sets stream to have actions pending.

If the pending flag is already set or stream is closed, it will return false and set error.

Since glibmm 2.50:
Returns
true if pending was previously unset and is now set.
Exceptions
Glib::Error
gssize Gio::OutputStream::splice ( const Glib::RefPtr< InputStream >&  source,
const Glib::RefPtr< Cancellable >&  cancellable,
SpliceFlags  flags = SpliceFlags::NONE 
)

Splices an input stream into an output stream.

Parameters
sourceAn InputStream.
flagsA set of SpliceFlags.
cancellableA Cancellable object. ignore.
Returns
A #gssize containing the size of the data spliced.
gssize Gio::OutputStream::splice ( const Glib::RefPtr< InputStream >&  source,
SpliceFlags  flags = SpliceFlags::NONE 
)

Splices an input stream into an output stream.

Parameters
sourceAn InputStream.
flagsA set of SpliceFlags. ignore.
Returns
A #gssize containing the size of the data spliced.
void Gio::OutputStream::splice_async ( const Glib::RefPtr< InputStream >&  source,
const SlotAsyncReady slot,
const Glib::RefPtr< Cancellable >&  cancellable,
SpliceFlags  flags = SpliceFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Splices a stream asynchronously.

When the operation is finished slot will be called. You can then call splice_finish() to get the result of the operation.

For the synchronous, blocking version of this function, see splice().

Parameters
sourceAn InputStream.
slotCallback slot to call when the request is satisfied.
cancellableCancellable object.
flagsA set of SpliceFlags.
io_priorityThe io priority of the request.
void Gio::OutputStream::splice_async ( const Glib::RefPtr< InputStream >&  source,
const SlotAsyncReady slot,
SpliceFlags  flags = SpliceFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Splices a stream asynchronously.

When the operation is finished slot will be called. You can then call splice_finish() to get the result of the operation.

For the synchronous, blocking version of this function, see splice().

Parameters
sourceAn InputStream.
slotCallback slot to call when the request is satisfied.
flagsA set of SpliceFlags.
io_priorityThe io priority of the request.
gssize Gio::OutputStream::splice_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes an asynchronous stream splice operation.

Parameters
resultA AsyncResult.
Returns
A #gssize of the number of bytes spliced. Note that if the number of bytes spliced is greater than G_MAXSSIZE, then that will be returned, and there is no way to determine the actual number of bytes spliced.
Exceptions
Glib::Error
virtual gssize Gio::OutputStream::splice_vfunc ( const Glib::RefPtr< InputStream >&  source,
const Glib::RefPtr< Cancellable >&  cancellable,
SpliceFlags  flags 
)
protectedvirtual
Exceptions
Glib::Error.
gssize Gio::OutputStream::write ( const void *  buffer,
gsize  count,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Tries to write count bytes from buffer into the stream.

Will block during the operation.

If count is zero returns zero and does nothing. A value of count larger than G_MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written to the stream is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial i/o error, or if there is not enough storage in the stream. All writes either block until at least one byte is written, so zero is never returned (unless count is zero).

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

Parameters
bufferThe buffer containing the data to write.
countThe number of bytes to write.
cancellableCancellable object.
Returns
Number of bytes written, or -1 on error.
Exceptions
Glib::Error
gssize Gio::OutputStream::write ( const void *  buffer,
gsize  count 
)

A write() convenience overload.

gssize Gio::OutputStream::write ( const std::string buffer,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Tries to write count bytes from buffer into the stream.

Will block during the operation.

If count is zero returns zero and does nothing. A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written to the stream is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial i/o error, or if the there is not enough storage in the stream. All writes either block until at least one byte is written, so zero is never returned (unless count is zero).

On error -1 is returned.

Parameters
bufferThe buffer containing the data to write.
cancellableCancellable object.
Returns
Number of bytes written, or -1 on error.
gssize Gio::OutputStream::write ( const std::string buffer)

Tries to write count bytes from buffer into the stream.

Will block during the operation.

If string that is larger than MAXSSIZE bytes will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written to the stream is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial i/o error, or if the there is not enough storage in the stream. All writes either block until at least one byte is written, so zero is never returned (unless count is zero).

On error -1 is returned.

Parameters
bufferThe buffer containing the data to write.
Returns
Number of bytes written, or -1 on error.
bool Gio::OutputStream::write_all ( const void *  buffer,
gsize  count,
gsize &  bytes_written,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Tries to write count bytes from buffer into the stream.

Will block during the operation.

This function is similar to g_output_stream_write(), except it tries to write as many bytes as requested, only stopping on an error.

On a successful write of count bytes, true is returned, and bytes_written is set to count.

If there is an error during the operation false is returned and error is set to indicate the error status.

As a special exception to the normal conventions for functions that use Error, if this function returns false (and sets error) then bytes_written will be set to the number of bytes that were successfully written before the error was encountered. This functionality is only available from C. If you need it from another language then you must write your own loop around g_output_stream_write().

Parameters
bufferThe buffer containing the data to write.
countThe number of bytes to write.
bytes_writtenLocation to store the number of bytes that was written to the stream.
cancellableOptional Cancellable object, nullptr to ignore.
Returns
true on success, false if there was an error.
Exceptions
Glib::Error
bool Gio::OutputStream::write_all ( const void *  buffer,
gsize  count,
gsize &  bytes_written 
)

A write_all() convenience overload.

bool Gio::OutputStream::write_all ( const std::string buffer,
gsize &  bytes_written,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Tries to write count bytes from buffer into the stream.

Will block during the operation.

This function is similar to write(), except it tries to write as many bytes as requested, only stopping on an error.

On a successful write of count bytes, true is returned, and bytes_written is set to count .

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

Parameters
bufferThe buffer containing the data to write.
bytes_writtenLocation to store the number of bytes that was written to the stream.
cancellableCancellable object.
Returns
true on success, false if there was an error.
bool Gio::OutputStream::write_all ( const std::string buffer,
gsize &  bytes_written 
)

Tries to write count bytes from buffer into the stream.

Will block during the operation.

This function is similar to write(), except it tries to write as many bytes as requested, only stopping on an error.

On a successful write of count bytes, true is returned, and bytes_written is set to count .

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

Parameters
bufferThe buffer containing the data to write.
bytes_writtenLocation to store the number of bytes that was written to the stream.
Returns
true on success, false if there was an error.
void Gio::OutputStream::write_all_async ( const void *  buffer,
gsize  count,
const SlotAsyncReady slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous write of count bytes from buffer into the stream.

When the operation is finished slot will be called. You can then call write_all_finish() to get the result of the operation.

This is the asynchronous version of write_all().

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written will be passed to the callback slot. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is Glib::PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

For the synchronous, blocking version of this function, see write().

Note that no copy of buffer will be made, so it must stay valid until slot is called.

Parameters
bufferThe buffer containing the data to write.
countThe number of bytes to write
slotCallback slot to call when the request is satisfied.
cancellableCancellable object.
io_priorityThe io priority of the request.
void Gio::OutputStream::write_all_async ( const void *  buffer,
gsize  count,
const SlotAsyncReady slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous write of count bytes from buffer into the stream.

When the operation is finished slot will be called. You can then call write_finish() to get the result of the operation.

This is the asynchronous version of write_all().

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written will be passed to the callback slot. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is Glib::PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

For the synchronous, blocking version of this function, see write().

Note that no copy of buffer will be made, so it must stay valid until slot is called.

Parameters
bufferThe buffer containing the data to write.
countThe number of bytes to write
slotCallback slot to call when the request is satisfied.
io_priorityThe io priority of the request.
bool Gio::OutputStream::write_all_finish ( const Glib::RefPtr< AsyncResult >&  result,
gsize &  bytes_written 
)

Finishes an asynchronous stream write operation started with g_output_stream_write_all_async().

As a special exception to the normal conventions for functions that use Error, if this function returns false (and sets error) then bytes_written will be set to the number of bytes that were successfully written before the error was encountered. This functionality is only available from C. If you need it from another language then you must write your own loop around g_output_stream_write_async().

Since glibmm 2.44:
Parameters
resultA AsyncResult.
bytes_writtenLocation to store the number of bytes that was written to the stream.
Returns
true on success, false if there was an error.
Exceptions
Glib::Error
void Gio::OutputStream::write_async ( const void *  buffer,
gsize  count,
const SlotAsyncReady slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous write of count bytes from buffer into the stream.

When the operation is finished slot will be called. You can then call write_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written will be passed to the callback slot. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is Glib::PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

For the synchronous, blocking version of this function, see write().

Note that no copy of buffer will be made, so it must stay valid until slot is called. See write_bytes_async() for a Glib::Bytes version that will automatically hold a reference to the contents (without copying) for the duration of the call.

Parameters
bufferThe buffer containing the data to write.
countThe number of bytes to write
slotCallback slot to call when the request is satisfied.
cancellableCancellable object.
io_priorityThe io priority of the request.
void Gio::OutputStream::write_async ( const void *  buffer,
gsize  count,
const SlotAsyncReady slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous write of count bytes from buffer into the stream.

When the operation is finished slot will be called. You can then call write_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written will be passed to the callback slot. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is Glib::PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

For the synchronous, blocking version of this function, see write().

Note that no copy of buffer will be made, so it must stay valid until slot is called. See write_bytes_async() for a Glib::Bytes version that will automatically hold a reference to the contents (without copying) for the duration of the call.

Parameters
bufferThe buffer containing the data to write.
countThe number of bytes to write
slotCallback slot to call when the request is satisfied.
io_priorityThe io priority of the request.
gssize Gio::OutputStream::write_bytes ( const Glib::RefPtr< const Glib::Bytes >&  bytes,
const Glib::RefPtr< Cancellable >&  cancellable 
)

A wrapper function for g_output_stream_write() which takes a Bytes as input.

This can be more convenient for use by language bindings or in other cases where the refcounted nature of Bytes is helpful over a bare pointer interface.

However, note that this function may still perform partial writes, just like g_output_stream_write(). If that occurs, to continue writing, you will need to create a new Bytes containing just the remaining bytes, using Glib::bytes_new_from_bytes(). Passing the same Bytes instance multiple times potentially can result in duplicated data in the output stream.

Parameters
bytesThe Bytes to write.
cancellableOptional cancellable object.
Returns
Number of bytes written, or -1 on error.
Exceptions
Glib::Error
gssize Gio::OutputStream::write_bytes ( const Glib::RefPtr< const Glib::Bytes >&  bytes)

A write_bytes() convenience overload.

void Gio::OutputStream::write_bytes_async ( const Glib::RefPtr< const Glib::Bytes >&  bytes,
const SlotAsyncReady slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous write of the data in bytes to the stream.

When the operation is finished slot will be called. You can then call write_bytes_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A Glib:Bytes larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written will be passed to the callback slot. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

You are guaranteed that this method will never fail with IO_ERROR_WOULD_BLOCK - if the stream can't accept more data, the method will just wait until this changes.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is Glib::PRIORITY_DEFAULT.

For the synchronous, blocking version of this function, see write_bytes().

Parameters
bytesThe bytes to
slotCallback slot to call when the request is satisfied.
cancellableCancellable object.
io_priorityThe io priority of the request.
Since glibmm 2.34:
void Gio::OutputStream::write_bytes_async ( const Glib::RefPtr< const Glib::Bytes >&  bytes,
const SlotAsyncReady slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Request an asynchronous write of the data in bytes to the stream.

When the operation is finished slot will be called. You can then call write_bytes_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A Glib:Bytes larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written will be passed to the callback slot. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

You are guaranteed that this method will never fail with IO_ERROR_WOULD_BLOCK - if the stream can't accept more data, the method will just wait until this changes.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is Glib::PRIORITY_DEFAULT.

For the synchronous, blocking version of this function, see write_bytes().

Parameters
bytesThe bytes to
slotCallback slot to call when the request is satisfied.
io_priorityThe io priority of the request.
Since glibmm 2.34:
gssize Gio::OutputStream::write_bytes_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes a stream write-from-Bytes operation.

Parameters
resultA AsyncResult.
Returns
A #gssize containing the number of bytes written to the stream.
Exceptions
Glib::Error
gssize Gio::OutputStream::write_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes a stream write operation.

Parameters
resultA AsyncResult.
Returns
A #gssize containing the number of bytes written to the stream.
Exceptions
Glib::Error
virtual gssize Gio::OutputStream::write_vfunc ( const void *  buffer,
gsize  count,
const Glib::RefPtr< Cancellable >&  cancellable 
)
protectedvirtual
Exceptions
Glib::Error.

Friends And Related Function Documentation

Glib::RefPtr< Gio::OutputStream > wrap ( GOutputStream *  object,
bool  take_copy = false 
)
related

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

Parameters
objectThe C instance.
take_copyFalse 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.