glibmm 2.80.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gio::OutputStream Class Reference

Base class for implementing streaming output. More...

#include <giomm/outputstream.h>

Inheritance diagram for Gio::OutputStream:
Inheritance graph
[legend]

Public Types

enum class  SpliceFlags {
  NONE = 0x0 ,
  CLOSE_SOURCE = (1 << 0) ,
  CLOSE_TARGET = (1 << 1)
}
 
- Public Types inherited from Glib::Object
using DestroyNotify = void(*)(gpointer data)
 

Public Member Functions

 OutputStream (OutputStream &&src) noexcept
 
OutputStreamoperator= (OutputStream &&src) noexcept
 
 ~OutputStream () noexcept override
 
GOutputStreamgobj ()
 Provides access to the underlying C GObject.
 
const GOutputStreamgobj () const
 Provides access to the underlying C GObject.
 
GOutputStreamgobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
 
gssize write (const void *buffer, gsize count, const Glib::RefPtr< Cancellable > &cancellable)
 Tries to write count bytes from buffer into the stream.
 
gssize write (const void *buffer, gsize count)
 A write() convenience overload.
 
gssize write (const std::string &buffer, const Glib::RefPtr< Cancellable > &cancellable)
 Tries to write count bytes from buffer into the stream.
 
gssize write (const std::string &buffer)
 Tries to write count bytes from buffer into the stream.
 
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.
 
bool write_all (const void *buffer, gsize count, gsize &bytes_written)
 A write_all() convenience overload.
 
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.
 
bool write_all (const std::string &buffer, gsize &bytes_written)
 Tries to write count bytes from buffer into the stream.
 
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.
 
gssize write_bytes (const Glib::RefPtr< const Glib::Bytes > & bytes)
 A write_bytes() convenience overload.
 
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.
 
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.
 
gssize write_bytes_finish (const Glib::RefPtr< AsyncResult > &result)
 Finishes a stream write-from-Bytes operation.
 
gssize splice (const Glib::RefPtr< InputStream > &source, const Glib::RefPtr< Cancellable > &cancellable, SpliceFlags flags=SpliceFlags::NONE)
 Splices an input stream into an output stream.
 
gssize splice (const Glib::RefPtr< InputStream > &source, SpliceFlags flags=SpliceFlags::NONE)
 Splices an input stream into an output stream.
 
bool flush (const Glib::RefPtr< Cancellable > &cancellable)
 Flushed any outstanding buffers in the stream.
 
bool flush ()
 A flush() convenience overload.
 
bool close (const Glib::RefPtr< Cancellable > &cancellable)
 Closes the stream, releasing resources related to it.
 
bool close ()
 A close() convenience overload.
 
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.
 
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.
 
gssize write_finish (const Glib::RefPtr< AsyncResult > &result)
 Finishes a stream write operation.
 
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.
 
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.
 
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().
 
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.
 
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.
 
gssize splice_finish (const Glib::RefPtr< AsyncResult > &result)
 Finishes an asynchronous stream splice operation.
 
void flush_async (const SlotAsyncReady &slot, const Glib::RefPtr< Cancellable > &cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Flushes a stream asynchronously.
 
void flush_async (const SlotAsyncReady &slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Flushes a stream asynchronously.
 
bool flush_finish (const Glib::RefPtr< AsyncResult > &result)
 Finishes flushing an output stream.
 
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.
 
void close_async (const SlotAsyncReady &slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Requests an asynchronous close of the stream, releasing resources related to it.
 
bool close_finish (const Glib::RefPtr< AsyncResult > &result)
 Closes an output stream.
 
bool is_closed () const
 Checks if an output stream has already been closed.
 
bool is_closing () const
 Checks if an output stream is being closed.
 
bool has_pending () const
 Checks if an output stream has pending actions.
 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&src) noexcept
 
Objectoperator= (Object &&src) noexcept
 
voidget_data (const QueryQuark & key)
 
void set_data (const Quark & key, void *data)
 
void set_data_with_c_callback (const Quark & key, void *data, GDestroyNotify notify)
 
void set_data (const Quark & key, void *data, DestroyNotify notify)
 Prefer set_data_with_c_callback() with a callback with C linkage.
 
void remove_data (const QueryQuark &quark)
 
voidsteal_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.
 
void get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
 You probably want to use a specific property_*() accessor method instead.
 
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.
 
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.
 
template<class PropertyType >
PropertyType get_property (const Glib::ustring & property_name) const
 You probably want to use a specific property_*() accessor method instead.
 
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.
 
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.
 
void freeze_notify ()
 Increases the freeze count on object.
 
void thaw_notify ()
 Reverts the effect of a previous call to freeze_notify().
 
virtual void reference () const
 Increment the reference count for this object.
 
virtual void unreference () const
 Decrement the reference count for this object.
 
GObject * gobj ()
 Provides access to the underlying C GObject.
 
const GObject * gobj () const
 Provides access to the underlying C GObject.
 
GObject * gobj_copy () const
 Give a ref-ed copy to someone. Use for direct struct access.
 

Static Public Member Functions

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

Protected Member Functions

 OutputStream ()
 
bool set_pending ()
 Sets stream to have actions pending.
 
void clear_pending ()
 Clears the pending flag on stream.
 
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.
 
 ObjectBase (const char *custom_type_name)
 A derived constructor always overrides this choice.
 
 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.
 
 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 Symbols

(Note that these are not member symbols.)

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

Detailed Description

Base class for implementing streaming output.

Since glibmm 2.16:

Member Enumeration Documentation

◆ SpliceFlags

Enumerator
NONE 

Do not close either stream.

CLOSE_SOURCE 

Close the source stream after the splice.

CLOSE_TARGET 

Close the target stream after the splice.

Constructor & Destructor Documentation

◆ OutputStream() [1/2]

Gio::OutputStream::OutputStream ( OutputStream &&  src)
noexcept

◆ ~OutputStream()

Gio::OutputStream::~OutputStream ( )
overridenoexcept

◆ OutputStream() [2/2]

Gio::OutputStream::OutputStream ( )
protected

Member Function Documentation

◆ clear_pending()

void Gio::OutputStream::clear_pending ( )
protected

Clears the pending flag on stream.

Since glibmm 2.50:

◆ close() [1/2]

bool Gio::OutputStream::close ( )

A close() convenience overload.

◆ close() [2/2]

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

◆ close_async() [1/2]

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.

◆ close_async() [2/2]

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.

◆ close_finish()

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

◆ close_vfunc()

virtual bool Gio::OutputStream::close_vfunc ( const Glib::RefPtr< Cancellable > &  cancellable)
protectedvirtual
Exceptions
Glib::Error.

◆ flush() [1/2]

bool Gio::OutputStream::flush ( )

A flush() convenience overload.

◆ flush() [2/2]

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

◆ flush_async() [1/2]

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.

◆ flush_async() [2/2]

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.

◆ flush_finish()

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

◆ flush_vfunc()

virtual bool Gio::OutputStream::flush_vfunc ( const Glib::RefPtr< Cancellable > &  cancellable)
protectedvirtual
Exceptions
Glib::Error.

◆ get_type()

static GType Gio::OutputStream::get_type ( )
static

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

◆ gobj() [1/2]

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

Provides access to the underlying C GObject.

◆ gobj() [2/2]

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

Provides access to the underlying C GObject.

◆ gobj_copy()

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.

◆ has_pending()

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.

◆ is_closed()

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.

◆ is_closing()

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.

◆ operator=()

OutputStream & Gio::OutputStream::operator= ( OutputStream &&  src)
noexcept

◆ set_pending()

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

◆ splice() [1/2]

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.

◆ splice() [2/2]

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.

◆ splice_async() [1/2]

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.

◆ splice_async() [2/2]

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.

◆ splice_finish()

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

◆ splice_vfunc()

virtual gssize Gio::OutputStream::splice_vfunc ( const Glib::RefPtr< InputStream > &  source,
const Glib::RefPtr< Cancellable > &  cancellable,
SpliceFlags  flags 
)
protectedvirtual
Exceptions
Glib::Error.

◆ write() [1/4]

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.

◆ write() [2/4]

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.

◆ write() [3/4]

gssize Gio::OutputStream::write ( const void buffer,
gsize  count 
)

A write() convenience overload.

◆ write() [4/4]

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

◆ write_all() [1/4]

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.

◆ write_all() [2/4]

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.

◆ write_all() [3/4]

bool Gio::OutputStream::write_all ( const void buffer,
gsize  count,
gsize bytes_written 
)

A write_all() convenience overload.

◆ write_all() [4/4]

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

◆ write_all_async() [1/2]

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.

◆ write_all_async() [2/2]

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.

◆ write_all_finish()

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

◆ write_async() [1/2]

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.

◆ write_async() [2/2]

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.

◆ write_bytes() [1/2]

gssize Gio::OutputStream::write_bytes ( const Glib::RefPtr< const Glib::Bytes > &  bytes)

A write_bytes() convenience overload.

◆ write_bytes() [2/2]

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

◆ write_bytes_async() [1/2]

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:

◆ write_bytes_async() [2/2]

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:

◆ write_bytes_finish()

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

◆ write_finish()

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

◆ write_vfunc()

virtual gssize Gio::OutputStream::write_vfunc ( const void buffer,
gsize  count,
const Glib::RefPtr< Cancellable > &  cancellable 
)
protectedvirtual
Exceptions
Glib::Error.

Friends And Related Symbol Documentation

◆ wrap()

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.