1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
4 * @author: Xavier Claessens <xclaesse@gmail.com>
5 * Copyright (C) 2007 Marco Barisione <marco@barisione.org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <sys/types.h>
27 #include <sys/socket.h>
30 #include <glib/gi18n.h>
33 #include <gio/gunixinputstream.h>
34 #include <gio/gunixoutputstream.h>
36 #include <libtelepathy/tp-conn.h>
37 #include <libtelepathy/tp-helpers.h>
38 #include <libtelepathy/tp-props-iface.h>
40 #include <telepathy-glib/proxy-subclass.h>
42 #include "empathy-tp-file.h"
43 #include "empathy-file.h"
44 #include "empathy-tp-file-priv.h"
45 #include "empathy-contact-factory.h"
46 #include "empathy-marshal.h"
47 #include "empathy-time.h"
48 #include "empathy-utils.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_FT
51 #include "empathy-debug.h"
54 * SECTION:empathy-tp-file
55 * @short_description: File channel
56 * @see_also: #EmpathyFile, #EmpathyContact, empathy_send_file()
57 * @include: libempthy/empathy-tp-file.h
59 * The #EmpathyTpFile object represents a Telepathy file channel.
62 static void empathy_tp_file_class_init (EmpathyTpFileClass *klass);
63 static void empathy_tp_file_init (EmpathyTpFile *tp_file);
64 static void tp_file_finalize (GObject *object);
65 static GObject * tp_file_constructor (GType type,
67 GObjectConstructParam *props);
68 static void tp_file_get_property (GObject *object,
72 static void tp_file_set_property (GObject *object,
76 static void tp_file_destroy_cb (TpChannel *file_chan,
77 EmpathyTpFile *tp_file);
78 static void tp_file_closed_cb (TpChannel *file_chan,
79 EmpathyTpFile *tp_file,
80 GObject *weak_object);
81 static void tp_file_state_changed_cb (DBusGProxy *file_iface,
84 EmpathyTpFile *tp_file);
85 static void tp_file_transferred_bytes_changed_cb (DBusGProxy *file_iface,
86 guint64 transferred_bytes,
87 EmpathyTpFile *tp_file);
88 static void copy_stream (GInputStream *in,
90 GCancellable *cancellable);
92 /* EmpathyTpFile object */
94 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
95 EMPATHY_TYPE_TP_FILE, EmpathyTpFilePriv))
97 typedef struct _EmpathyTpFilePriv EmpathyTpFilePriv;
99 struct _EmpathyTpFilePriv {
100 EmpathyContactFactory *factory;
107 /* Previously in File/FT struct */
108 EmpathyFile *cached_empathy_file;
109 EmpathyContact *contact;
110 GInputStream *in_stream;
111 GOutputStream *out_stream;
113 EmpFileTransferDirection direction;
114 EmpFileTransferState state;
115 EmpFileTransferStateChangeReason state_change_reason;
117 guint64 transferred_bytes;
119 gchar *unix_socket_path;
123 GCancellable *cancellable;
139 G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT);
142 empathy_tp_file_class_init (EmpathyTpFileClass *klass)
144 GObjectClass *object_class = G_OBJECT_CLASS (klass);
146 object_class->finalize = tp_file_finalize;
147 object_class->constructor = tp_file_constructor;
148 object_class->get_property = tp_file_get_property;
149 object_class->set_property = tp_file_set_property;
151 /* Construct-only properties */
152 g_object_class_install_property (object_class,
154 g_param_spec_object ("account",
156 "The account associated with the channel",
159 G_PARAM_CONSTRUCT_ONLY));
161 g_object_class_install_property (object_class,
163 g_param_spec_object ("channel",
165 "The file transfer channel",
168 G_PARAM_CONSTRUCT_ONLY));
170 g_object_class_install_property (object_class,
172 g_param_spec_uint ("state",
173 "state of the transfer",
174 "The file transfer state",
181 g_object_class_install_property (object_class,
183 g_param_spec_uint ("direction",
184 "direction of the transfer",
185 "The file transfer direction",
192 g_object_class_install_property (object_class,
194 g_param_spec_string ("filename",
195 "name of the transfer",
196 "The file transfer filename",
200 g_object_class_install_property (object_class,
202 g_param_spec_uint64 ("size",
204 "The file transfer size",
210 g_object_class_install_property (object_class,
212 g_param_spec_string ("content-type",
213 "file transfer content-type",
214 "The file transfer content-type",
218 g_object_class_install_property (object_class,
220 g_param_spec_string ("content-md5",
221 "file transfer md5sum",
222 "The md5 sum of the transfer's contents",
226 g_object_class_install_property (object_class,
228 g_param_spec_object ("in-stream",
229 "transfer input stream",
230 "The input stream for file transfer",
234 g_type_class_add_private (object_class, sizeof (EmpathyTpFilePriv));
238 empathy_tp_file_init (EmpathyTpFile *tp_file)
243 tp_file_finalize (GObject *object)
245 EmpathyTpFilePriv *priv;
246 EmpathyTpFile *tp_file;
248 tp_file = EMPATHY_TP_FILE (object);
249 priv = GET_PRIV (tp_file);
253 DEBUG ("Closing channel..");
254 g_signal_handlers_disconnect_by_func (priv->channel,
255 tp_file_destroy_cb, object);
256 tp_cli_channel_run_close (priv->channel, -1, NULL, NULL);
257 if (G_IS_OBJECT (priv->channel))
258 g_object_unref (priv->channel);
263 g_object_unref (priv->factory);
267 g_object_unref (priv->account);
271 g_object_unref (priv->mc);
275 g_free (priv->filename);
276 g_free (priv->unix_socket_path);
277 g_free (priv->description);
278 g_free (priv->content_md5);
279 g_free (priv->content_type);
282 g_object_unref (priv->in_stream);
284 if (priv->out_stream)
285 g_object_unref (priv->out_stream);
288 g_object_unref (priv->contact);
290 if (priv->cancellable)
291 g_object_unref (priv->cancellable);
293 G_OBJECT_CLASS (empathy_tp_file_parent_class)->finalize (object);
297 tp_file_constructor (GType type,
299 GObjectConstructParam *props)
302 EmpathyTpFilePriv *priv;
303 GError *error = NULL;
304 GHashTable *properties;
306 tp_file = G_OBJECT_CLASS (empathy_tp_file_parent_class)->constructor (type, n_props, props);
308 priv = GET_PRIV (tp_file);
310 priv->factory = empathy_contact_factory_new ();
311 priv->mc = empathy_mission_control_new ();
313 tp_cli_channel_connect_to_closed (priv->channel,
314 (tp_cli_channel_signal_callback_closed) tp_file_closed_cb,
318 emp_cli_channel_type_file_connect_to_file_transfer_state_changed (TP_PROXY (priv->channel),
319 (emp_cli_channel_type_file_signal_callback_file_transfer_state_changed) tp_file_state_changed_cb,
323 emp_cli_channel_type_file_connect_to_transferred_bytes_changed (TP_PROXY (priv->channel),
324 (emp_cli_channel_type_file_signal_callback_transferred_bytes_changed) tp_file_transferred_bytes_changed_cb,
328 if (!tp_cli_dbus_properties_run_get_all (priv->channel,
329 -1, EMP_IFACE_CHANNEL_TYPE_FILE, &properties, &error, NULL))
331 DEBUG ("Failed to get properties: %s",
332 error ? error->message : "No error given");
333 g_clear_error (&error);
337 priv->size = g_value_get_uint64 (g_hash_table_lookup (properties, "Size"));
339 priv->state = g_value_get_uint (g_hash_table_lookup (properties, "State"));
341 /* Invalid reason, so empathy_file_get_state_change_reason() can give
342 * a warning if called for a not closed file transfer. */
343 priv->state_change_reason = -1;
345 priv->transferred_bytes = g_value_get_uint64 (g_hash_table_lookup (properties, "TransferredBytes"));
347 priv->filename = g_value_dup_string (g_hash_table_lookup (properties, "Filename"));
349 priv->content_md5 = g_value_dup_string (g_hash_table_lookup (properties, "ContentMD5"));
351 priv->description = g_value_dup_string (g_hash_table_lookup (properties, "Description"));
353 priv->unix_socket_path = g_value_dup_string (g_hash_table_lookup (properties, "SocketPath"));
355 priv->direction = g_value_get_uint (g_hash_table_lookup (properties, "Direction"));
357 g_hash_table_destroy (properties);
363 tp_file_get_property (GObject *object,
368 EmpathyTpFilePriv *priv;
369 EmpathyTpFile *tp_file;
371 priv = GET_PRIV (object);
372 tp_file = EMPATHY_TP_FILE (object);
377 g_value_set_object (value, priv->account);
380 g_value_set_object (value, priv->channel);
383 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
389 tp_file_channel_set_dbus_property (gpointer proxy,
390 const gchar *property,
393 DEBUG ("Setting %s property", property);
394 tp_cli_dbus_properties_run_set (TP_PROXY (proxy),
396 EMP_IFACE_CHANNEL_TYPE_FILE,
406 tp_file_set_property (GObject *object,
411 EmpathyTpFilePriv *priv;
413 priv = GET_PRIV (object);
418 priv->account = g_object_ref (g_value_get_object (value));
421 priv->channel = g_object_ref (g_value_get_object (value));
424 priv->state = g_value_get_uint (value);
427 priv->direction = g_value_get_uint (value);
430 g_free (priv->filename);
431 priv->filename = g_value_dup_string (value);
432 tp_file_channel_set_dbus_property (priv->channel, "Filename", value);
435 priv->size = g_value_get_uint64 (value);
436 tp_file_channel_set_dbus_property (priv->channel, "Size", value);
438 case PROP_CONTENT_TYPE:
439 tp_file_channel_set_dbus_property (priv->channel, "ContentType", value);
440 g_free (priv->content_type);
441 priv->content_type = g_value_dup_string (value);
443 case PROP_CONTENT_MD5:
444 tp_file_channel_set_dbus_property (priv->channel, "ContentMD5", value);
445 g_free (priv->content_md5);
446 priv->content_md5 = g_value_dup_string (value);
450 g_object_unref (priv->in_stream);
451 priv->in_stream = g_object_ref (g_value_get_object (value));
454 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
460 * empathy_tp_file_new:
461 * @account: the #McAccount for the channel
462 * @channel: a Telepathy channel
464 * Creates a new #EmpathyTpFile wrapping @channel.
466 * Returns: a new #EmpathyTpFile
469 empathy_tp_file_new (McAccount *account,
472 return g_object_new (EMPATHY_TYPE_TP_FILE,
479 * empathy_tp_file_get_id:
480 * @tp_file: an #EmpathyTpFile
482 * Returns the ID of @tp_file.
487 empathy_tp_file_get_id (EmpathyTpFile *tp_file)
489 EmpathyTpFilePriv *priv;
491 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
493 priv = GET_PRIV (tp_file);
499 * empathy_tp_file_get_channel
500 * @tp_file: an #EmpathyTpFile
502 * Returns the Telepathy file transfer channel
504 * Returns: the #TpChannel
507 empathy_tp_file_get_channel (EmpathyTpFile *tp_file)
509 EmpathyTpFilePriv *priv;
511 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
513 priv = GET_PRIV (tp_file);
515 return priv->channel;
519 tp_file_destroy_cb (TpChannel *file_channel, EmpathyTpFile *tp_file)
521 EmpathyTpFilePriv *priv;
523 priv = GET_PRIV (tp_file);
525 DEBUG ("Channel Closed or CM crashed");
527 g_object_unref (priv->channel);
528 priv->channel = NULL;
532 tp_file_closed_cb (TpChannel *file_channel, EmpathyTpFile *tp_file, GObject *weak_object)
534 EmpathyTpFilePriv *priv;
536 priv = GET_PRIV (tp_file);
538 /* The channel is closed, do just like if the proxy was destroyed */
539 g_signal_handlers_disconnect_by_func (priv->channel,
542 tp_file_destroy_cb (file_channel, tp_file);
550 g_get_current_time (&tv);
551 return ((gint64) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
555 _get_local_socket (EmpathyTpFile *tp_file)
559 struct sockaddr_un addr;
560 EmpathyTpFilePriv *priv;
562 priv = GET_PRIV (tp_file);
564 if (priv->unix_socket_path == NULL)
567 fd = socket (PF_UNIX, SOCK_STREAM, 0);
571 memset (&addr, 0, sizeof (addr));
572 addr.sun_family = AF_UNIX;
573 path_len = strlen (priv->unix_socket_path);
574 strncpy (addr.sun_path, priv->unix_socket_path, path_len);
576 if (connect (fd, (struct sockaddr*) &addr,
577 G_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
587 send_file (EmpathyTpFile *tp_file)
590 GOutputStream *socket_stream;
591 EmpathyTpFilePriv *priv;
593 priv = GET_PRIV (tp_file);
595 DEBUG ("Sending file content: filename=%s",
598 g_return_if_fail (priv->in_stream);
600 socket_fd = _get_local_socket (tp_file);
603 DEBUG ("failed to get local socket fd");
606 DEBUG ("got local socket fd");
607 socket_stream = g_unix_output_stream_new (socket_fd, TRUE);
609 priv->cancellable = g_cancellable_new ();
611 copy_stream (priv->in_stream, socket_stream, priv->cancellable);
613 g_object_unref (socket_stream);
617 tp_file_state_changed_cb (DBusGProxy *file_iface,
618 EmpFileTransferState state,
619 EmpFileTransferStateChangeReason reason,
620 EmpathyTpFile *tp_file)
622 EmpathyTpFilePriv *priv;
624 priv = GET_PRIV (tp_file);
626 DEBUG ("File transfer state changed: filename=%s, "
627 "old state=%u, state=%u, reason=%u",
628 priv->filename, priv->state, state, reason);
630 if (state == EMP_FILE_TRANSFER_STATE_OPEN)
631 priv->start_time = get_time_msec ();
633 DEBUG ("state = %u, direction = %u, in_stream = %s",
634 state, priv->direction, priv->in_stream ? "present" : "not present");
636 if (state == EMP_FILE_TRANSFER_STATE_OPEN &&
637 priv->direction == EMP_FILE_TRANSFER_DIRECTION_OUTGOING &&
642 priv->state_change_reason = reason;
644 g_object_notify (G_OBJECT (tp_file), "state");
648 tp_file_transferred_bytes_changed_cb (DBusGProxy *file_iface,
649 guint64 transferred_bytes, EmpathyTpFile *tp_file)
651 EmpathyTpFilePriv *priv;
653 priv = GET_PRIV (tp_file);
655 if (priv->transferred_bytes == transferred_bytes)
658 priv->transferred_bytes = transferred_bytes;
660 g_object_notify (G_OBJECT (tp_file), "transferred-bytes");
664 _empathy_tp_file_get_contact (EmpathyTpFile *tp_file)
666 EmpathyTpFilePriv *priv;
668 priv = GET_PRIV (tp_file);
670 return priv->contact;
674 _empathy_tp_file_get_input_stream (EmpathyTpFile *tp_file)
676 EmpathyTpFilePriv *priv;
678 priv = GET_PRIV (tp_file);
680 return priv->in_stream;
684 _empathy_tp_file_get_output_stream (EmpathyTpFile *tp_file)
686 EmpathyTpFilePriv *priv;
688 priv = GET_PRIV (tp_file);
690 return priv->out_stream;
694 _empathy_tp_file_get_filename (EmpathyTpFile *tp_file)
696 EmpathyTpFilePriv *priv;
698 priv = GET_PRIV (tp_file);
700 return priv->filename;
703 EmpFileTransferDirection
704 _empathy_tp_file_get_direction (EmpathyTpFile *tp_file)
706 EmpathyTpFilePriv *priv;
708 priv = GET_PRIV (tp_file);
710 return priv->direction;
714 _empathy_tp_file_get_state (EmpathyTpFile *tp_file)
716 EmpathyTpFilePriv *priv;
718 priv = GET_PRIV (tp_file);
723 EmpFileTransferStateChangeReason
724 _empathy_tp_file_get_state_change_reason (EmpathyTpFile *tp_file)
726 EmpathyTpFilePriv *priv;
728 priv = GET_PRIV (tp_file);
730 g_return_val_if_fail (priv->state_change_reason >= 0,
731 EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE);
733 return priv->state_change_reason;
737 _empathy_tp_file_get_size (EmpathyTpFile *tp_file)
739 EmpathyTpFilePriv *priv;
741 priv = GET_PRIV (tp_file);
747 _empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file)
749 EmpathyTpFilePriv *priv;
751 priv = GET_PRIV (tp_file);
753 return priv->transferred_bytes;
757 _empathy_tp_file_get_remaining_time (EmpathyTpFile *tp_file)
759 EmpathyTpFilePriv *priv;
760 gint64 curr_time, elapsed_time;
761 gdouble time_per_byte;
762 gdouble remaining_time;
764 priv = GET_PRIV (tp_file);
766 if (priv->size == EMPATHY_FILE_UNKNOWN_SIZE)
769 if (priv->transferred_bytes == priv->size)
772 curr_time = get_time_msec ();
773 elapsed_time = curr_time - priv->start_time;
774 time_per_byte = (gdouble) elapsed_time / (gdouble) priv->transferred_bytes;
775 remaining_time = (time_per_byte * (priv->size - priv->transferred_bytes)) / 1000;
777 return (gint) (remaining_time + 0.5);
781 _empathy_tp_file_set_input_stream (EmpathyTpFile *tp_file,
782 GInputStream *in_stream)
784 EmpathyTpFilePriv *priv;
786 priv = GET_PRIV (tp_file);
788 if (priv->in_stream == in_stream)
791 if (priv->direction == EMP_FILE_TRANSFER_DIRECTION_INCOMING)
792 g_warning ("Setting an input stream for incoming file "
793 "transfers is useless");
796 g_object_unref (priv->in_stream);
798 g_object_ref (in_stream);
799 priv->in_stream = in_stream;
801 g_object_notify (G_OBJECT (tp_file), "in-stream");
805 _empathy_tp_file_set_output_stream (EmpathyTpFile *tp_file,
806 GOutputStream *out_stream)
808 EmpathyTpFilePriv *priv;
810 priv = GET_PRIV (tp_file);
812 if (priv->out_stream == out_stream)
815 if (priv->direction == EMP_FILE_TRANSFER_DIRECTION_OUTGOING)
816 g_warning ("Setting an output stream for outgoing file "
817 "transfers is useless");
819 if (priv->out_stream)
820 g_object_unref (priv->out_stream);
822 g_object_ref (out_stream);
823 priv->out_stream = out_stream;
825 g_object_notify (G_OBJECT (tp_file), "output-stream");
829 _empathy_tp_file_set_filename (EmpathyTpFile *tp_file,
830 const gchar *filename)
832 EmpathyTpFilePriv *priv;
834 priv = GET_PRIV (tp_file);
836 g_return_if_fail (filename != NULL);
838 if (priv->filename && strcmp (filename, priv->filename) == 0) {
842 g_free (priv->filename);
843 priv->filename = g_strdup (filename);
845 g_object_notify (G_OBJECT (tp_file), "filename");
848 /* Functions to copy the content of a GInputStream to a GOutputStream */
851 #define BUFFER_SIZE 4096
856 GCancellable *cancellable;
857 char *buff[N_BUFFERS]; /* the temporary buffers */
858 gsize count[N_BUFFERS]; /* how many bytes are used in the buffers */
859 gboolean is_full[N_BUFFERS]; /* whether the buffers contain data */
860 gint curr_read; /* index of the buffer used for reading */
861 gint curr_write; /* index of the buffer used for writing */
862 gboolean is_reading; /* we are reading */
863 gboolean is_writing; /* we are writing */
864 guint n_closed; /* number of streams that have been closed */
867 static void schedule_next (CopyData *copy);
870 free_copy_data_if_closed (CopyData *copy)
874 /* Free the data only if both the input and output streams have
877 if (copy->n_closed < 2)
880 if (copy->in != NULL)
881 g_object_unref (copy->in);
883 if (copy->out != NULL)
884 g_object_unref (copy->out);
886 for (i = 0; i < N_BUFFERS; i++)
887 g_free (copy->buff[i]);
889 g_object_unref (copy->cancellable);
894 io_error (CopyData *copy, GError *error)
896 g_cancellable_cancel (copy->cancellable);
899 g_warning ("I/O error");
900 else if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
901 ; /* Ignore cancellations */
903 g_warning ("I/O error: %d: %s\n", error->code, error->message);
905 if (copy->in != NULL)
906 g_input_stream_close (copy->in, NULL, NULL);
908 if (copy->out != NULL)
909 g_output_stream_close (copy->out, NULL, NULL);
911 free_copy_data_if_closed (copy);
915 close_done (GObject *source_object, GAsyncResult *res, gpointer user_data)
917 CopyData *copy = user_data;
919 g_object_unref (source_object);
920 free_copy_data_if_closed (copy);
924 write_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
926 CopyData *copy = user_data;
928 GError *error = NULL;
930 count_write = g_output_stream_write_finish (copy->out, res, &error);
932 if (count_write <= 0) {
933 io_error (copy, error);
934 g_error_free (error);
938 copy->is_full[copy->curr_write] = FALSE;
939 copy->curr_write = (copy->curr_write + 1) % N_BUFFERS;
940 copy->is_writing = FALSE;
942 schedule_next (copy);
946 read_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
948 CopyData *copy = user_data;
950 GError *error = NULL;
952 count_read = g_input_stream_read_finish (copy->in, res, &error);
954 if (count_read == 0) {
955 g_input_stream_close_async (copy->in, 0, copy->cancellable,
959 else if (count_read < 0) {
960 io_error (copy, error);
961 g_error_free (error);
965 copy->count[copy->curr_read] = count_read;
966 copy->is_full[copy->curr_read] = TRUE;
967 copy->curr_read = (copy->curr_read + 1) % N_BUFFERS;
968 copy->is_reading = FALSE;
970 schedule_next (copy);
974 schedule_next (CopyData *copy)
976 if (copy->in != NULL &&
978 !copy->is_full[copy->curr_read]) {
979 /* We are not reading and the current buffer is empty, so
980 * start an async read. */
981 copy->is_reading = TRUE;
982 g_input_stream_read_async (copy->in,
983 copy->buff[copy->curr_read],
984 BUFFER_SIZE, 0, copy->cancellable,
988 if (!copy->is_writing &&
989 copy->is_full[copy->curr_write]) {
990 if (copy->count[copy->curr_write] == 0) {
991 /* The last read on the buffer read 0 bytes, this
992 * means that we got an EOF, so we can close
993 * the output channel. */
994 g_output_stream_close_async (copy->out, 0,
999 /* We are not writing and the current buffer contains
1000 * data, so start an async write. */
1001 copy->is_writing = TRUE;
1002 g_output_stream_write_async (copy->out,
1003 copy->buff[copy->curr_write],
1004 copy->count[copy->curr_write],
1005 0, copy->cancellable,
1006 write_done_cb, copy);
1012 copy_stream (GInputStream *in, GOutputStream *out, GCancellable *cancellable)
1017 g_return_if_fail (in != NULL);
1018 g_return_if_fail (out != NULL);
1020 copy = g_new0 (CopyData, 1);
1021 copy->in = g_object_ref (in);
1022 copy->out = g_object_ref (out);
1024 if (cancellable != NULL)
1025 copy->cancellable = g_object_ref (cancellable);
1027 copy->cancellable = g_cancellable_new ();
1029 for (i = 0; i < N_BUFFERS; i++)
1030 copy->buff[i] = g_malloc (BUFFER_SIZE);
1032 schedule_next (copy);