#include <gio/gsimpleasyncresult.h>
#include <gio/gasyncresult.h>
-#include "gioalias.h"
-G_DEFINE_TYPE (GIOStream, g_io_stream, G_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE (GIOStream, g_io_stream, G_TYPE_OBJECT);
/**
- * SECTION:ginputstream
- * @short_description: Base class for implementing readwrite streams
+ * SECTION:giostream
+ * @short_description: Base class for implementing read/write streams
* @include: gio/gio.h
+ * @see_also: #GInputStream, #GOutputStream
*
* 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.
*
+ * Examples of #GIOStream objects are #GSocketConnection which represents
+ * a two-way network connection, and #GFileIOStream which represent a
+ * file handle opened in read-write mode.
+ *
* To do the actual reading and writing you need to get the substreams
* with g_io_stream_get_input_stream() and g_io_stream_get_output_stream().
*
* is actually shut down.
*
* Since: 2.22
- **/
+ */
enum
{
static void
g_io_stream_finalize (GObject *object)
{
- GIOStream *stream;
-
- stream = G_IO_STREAM (object);
-
G_OBJECT_CLASS (g_io_stream_parent_class)->finalize (object);
}
/**
* g_io_stream_is_closed:
- * @stream: a #GIOStream.
+ * @stream: a #GIOStream
*
* Checks if a stream is closed.
*
* Returns: %TRUE if the stream is closed.
*
* Since: 2.22
- **/
+ */
gboolean
g_io_stream_is_closed (GIOStream *stream)
{
/**
* g_io_stream_get_input_stream:
- * @stream: input #GIOStream.
+ * @stream: a #GIOStream
*
* Gets the input stream for this object. This is used
* for reading.
*
- * Returns: a #GInputStream, owned by the #GIOStream do not free.
+ * Returns: (transfer none): a #GInputStream, owned by the #GIOStream.
+ * Do not free.
*
* Since: 2.22
- **/
+ */
GInputStream *
-g_io_stream_get_input_stream (GIOStream *io_stream)
+g_io_stream_get_input_stream (GIOStream *stream)
{
GIOStreamClass *klass;
- klass = G_IO_STREAM_GET_CLASS (io_stream);
+ klass = G_IO_STREAM_GET_CLASS (stream);
g_assert (klass->get_input_stream != NULL);
- return klass->get_input_stream (io_stream);
+ return klass->get_input_stream (stream);
}
/**
* g_io_stream_get_output_stream:
- * @stream: input #GIOStream.
+ * @stream: a #GIOStream
*
* Gets the output stream for this object. This is used for
* writing.
*
- * Returns: a #GOutputStream, owned by the #GIOStream do not free.
+ * Returns: (transfer none): a #GOutputStream, owned by the #GIOStream.
+ * Do not free.
*
* Since: 2.22
- **/
+ */
GOutputStream *
-g_io_stream_get_output_stream (GIOStream *io_stream)
+g_io_stream_get_output_stream (GIOStream *stream)
{
GIOStreamClass *klass;
- klass = G_IO_STREAM_GET_CLASS (io_stream);
+ klass = G_IO_STREAM_GET_CLASS (stream);
g_assert (klass->get_output_stream != NULL);
- return klass->get_output_stream (io_stream);
+ return klass->get_output_stream (stream);
}
/**
* g_io_stream_has_pending:
- * @stream: a #GIOStream.
+ * @stream: a #GIOStream
*
* Checks if a stream has pending actions.
*
- * Returns: %TRUE if @stream has pending actions.
+ * Returns: %TRUE if @stream has pending actions.
*
* Since: 2.22
**/
/**
* g_io_stream_set_pending:
- * @stream: a #GIOStream.
- * @error: a #GError location to store the error occuring, or %NULL to
- * ignore.
+ * @stream: a #GIOStream
+ * @error: a #GError location to store the error occuring, or %NULL to
+ * ignore
*
* Sets @stream to have actions pending. If the pending flag is
* already set or @stream is closed, it will return %FALSE and set
* Return value: %TRUE if pending was previously unset and is now set.
*
* Since: 2.22
- **/
+ */
gboolean
-g_io_stream_set_pending (GIOStream *stream,
- GError **error)
+g_io_stream_set_pending (GIOStream *stream,
+ GError **error)
{
g_return_val_if_fail (G_IS_IO_STREAM (stream), FALSE);
/**
* g_io_stream_clear_pending:
- * @stream: output stream
+ * @stream: a #GIOStream
*
* Clears the pending flag on @stream.
*
* Since: 2.22
- **/
+ */
void
g_io_stream_clear_pending (GIOStream *stream)
{
}
static gboolean
-g_io_stream_real_close (GIOStream *stream,
- GCancellable *cancellable,
- GError **error)
+g_io_stream_real_close (GIOStream *stream,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean res;
/**
* g_io_stream_close:
- * @stream: A #GIOStream.
- * @cancellable: optional #GCancellable object, %NULL to ignore.
+ * @stream: a #GIOStream
+ * @cancellable: optional #GCancellable object, %NULL to ignore
* @error: location to store the error occuring, or %NULL to ignore
*
* Closes the stream, releasing resources related to it. This will also
* closes the individual input and output streams, if they are not already
* closed.
*
- * Once the stream is closed, all other operations will return %G_IO_ERROR_CLOSED.
- * Closing a stream multiple times will not return an error.
+ * Once the stream is closed, all other operations will return
+ * %G_IO_ERROR_CLOSED. Closing a stream multiple times will not
+ * return an error.
*
- * Closing a stream will automatically flush any outstanding buffers in the
- * stream.
+ * 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.
+ * Some streams might keep the backing store of the stream (e.g. a file
+ * descriptor) open after the stream is closed. See the documentation for
+ * the individual stream for details.
*
- * On failure the first error that happened will be reported, but the close
- * operation will finish as much as possible. A stream that failed to
- * close will still return %G_IO_ERROR_CLOSED 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.
+ * On failure the first error that happened will be reported, but the
+ * close operation will finish as much as possible. A stream that failed
+ * to close will still return %G_IO_ERROR_CLOSED 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.
*
* If @cancellable is not NULL, then the operation can be cancelled by
* triggering the cancellable object from another thread. If the operation
* Return value: %TRUE on success, %FALSE on failure
*
* Since: 2.22
- **/
+ */
gboolean
-g_io_stream_close (GIOStream *stream,
+g_io_stream_close (GIOStream *stream,
GCancellable *cancellable,
GError **error)
{
/**
* g_io_stream_close_async:
- * @stream: A #GIOStream.
- * @io_priority: the io priority of the request.
+ * @stream: a #GIOStream
+ * @io_priority: the io priority of the request
* @callback: callback to call when the request is satisfied
* @user_data: the data to pass to callback function
* @cancellable: optional cancellable object
*
* For behaviour details see g_io_stream_close().
*
- * The asyncronous methods have a default fallback that uses threads
+ * 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.
*
* Since: 2.22
- **/
+ */
void
g_io_stream_close_async (GIOStream *stream,
int io_priority,
/**
* g_io_stream_close_finish:
- * @stream: a #GIOStream.
- * @result: a #GAsyncResult.
+ * @stream: a #GIOStream
+ * @result: a #GAsyncResult
* @error: a #GError location to store the error occuring, or %NULL to
- * ignore.
+ * ignore
*
* Closes a stream.
*
* Returns: %TRUE if stream was successfully closed, %FALSE otherwise.
*
* Since: 2.22
- **/
+ */
gboolean
-g_io_stream_close_finish (GIOStream *stream,
- GAsyncResult *result,
- GError **error)
+g_io_stream_close_finish (GIOStream *stream,
+ GAsyncResult *result,
+ GError **error)
{
GSimpleAsyncResult *simple;
GIOStreamClass *class;
GError *error = NULL;
gboolean result;
- /* Auto handling of cancelation disabled, and ignore
- cancellation, since we want to close things anyway, although
- possibly in a quick-n-dirty way. At least we never want to leak
- open handles */
-
+ /* Auto handling of cancelation disabled, and ignore cancellation,
+ * since we want to close things anyway, although possibly in a
+ * quick-n-dirty way. At least we never want to leak open handles
+ */
class = G_IO_STREAM_GET_CLASS (object);
- result = class->close_fn (G_IO_STREAM (object), cancellable, &error);
- if (!result)
+ if (class->close_fn)
{
- g_simple_async_result_set_from_error (res, error);
- g_error_free (error);
+ result = class->close_fn (G_IO_STREAM (object), cancellable, &error);
+ if (!result)
+ {
+ g_simple_async_result_set_from_error (res, error);
+ g_error_free (error);
+ }
}
}
static void
-g_io_stream_real_close_async (GIOStream *stream,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+g_io_stream_real_close_async (GIOStream *stream,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GSimpleAsyncResult *res;
}
static gboolean
-g_io_stream_real_close_finish (GIOStream *stream,
+g_io_stream_real_close_finish (GIOStream *stream,
GAsyncResult *result,
GError **error)
{
g_io_stream_real_close_async);
return TRUE;
}
-
-#define __G_IO_STREAM_C__
-#include "gioaliasdef.c"