<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="GIOStream">
<refmeta>
<refentrytitle role="top_of_page" id="GIOStream.top_of_page">GIOStream</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GIO Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>GIOStream</refname>
<refpurpose>Base class for implementing read/write streams</refpurpose>
</refnamediv>

<refsynopsisdiv id="GIOStream.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>

#include &lt;gio/gio.h&gt;

                    <link linkend="GIOStream-struct">GIOStream</link>;
<link linkend="GInputStream">GInputStream</link> *      <link linkend="g-io-stream-get-input-stream">g_io_stream_get_input_stream</link>        (<link linkend="GIOStream">GIOStream</link> *stream);
<link linkend="GOutputStream">GOutputStream</link> *     <link linkend="g-io-stream-get-output-stream">g_io_stream_get_output_stream</link>       (<link linkend="GIOStream">GIOStream</link> *stream);
<link linkend="gboolean">gboolean</link>            <link linkend="g-io-stream-close">g_io_stream_close</link>                   (<link linkend="GIOStream">GIOStream</link> *stream,
                                                         <link linkend="GCancellable">GCancellable</link> *cancellable,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="void">void</link>                <link linkend="g-io-stream-close-async">g_io_stream_close_async</link>             (<link linkend="GIOStream">GIOStream</link> *stream,
                                                         <link linkend="int">int</link> io_priority,
                                                         <link linkend="GCancellable">GCancellable</link> *cancellable,
                                                         <link linkend="GAsyncReadyCallback">GAsyncReadyCallback</link> callback,
                                                         <link linkend="gpointer">gpointer</link> user_data);
<link linkend="gboolean">gboolean</link>            <link linkend="g-io-stream-close-finish">g_io_stream_close_finish</link>            (<link linkend="GIOStream">GIOStream</link> *stream,
                                                         <link linkend="GAsyncResult">GAsyncResult</link> *result,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gboolean">gboolean</link>            <link linkend="g-io-stream-is-closed">g_io_stream_is_closed</link>               (<link linkend="GIOStream">GIOStream</link> *stream);
<link linkend="gboolean">gboolean</link>            <link linkend="g-io-stream-has-pending">g_io_stream_has_pending</link>             (<link linkend="GIOStream">GIOStream</link> *stream);
<link linkend="gboolean">gboolean</link>            <link linkend="g-io-stream-set-pending">g_io_stream_set_pending</link>             (<link linkend="GIOStream">GIOStream</link> *stream,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="void">void</link>                <link linkend="g-io-stream-clear-pending">g_io_stream_clear_pending</link>           (<link linkend="GIOStream">GIOStream</link> *stream);
</synopsis>
</refsynopsisdiv>

<refsect1 id="GIOStream.object-hierarchy" role="object_hierarchy">
<title role="object_hierarchy.title">Object Hierarchy</title>
<synopsis>
  <link linkend="GObject">GObject</link>
   +----GIOStream
         +----<link linkend="GFileIOStream">GFileIOStream</link>
         +----<link linkend="GSocketConnection">GSocketConnection</link>
</synopsis>
</refsect1>





<refsect1 id="GIOStream.properties" role="properties">
<title role="properties.title">Properties</title>
<synopsis>
  &quot;<link linkend="GIOStream--closed">closed</link>&quot;                   <link linkend="gboolean">gboolean</link>              : Read / Write
  &quot;<link linkend="GIOStream--input-stream">input-stream</link>&quot;             <link linkend="GInputStream">GInputStream</link>*         : Read
  &quot;<link linkend="GIOStream--output-stream">output-stream</link>&quot;            <link linkend="GOutputStream">GOutputStream</link>*        : Read
</synopsis>
</refsect1>



<refsect1 id="GIOStream.description" role="desc">
<title role="desc.title">Description</title>
<para>
GIOStream represents an object that has both read and write streams.
Generally the two streams acts as separate input and output streams,
but they share some common resources and state. For instance, for
seekable streams they may use the same position in both streams.
</para>
<para>
Examples of <link linkend="GIOStream"><type>GIOStream</type></link> objects are <link linkend="GSocketConnection"><type>GSocketConnection</type></link> which represents
a two-way network connection, and <link linkend="GFileIOStream"><type>GFileIOStream</type></link> which represent a
file handle opened in read-write mode.
</para>
<para>
To do the actual reading and writing you need to get the substreams
with <link linkend="g-io-stream-get-input-stream"><function>g_io_stream_get_input_stream()</function></link> and <link linkend="g-io-stream-get-output-stream"><function>g_io_stream_get_output_stream()</function></link>.
</para>
<para>
The <link linkend="GIOStream"><type>GIOStream</type></link> object owns the input and the output streams, not the other
way around, so keeping the substreams alive will not keep the <link linkend="GIOStream"><type>GIOStream</type></link>
object alive. If the <link linkend="GIOStream"><type>GIOStream</type></link> object is freed it will be closed, thus
closing the substream, so even if the substreams stay alive they will
always just return a <link linkend="G-IO-ERROR-CLOSED--CAPS"><literal>G_IO_ERROR_CLOSED</literal></link> for all operations.
</para>
<para>
To close a stream use <link linkend="g-io-stream-close"><function>g_io_stream_close()</function></link> which will close the common
stream object and also the individual substreams. You can also close
the substreams themselves. In most cases this only marks the
substream as closed, so further I/O on it fails. However, some streams
may support "half-closed" states where one direction of the stream
is actually shut down.</para>
<para>
</para>
</refsect1>

<refsect1 id="GIOStream.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="GIOStream-struct" role="struct">
<title>GIOStream</title>
<indexterm zone="GIOStream-struct"><primary sortas="IOStream">GIOStream</primary></indexterm><programlisting>typedef struct _GIOStream GIOStream;</programlisting>
<para>
Base class for read-write streams.</para>
<para>
</para></refsect2>
<refsect2 id="g-io-stream-get-input-stream" role="function" condition="since:2.22">
<title>g_io_stream_get_input_stream ()</title>
<indexterm zone="g-io-stream-get-input-stream" role="2.22"><primary sortas="io_stream_get_input_stream">g_io_stream_get_input_stream</primary></indexterm><programlisting><link linkend="GInputStream">GInputStream</link> *      g_io_stream_get_input_stream        (<link linkend="GIOStream">GIOStream</link> *stream);</programlisting>
<para>
Gets the input stream for this object. This is used
for reading.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a <link linkend="GInputStream"><type>GInputStream</type></link>, owned by the <link linkend="GIOStream"><type>GIOStream</type></link>. Do not free.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>
<refsect2 id="g-io-stream-get-output-stream" role="function" condition="since:2.22">
<title>g_io_stream_get_output_stream ()</title>
<indexterm zone="g-io-stream-get-output-stream" role="2.22"><primary sortas="io_stream_get_output_stream">g_io_stream_get_output_stream</primary></indexterm><programlisting><link linkend="GOutputStream">GOutputStream</link> *     g_io_stream_get_output_stream       (<link linkend="GIOStream">GIOStream</link> *stream);</programlisting>
<para>
Gets the output stream for this object. This is used for
writing.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a <link linkend="GOutputStream"><type>GOutputStream</type></link>, owned by the <link linkend="GIOStream"><type>GIOStream</type></link>. Do not free.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>
<refsect2 id="g-io-stream-close" role="function" condition="since:2.22">
<title>g_io_stream_close ()</title>
<indexterm zone="g-io-stream-close" role="2.22"><primary sortas="io_stream_close">g_io_stream_close</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_io_stream_close                   (<link linkend="GIOStream">GIOStream</link> *stream,
                                                         <link linkend="GCancellable">GCancellable</link> *cancellable,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Closes the stream, releasing resources related to it. This will also
closes the individual input and output streams, if they are not already
closed.
</para>
<para>
Once the stream is closed, all other operations will return
<link linkend="G-IO-ERROR-CLOSED--CAPS"><literal>G_IO_ERROR_CLOSED</literal></link>. Closing a stream multiple times will not
return an error.
</para>
<para>
Closing a stream will automatically flush any outstanding buffers
in the stream.
</para>
<para>
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.
</para>
<para>
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.
</para>
<para>
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 <link linkend="G-IO-ERROR-CLOSED--CAPS"><literal>G_IO_ERROR_CLOSED</literal></link> 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.
</para>
<para>
If <parameter>cancellable</parameter> is not NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error <link linkend="G-IO-ERROR-CANCELLED--CAPS"><literal>G_IO_ERROR_CANCELLED</literal></link> 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.
</para>
<para>
The default implementation of this method just calls close on the
individual input/output streams.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>cancellable</parameter>&#160;:</term>
<listitem><simpara> optional <link linkend="GCancellable"><type>GCancellable</type></link> object, <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> on failure

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>
<refsect2 id="g-io-stream-close-async" role="function" condition="since:2.22">
<title>g_io_stream_close_async ()</title>
<indexterm zone="g-io-stream-close-async" role="2.22"><primary sortas="io_stream_close_async">g_io_stream_close_async</primary></indexterm><programlisting><link linkend="void">void</link>                g_io_stream_close_async             (<link linkend="GIOStream">GIOStream</link> *stream,
                                                         <link linkend="int">int</link> io_priority,
                                                         <link linkend="GCancellable">GCancellable</link> *cancellable,
                                                         <link linkend="GAsyncReadyCallback">GAsyncReadyCallback</link> callback,
                                                         <link linkend="gpointer">gpointer</link> user_data);</programlisting>
<para>
Requests an asynchronous close of the stream, releasing resources
related to it. When the operation is finished <parameter>callback</parameter> will be
called. You can then call <link linkend="g-io-stream-close-finish"><function>g_io_stream_close_finish()</function></link> to get
the result of the operation.
</para>
<para>
For behaviour details see <link linkend="g-io-stream-close"><function>g_io_stream_close()</function></link>.
</para>
<para>
The asynchronous 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.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>io_priority</parameter>&#160;:</term>
<listitem><simpara> the io priority of the request
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>cancellable</parameter>&#160;:</term>
<listitem><simpara> optional cancellable object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>callback</parameter>&#160;:</term>
<listitem><simpara> callback to call when the request is satisfied
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>user_data</parameter>&#160;:</term>
<listitem><simpara> the data to pass to callback function
</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>
<refsect2 id="g-io-stream-close-finish" role="function" condition="since:2.22">
<title>g_io_stream_close_finish ()</title>
<indexterm zone="g-io-stream-close-finish" role="2.22"><primary sortas="io_stream_close_finish">g_io_stream_close_finish</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_io_stream_close_finish            (<link linkend="GIOStream">GIOStream</link> *stream,
                                                         <link linkend="GAsyncResult">GAsyncResult</link> *result,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Closes a stream.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>result</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GAsyncResult"><type>GAsyncResult</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GError"><type>GError</type></link> location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to
   ignore
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if stream was successfully closed, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> otherwise.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>
<refsect2 id="g-io-stream-is-closed" role="function" condition="since:2.22">
<title>g_io_stream_is_closed ()</title>
<indexterm zone="g-io-stream-is-closed" role="2.22"><primary sortas="io_stream_is_closed">g_io_stream_is_closed</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_io_stream_is_closed               (<link linkend="GIOStream">GIOStream</link> *stream);</programlisting>
<para>
Checks if a stream is closed.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if the stream is closed.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>
<refsect2 id="g-io-stream-has-pending" role="function" condition="since:2.22">
<title>g_io_stream_has_pending ()</title>
<indexterm zone="g-io-stream-has-pending" role="2.22"><primary sortas="io_stream_has_pending">g_io_stream_has_pending</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_io_stream_has_pending             (<link linkend="GIOStream">GIOStream</link> *stream);</programlisting>
<para>
Checks if a stream has pending actions.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if <parameter>stream</parameter> has pending actions.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>
<refsect2 id="g-io-stream-set-pending" role="function" condition="since:2.22">
<title>g_io_stream_set_pending ()</title>
<indexterm zone="g-io-stream-set-pending" role="2.22"><primary sortas="io_stream_set_pending">g_io_stream_set_pending</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_io_stream_set_pending             (<link linkend="GIOStream">GIOStream</link> *stream,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Sets <parameter>stream</parameter> to have actions pending. If the pending flag is
already set or <parameter>stream</parameter> is closed, it will return <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> and set
<parameter>error</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GError"><type>GError</type></link> location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to
    ignore
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if pending was previously unset and is now set.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>
<refsect2 id="g-io-stream-clear-pending" role="function" condition="since:2.22">
<title>g_io_stream_clear_pending ()</title>
<indexterm zone="g-io-stream-clear-pending" role="2.22"><primary sortas="io_stream_clear_pending">g_io_stream_clear_pending</primary></indexterm><programlisting><link linkend="void">void</link>                g_io_stream_clear_pending           (<link linkend="GIOStream">GIOStream</link> *stream);</programlisting>
<para>
Clears the pending flag on <parameter>stream</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>stream</parameter>&#160;:</term>
<listitem><simpara> a <link linkend="GIOStream"><type>GIOStream</type></link>
</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.22</para></refsect2>

</refsect1>
<refsect1 id="GIOStream.property-details" role="property_details">
<title role="property_details.title">Property Details</title>
<refsect2 id="GIOStream--closed" role="property"><title>The <literal>&quot;closed&quot;</literal> property</title>
<indexterm zone="GIOStream--closed"><primary sortas="IOStream:closed">GIOStream:closed</primary></indexterm><programlisting>  &quot;closed&quot;                   <link linkend="gboolean">gboolean</link>              : Read / Write</programlisting>
<para>Is the stream closed.</para><para>Default value: FALSE</para>
</refsect2>
<refsect2 id="GIOStream--input-stream" role="property"><title>The <literal>&quot;input-stream&quot;</literal> property</title>
<indexterm zone="GIOStream--input-stream"><primary sortas="IOStream:input-stream">GIOStream:input-stream</primary></indexterm><programlisting>  &quot;input-stream&quot;             <link linkend="GInputStream">GInputStream</link>*         : Read</programlisting>
<para>The GInputStream to read from.</para></refsect2>
<refsect2 id="GIOStream--output-stream" role="property"><title>The <literal>&quot;output-stream&quot;</literal> property</title>
<indexterm zone="GIOStream--output-stream"><primary sortas="IOStream:output-stream">GIOStream:output-stream</primary></indexterm><programlisting>  &quot;output-stream&quot;            <link linkend="GOutputStream">GOutputStream</link>*        : Read</programlisting>
<para>The GOutputStream to write to.</para></refsect2>
</refsect1>



<refsect1 id="GIOStream.see-also">
<title>See Also</title>
#GInputStream, <link linkend="GOutputStream"><type>GOutputStream</type></link>
</refsect1>

</refentry>
