* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Authors: Ryan Lortie <desrt@desrt.ca>
* Alexander Larsson <alexl@redhat.com>
* To close a stream use g_io_stream_close() 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.
+ * substream as closed, so further I/O on it fails but common state in the
+ * #GIOStream may still be open. However, some streams may support
+ * "half-closed" states where one direction of the stream is actually shut down.
*
* Since: 2.22
*/
struct _GIOStreamPrivate {
guint closed : 1;
guint pending : 1;
- GAsyncReadyCallback outstanding_callback;
};
static gboolean g_io_stream_real_close (GIOStream *stream,
static void
g_io_stream_init (GIOStream *stream)
{
- stream->priv = g_io_stream_get_private (stream);
+ stream->priv = g_io_stream_get_instance_private (stream);
}
static void
* already set or @stream is closed, it will return %FALSE and set
* @error.
*
- * Return value: %TRUE if pending was previously unset and is now set.
+ * Returns: %TRUE if pending was previously unset and is now set.
*
* Since: 2.22
*/
* The default implementation of this method just calls close on the
* individual input/output streams.
*
- * Return value: %TRUE on success, %FALSE on failure
+ * Returns: %TRUE on success, %FALSE on failure
*
* Since: 2.22
*/
gpointer user_data)
{
GIOStream *stream = G_IO_STREAM (source_object);
+ GIOStreamClass *klass = G_IO_STREAM_GET_CLASS (stream);
+ GTask *task = user_data;
+ GError *error = NULL;
+ gboolean success;
stream->priv->closed = TRUE;
g_io_stream_clear_pending (stream);
- if (stream->priv->outstanding_callback)
- (*stream->priv->outstanding_callback) (source_object, res, user_data);
- g_object_unref (stream);
+
+ if (g_async_result_legacy_propagate_error (res, &error))
+ success = FALSE;
+ else
+ success = klass->close_finish (stream, res, &error);
+
+ if (error)
+ g_task_return_error (task, error);
+ else
+ g_task_return_boolean (task, success);
+
+ g_object_unref (task);
}
/**
{
GIOStreamClass *class;
GError *error = NULL;
+ GTask *task;
g_return_if_fail (G_IS_IO_STREAM (stream));
+ task = g_task_new (stream, cancellable, callback, user_data);
+
if (stream->priv->closed)
{
- GTask *task;
-
- task = g_task_new (stream, cancellable, callback, user_data);
- g_task_set_source_tag (task, g_io_stream_close_async);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
return;
if (!g_io_stream_set_pending (stream, &error))
{
- g_task_report_error (stream, callback, user_data,
- g_io_stream_close_async,
- error);
+ g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
class = G_IO_STREAM_GET_CLASS (stream);
- stream->priv->outstanding_callback = callback;
- g_object_ref (stream);
+
class->close_async (stream, io_priority, cancellable,
- async_ready_close_callback_wrapper, user_data);
+ async_ready_close_callback_wrapper, task);
}
/**
GAsyncResult *result,
GError **error)
{
- GIOStreamClass *class;
-
g_return_val_if_fail (G_IS_IO_STREAM (stream), FALSE);
- g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
-
- if (g_async_result_legacy_propagate_error (result, error))
- return FALSE;
- else if (g_async_result_is_tagged (result, g_io_stream_close_async))
- return g_task_propagate_boolean (G_TASK (result), error);
+ g_return_val_if_fail (g_task_is_valid (result, stream), FALSE);
- class = G_IO_STREAM_GET_CLASS (stream);
- return class->close_finish (stream, result, error);
+ return g_task_propagate_boolean (G_TASK (result), error);
}