Blame gio/gunixoutputstream.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 * 
Packit ae235b
 * Copyright (C) 2006-2007 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: Alexander Larsson <alexl@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include <sys/types.h>
Packit ae235b
#include <sys/stat.h>
Packit ae235b
#include <unistd.h>
Packit ae235b
#include <errno.h>
Packit ae235b
#include <stdio.h>
Packit ae235b
#include <fcntl.h>
Packit ae235b
Packit ae235b
#include <glib.h>
Packit ae235b
#include <glib/gstdio.h>
Packit ae235b
#include <glib/glib-unix.h>
Packit ae235b
#include "gioerror.h"
Packit ae235b
#include "gunixoutputstream.h"
Packit ae235b
#include "gcancellable.h"
Packit ae235b
#include "gasynchelper.h"
Packit ae235b
#include "gfiledescriptorbased.h"
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gunixoutputstream
Packit ae235b
 * @short_description: Streaming output operations for UNIX file descriptors
Packit ae235b
 * @include: gio/gunixoutputstream.h
Packit ae235b
 * @see_also: #GOutputStream
Packit ae235b
 *
Packit ae235b
 * #GUnixOutputStream implements #GOutputStream for writing to a UNIX
Packit ae235b
 * file descriptor, including asynchronous operations. (If the file
Packit ae235b
 * descriptor refers to a socket or pipe, this will use poll() to do
Packit ae235b
 * asynchronous I/O. If it refers to a regular file, it will fall back
Packit ae235b
 * to doing asynchronous I/O in another thread.)
Packit ae235b
 *
Packit ae235b
 * Note that `<gio/gunixoutputstream.h>` belongs to the UNIX-specific GIO
Packit ae235b
 * interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config file
Packit ae235b
 * when using it.
Packit ae235b
 */
Packit ae235b
Packit ae235b
enum {
Packit ae235b
  PROP_0,
Packit ae235b
  PROP_FD,
Packit ae235b
  PROP_CLOSE_FD
Packit ae235b
};
Packit ae235b
Packit ae235b
struct _GUnixOutputStreamPrivate {
Packit ae235b
  int fd;
Packit ae235b
  guint close_fd : 1;
Packit ae235b
  guint is_pipe_or_socket : 1;
Packit ae235b
};
Packit ae235b
Packit ae235b
static void g_unix_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface);
Packit ae235b
static void g_unix_output_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface);
Packit ae235b
Packit ae235b
G_DEFINE_TYPE_WITH_CODE (GUnixOutputStream, g_unix_output_stream, G_TYPE_OUTPUT_STREAM,
Packit ae235b
                         G_ADD_PRIVATE (GUnixOutputStream)
Packit ae235b
			 G_IMPLEMENT_INTERFACE (G_TYPE_POLLABLE_OUTPUT_STREAM,
Packit ae235b
						g_unix_output_stream_pollable_iface_init)
Packit ae235b
			 G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED,
Packit ae235b
						g_unix_output_stream_file_descriptor_based_iface_init)
Packit ae235b
			 )
Packit ae235b
Packit ae235b
static void     g_unix_output_stream_set_property (GObject              *object,
Packit ae235b
						   guint                 prop_id,
Packit ae235b
						   const GValue         *value,
Packit ae235b
						   GParamSpec           *pspec);
Packit ae235b
static void     g_unix_output_stream_get_property (GObject              *object,
Packit ae235b
						   guint                 prop_id,
Packit ae235b
						   GValue               *value,
Packit ae235b
						   GParamSpec           *pspec);
Packit ae235b
static gssize   g_unix_output_stream_write        (GOutputStream        *stream,
Packit ae235b
						   const void           *buffer,
Packit ae235b
						   gsize                 count,
Packit ae235b
						   GCancellable         *cancellable,
Packit ae235b
						   GError              **error);
Packit ae235b
static gboolean g_unix_output_stream_close        (GOutputStream        *stream,
Packit ae235b
						   GCancellable         *cancellable,
Packit ae235b
						   GError              **error);
Packit ae235b
static void     g_unix_output_stream_close_async  (GOutputStream        *stream,
Packit ae235b
						   int                   io_priority,
Packit ae235b
						   GCancellable         *cancellable,
Packit ae235b
						   GAsyncReadyCallback   callback,
Packit ae235b
						   gpointer              data);
Packit ae235b
static gboolean g_unix_output_stream_close_finish (GOutputStream        *stream,
Packit ae235b
						   GAsyncResult         *result,
Packit ae235b
						   GError              **error);
Packit ae235b
Packit ae235b
static gboolean g_unix_output_stream_pollable_can_poll      (GPollableOutputStream *stream);
Packit ae235b
static gboolean g_unix_output_stream_pollable_is_writable   (GPollableOutputStream *stream);
Packit ae235b
static GSource *g_unix_output_stream_pollable_create_source (GPollableOutputStream *stream,
Packit ae235b
							     GCancellable         *cancellable);
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_unix_output_stream_class_init (GUnixOutputStreamClass *klass)
Packit ae235b
{
Packit ae235b
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit ae235b
  GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass);
Packit ae235b
Packit ae235b
  gobject_class->get_property = g_unix_output_stream_get_property;
Packit ae235b
  gobject_class->set_property = g_unix_output_stream_set_property;
Packit ae235b
Packit ae235b
  stream_class->write_fn = g_unix_output_stream_write;
Packit ae235b
  stream_class->close_fn = g_unix_output_stream_close;
Packit ae235b
  stream_class->close_async = g_unix_output_stream_close_async;
Packit ae235b
  stream_class->close_finish = g_unix_output_stream_close_finish;
Packit ae235b
Packit ae235b
   /**
Packit ae235b
   * GUnixOutputStream:fd:
Packit ae235b
   *
Packit ae235b
   * The file descriptor that the stream writes to.
Packit ae235b
   *
Packit ae235b
   * Since: 2.20
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
				   PROP_FD,
Packit ae235b
				   g_param_spec_int ("fd",
Packit ae235b
						     P_("File descriptor"),
Packit ae235b
						     P_("The file descriptor to write to"),
Packit ae235b
						     G_MININT, G_MAXINT, -1,
Packit ae235b
						     G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GUnixOutputStream:close-fd:
Packit ae235b
   *
Packit ae235b
   * Whether to close the file descriptor when the stream is closed.
Packit ae235b
   *
Packit ae235b
   * Since: 2.20
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
				   PROP_CLOSE_FD,
Packit ae235b
				   g_param_spec_boolean ("close-fd",
Packit ae235b
							 P_("Close file descriptor"),
Packit ae235b
							 P_("Whether to close the file descriptor when the stream is closed"),
Packit ae235b
							 TRUE,
Packit ae235b
							 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_unix_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface)
Packit ae235b
{
Packit ae235b
  iface->can_poll = g_unix_output_stream_pollable_can_poll;
Packit ae235b
  iface->is_writable = g_unix_output_stream_pollable_is_writable;
Packit ae235b
  iface->create_source = g_unix_output_stream_pollable_create_source;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_unix_output_stream_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface)
Packit ae235b
{
Packit ae235b
  iface->get_fd = (int (*) (GFileDescriptorBased *))g_unix_output_stream_get_fd;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_unix_output_stream_set_property (GObject         *object,
Packit ae235b
				   guint            prop_id,
Packit ae235b
				   const GValue    *value,
Packit ae235b
				   GParamSpec      *pspec)
Packit ae235b
{
Packit ae235b
  GUnixOutputStream *unix_stream;
Packit ae235b
Packit ae235b
  unix_stream = G_UNIX_OUTPUT_STREAM (object);
Packit ae235b
Packit ae235b
  switch (prop_id)
Packit ae235b
    {
Packit ae235b
    case PROP_FD:
Packit ae235b
      unix_stream->priv->fd = g_value_get_int (value);
Packit ae235b
      if (lseek (unix_stream->priv->fd, 0, SEEK_CUR) == -1 && errno == ESPIPE)
Packit ae235b
	unix_stream->priv->is_pipe_or_socket = TRUE;
Packit ae235b
      else
Packit ae235b
	unix_stream->priv->is_pipe_or_socket = FALSE;
Packit ae235b
      break;
Packit ae235b
    case PROP_CLOSE_FD:
Packit ae235b
      unix_stream->priv->close_fd = g_value_get_boolean (value);
Packit ae235b
      break;
Packit ae235b
    default:
Packit ae235b
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_unix_output_stream_get_property (GObject    *object,
Packit ae235b
				   guint       prop_id,
Packit ae235b
				   GValue     *value,
Packit ae235b
				   GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  GUnixOutputStream *unix_stream;
Packit ae235b
Packit ae235b
  unix_stream = G_UNIX_OUTPUT_STREAM (object);
Packit ae235b
Packit ae235b
  switch (prop_id)
Packit ae235b
    {
Packit ae235b
    case PROP_FD:
Packit ae235b
      g_value_set_int (value, unix_stream->priv->fd);
Packit ae235b
      break;
Packit ae235b
    case PROP_CLOSE_FD:
Packit ae235b
      g_value_set_boolean (value, unix_stream->priv->close_fd);
Packit ae235b
      break;
Packit ae235b
    default:
Packit ae235b
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_unix_output_stream_init (GUnixOutputStream *unix_stream)
Packit ae235b
{
Packit ae235b
  unix_stream->priv = g_unix_output_stream_get_instance_private (unix_stream);
Packit ae235b
  unix_stream->priv->fd = -1;
Packit ae235b
  unix_stream->priv->close_fd = TRUE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unix_output_stream_new:
Packit ae235b
 * @fd: a UNIX file descriptor
Packit ae235b
 * @close_fd: %TRUE to close the file descriptor when done
Packit ae235b
 * 
Packit ae235b
 * Creates a new #GUnixOutputStream for the given @fd. 
Packit ae235b
 * 
Packit ae235b
 * If @close_fd, is %TRUE, the file descriptor will be closed when 
Packit ae235b
 * the output stream is destroyed.
Packit ae235b
 * 
Packit ae235b
 * Returns: a new #GOutputStream
Packit ae235b
 **/
Packit ae235b
GOutputStream *
Packit ae235b
g_unix_output_stream_new (gint     fd,
Packit ae235b
			  gboolean close_fd)
Packit ae235b
{
Packit ae235b
  GUnixOutputStream *stream;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (fd != -1, NULL);
Packit ae235b
Packit ae235b
  stream = g_object_new (G_TYPE_UNIX_OUTPUT_STREAM,
Packit ae235b
			 "fd", fd,
Packit ae235b
			 "close-fd", close_fd,
Packit ae235b
			 NULL);
Packit ae235b
  
Packit ae235b
  return G_OUTPUT_STREAM (stream);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unix_output_stream_set_close_fd:
Packit ae235b
 * @stream: a #GUnixOutputStream
Packit ae235b
 * @close_fd: %TRUE to close the file descriptor when done
Packit ae235b
 *
Packit ae235b
 * Sets whether the file descriptor of @stream shall be closed
Packit ae235b
 * when the stream is closed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_unix_output_stream_set_close_fd (GUnixOutputStream *stream,
Packit ae235b
                                   gboolean           close_fd)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_UNIX_OUTPUT_STREAM (stream));
Packit ae235b
Packit ae235b
  close_fd = close_fd != FALSE;
Packit ae235b
  if (stream->priv->close_fd != close_fd)
Packit ae235b
    {
Packit ae235b
      stream->priv->close_fd = close_fd;
Packit ae235b
      g_object_notify (G_OBJECT (stream), "close-fd");
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unix_output_stream_get_close_fd:
Packit ae235b
 * @stream: a #GUnixOutputStream
Packit ae235b
 *
Packit ae235b
 * Returns whether the file descriptor of @stream will be
Packit ae235b
 * closed when the stream is closed.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the file descriptor is closed when done
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_unix_output_stream_get_close_fd (GUnixOutputStream *stream)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_UNIX_OUTPUT_STREAM (stream), FALSE);
Packit ae235b
Packit ae235b
  return stream->priv->close_fd;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unix_output_stream_get_fd:
Packit ae235b
 * @stream: a #GUnixOutputStream
Packit ae235b
 *
Packit ae235b
 * Return the UNIX file descriptor that the stream writes to.
Packit ae235b
 *
Packit ae235b
 * Returns: The file descriptor of @stream
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 */
Packit ae235b
gint
Packit ae235b
g_unix_output_stream_get_fd (GUnixOutputStream *stream)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_UNIX_OUTPUT_STREAM (stream), -1);
Packit ae235b
Packit ae235b
  return stream->priv->fd;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gssize
Packit ae235b
g_unix_output_stream_write (GOutputStream  *stream,
Packit ae235b
			    const void     *buffer,
Packit ae235b
			    gsize           count,
Packit ae235b
			    GCancellable   *cancellable,
Packit ae235b
			    GError        **error)
Packit ae235b
{
Packit ae235b
  GUnixOutputStream *unix_stream;
Packit ae235b
  gssize res = -1;
Packit ae235b
  GPollFD poll_fds[2];
Packit ae235b
  int nfds;
Packit ae235b
  int poll_ret;
Packit ae235b
Packit ae235b
  unix_stream = G_UNIX_OUTPUT_STREAM (stream);
Packit ae235b
Packit ae235b
  poll_fds[0].fd = unix_stream->priv->fd;
Packit ae235b
  poll_fds[0].events = G_IO_OUT;
Packit ae235b
Packit ae235b
  if (unix_stream->priv->is_pipe_or_socket &&
Packit ae235b
      g_cancellable_make_pollfd (cancellable, &poll_fds[1]))
Packit ae235b
    nfds = 2;
Packit ae235b
  else
Packit ae235b
    nfds = 1;
Packit ae235b
Packit ae235b
  while (1)
Packit ae235b
    {
Packit ae235b
      int errsv;
Packit ae235b
Packit ae235b
      poll_fds[0].revents = poll_fds[1].revents = 0;
Packit ae235b
      do
Packit ae235b
        {
Packit ae235b
          poll_ret = g_poll (poll_fds, nfds, -1);
Packit ae235b
          errsv = errno;
Packit ae235b
        }
Packit ae235b
      while (poll_ret == -1 && errsv == EINTR);
Packit ae235b
Packit ae235b
      if (poll_ret == -1)
Packit ae235b
	{
Packit ae235b
	  g_set_error (error, G_IO_ERROR,
Packit ae235b
		       g_io_error_from_errno (errsv),
Packit ae235b
		       _("Error writing to file descriptor: %s"),
Packit ae235b
		       g_strerror (errsv));
Packit ae235b
	  break;
Packit ae235b
	}
Packit ae235b
Packit ae235b
      if (g_cancellable_set_error_if_cancelled (cancellable, error))
Packit ae235b
	break;
Packit ae235b
Packit ae235b
      if (!poll_fds[0].revents)
Packit ae235b
	continue;
Packit ae235b
Packit ae235b
      res = write (unix_stream->priv->fd, buffer, count);
Packit ae235b
      errsv = errno;
Packit ae235b
      if (res == -1)
Packit ae235b
	{
Packit ae235b
	  if (errsv == EINTR || errsv == EAGAIN)
Packit ae235b
	    continue;
Packit ae235b
Packit ae235b
	  g_set_error (error, G_IO_ERROR,
Packit ae235b
		       g_io_error_from_errno (errsv),
Packit ae235b
		       _("Error writing to file descriptor: %s"),
Packit ae235b
		       g_strerror (errsv));
Packit ae235b
	}
Packit ae235b
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (nfds == 2)
Packit ae235b
    g_cancellable_release_fd (cancellable);
Packit ae235b
  return res;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
g_unix_output_stream_close (GOutputStream  *stream,
Packit ae235b
			    GCancellable   *cancellable,
Packit ae235b
			    GError        **error)
Packit ae235b
{
Packit ae235b
  GUnixOutputStream *unix_stream;
Packit ae235b
  int res;
Packit ae235b
Packit ae235b
  unix_stream = G_UNIX_OUTPUT_STREAM (stream);
Packit ae235b
Packit ae235b
  if (!unix_stream->priv->close_fd)
Packit ae235b
    return TRUE;
Packit ae235b
  
Packit ae235b
  /* This might block during the close. Doesn't seem to be a way to avoid it though. */
Packit ae235b
  res = close (unix_stream->priv->fd);
Packit ae235b
  if (res == -1)
Packit ae235b
    {
Packit ae235b
      int errsv = errno;
Packit ae235b
Packit ae235b
      g_set_error (error, G_IO_ERROR,
Packit ae235b
		   g_io_error_from_errno (errsv),
Packit ae235b
		   _("Error closing file descriptor: %s"),
Packit ae235b
		   g_strerror (errsv));
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return res != -1;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_unix_output_stream_close_async (GOutputStream       *stream,
Packit ae235b
				  int                  io_priority,
Packit ae235b
				  GCancellable        *cancellable,
Packit ae235b
				  GAsyncReadyCallback  callback,
Packit ae235b
				  gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GTask *task;
Packit ae235b
  GError *error = NULL;
Packit ae235b
Packit ae235b
  task = g_task_new (stream, cancellable, callback, user_data);
Packit ae235b
  g_task_set_source_tag (task, g_unix_output_stream_close_async);
Packit ae235b
  g_task_set_priority (task, io_priority);
Packit ae235b
Packit ae235b
  if (g_unix_output_stream_close (stream, cancellable, &error))
Packit ae235b
    g_task_return_boolean (task, TRUE);
Packit ae235b
  else
Packit ae235b
    g_task_return_error (task, error);
Packit ae235b
  g_object_unref (task);
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
g_unix_output_stream_close_finish (GOutputStream  *stream,
Packit ae235b
				   GAsyncResult   *result,
Packit ae235b
				   GError        **error)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (g_task_is_valid (result, stream), FALSE);
Packit ae235b
Packit ae235b
  return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
g_unix_output_stream_pollable_can_poll (GPollableOutputStream *stream)
Packit ae235b
{
Packit ae235b
  return G_UNIX_OUTPUT_STREAM (stream)->priv->is_pipe_or_socket;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
g_unix_output_stream_pollable_is_writable (GPollableOutputStream *stream)
Packit ae235b
{
Packit ae235b
  GUnixOutputStream *unix_stream = G_UNIX_OUTPUT_STREAM (stream);
Packit ae235b
  GPollFD poll_fd;
Packit ae235b
  gint result;
Packit ae235b
Packit ae235b
  poll_fd.fd = unix_stream->priv->fd;
Packit ae235b
  poll_fd.events = G_IO_OUT;
Packit ae235b
  poll_fd.revents = 0;
Packit ae235b
Packit ae235b
  do
Packit ae235b
    result = g_poll (&poll_fd, 1, 0);
Packit ae235b
  while (result == -1 && errno == EINTR);
Packit ae235b
Packit ae235b
  return poll_fd.revents != 0;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GSource *
Packit ae235b
g_unix_output_stream_pollable_create_source (GPollableOutputStream *stream,
Packit ae235b
					     GCancellable          *cancellable)
Packit ae235b
{
Packit ae235b
  GUnixOutputStream *unix_stream = G_UNIX_OUTPUT_STREAM (stream);
Packit ae235b
  GSource *inner_source, *cancellable_source, *pollable_source;
Packit ae235b
Packit ae235b
  pollable_source = g_pollable_source_new (G_OBJECT (stream));
Packit ae235b
Packit ae235b
  inner_source = g_unix_fd_source_new (unix_stream->priv->fd, G_IO_OUT);
Packit ae235b
  g_source_set_dummy_callback (inner_source);
Packit ae235b
  g_source_add_child_source (pollable_source, inner_source);
Packit ae235b
  g_source_unref (inner_source);
Packit ae235b
Packit ae235b
  if (cancellable)
Packit ae235b
    {
Packit ae235b
      cancellable_source = g_cancellable_source_new (cancellable);
Packit ae235b
      g_source_set_dummy_callback (cancellable_source);
Packit ae235b
      g_source_add_child_source (pollable_source, cancellable_source);
Packit ae235b
      g_source_unref (cancellable_source);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return pollable_source;
Packit ae235b
}