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;
307 tp_file = G_OBJECT_CLASS (empathy_tp_file_parent_class)->constructor (type, n_props, props);
309 priv = GET_PRIV (tp_file);
311 priv->factory = empathy_contact_factory_new ();
312 priv->mc = empathy_mission_control_new ();
314 tp_cli_channel_connect_to_closed (priv->channel,
315 (tp_cli_channel_signal_callback_closed) tp_file_closed_cb,
319 emp_cli_channel_type_file_connect_to_file_transfer_state_changed (TP_PROXY (priv->channel),
320 (emp_cli_channel_type_file_signal_callback_file_transfer_state_changed) tp_file_state_changed_cb,
324 emp_cli_channel_type_file_connect_to_transferred_bytes_changed (TP_PROXY (priv->channel),
325 (emp_cli_channel_type_file_signal_callback_transferred_bytes_changed) tp_file_transferred_bytes_changed_cb,
330 handle = tp_channel_get_handle (priv->channel, NULL);
331 priv->contact = empathy_contact_factory_get_from_handle (priv->factory,
335 if (!tp_cli_dbus_properties_run_get_all (priv->channel,
336 -1, EMP_IFACE_CHANNEL_TYPE_FILE, &properties, &error, NULL))
338 DEBUG ("Failed to get properties: %s",
339 error ? error->message : "No error given");
340 g_clear_error (&error);
344 priv->size = g_value_get_uint64 (g_hash_table_lookup (properties, "Size"));
346 priv->state = g_value_get_uint (g_hash_table_lookup (properties, "State"));
348 /* Invalid reason, so empathy_file_get_state_change_reason() can give
349 * a warning if called for a not closed file transfer. */
350 priv->state_change_reason = -1;
352 priv->transferred_bytes = g_value_get_uint64 (g_hash_table_lookup (properties, "TransferredBytes"));
354 priv->filename = g_value_dup_string (g_hash_table_lookup (properties, "Filename"));
356 priv->content_md5 = g_value_dup_string (g_hash_table_lookup (properties, "ContentMD5"));
358 priv->description = g_value_dup_string (g_hash_table_lookup (properties, "Description"));
360 priv->unix_socket_path = g_value_dup_string (g_hash_table_lookup (properties, "SocketPath"));
362 priv->direction = g_value_get_uint (g_hash_table_lookup (properties, "Direction"));
364 g_hash_table_destroy (properties);
370 tp_file_get_property (GObject *object,
375 EmpathyTpFilePriv *priv;
376 EmpathyTpFile *tp_file;
378 priv = GET_PRIV (object);
379 tp_file = EMPATHY_TP_FILE (object);
384 g_value_set_object (value, priv->account);
387 g_value_set_object (value, priv->channel);
390 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
396 tp_file_channel_set_dbus_property (gpointer proxy,
397 const gchar *property,
400 DEBUG ("Setting %s property", property);
401 tp_cli_dbus_properties_run_set (TP_PROXY (proxy),
403 EMP_IFACE_CHANNEL_TYPE_FILE,
413 tp_file_set_property (GObject *object,
418 EmpathyTpFilePriv *priv;
420 priv = GET_PRIV (object);
425 priv->account = g_object_ref (g_value_get_object (value));
428 priv->channel = g_object_ref (g_value_get_object (value));
431 priv->state = g_value_get_uint (value);
434 priv->direction = g_value_get_uint (value);
437 g_free (priv->filename);
438 priv->filename = g_value_dup_string (value);
439 tp_file_channel_set_dbus_property (priv->channel, "Filename", value);
442 priv->size = g_value_get_uint64 (value);
443 tp_file_channel_set_dbus_property (priv->channel, "Size", value);
445 case PROP_CONTENT_TYPE:
446 tp_file_channel_set_dbus_property (priv->channel, "ContentType", value);
447 g_free (priv->content_type);
448 priv->content_type = g_value_dup_string (value);
450 case PROP_CONTENT_MD5:
451 tp_file_channel_set_dbus_property (priv->channel, "ContentMD5", value);
452 g_free (priv->content_md5);
453 priv->content_md5 = g_value_dup_string (value);
457 g_object_unref (priv->in_stream);
458 priv->in_stream = g_object_ref (g_value_get_object (value));
461 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
467 * empathy_tp_file_new:
468 * @account: the #McAccount for the channel
469 * @channel: a Telepathy channel
471 * Creates a new #EmpathyTpFile wrapping @channel.
473 * Returns: a new #EmpathyTpFile
476 empathy_tp_file_new (McAccount *account,
479 return g_object_new (EMPATHY_TYPE_TP_FILE,
486 * empathy_tp_file_get_id:
487 * @tp_file: an #EmpathyTpFile
489 * Returns the ID of @tp_file.
494 empathy_tp_file_get_id (EmpathyTpFile *tp_file)
496 EmpathyTpFilePriv *priv;
498 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
500 priv = GET_PRIV (tp_file);
506 * empathy_tp_file_get_channel
507 * @tp_file: an #EmpathyTpFile
509 * Returns the Telepathy file transfer channel
511 * Returns: the #TpChannel
514 empathy_tp_file_get_channel (EmpathyTpFile *tp_file)
516 EmpathyTpFilePriv *priv;
518 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
520 priv = GET_PRIV (tp_file);
522 return priv->channel;
526 tp_file_destroy_cb (TpChannel *file_channel, EmpathyTpFile *tp_file)
528 EmpathyTpFilePriv *priv;
530 priv = GET_PRIV (tp_file);
532 DEBUG ("Channel Closed or CM crashed");
534 g_object_unref (priv->channel);
535 priv->channel = NULL;
539 tp_file_closed_cb (TpChannel *file_channel, EmpathyTpFile *tp_file, GObject *weak_object)
541 EmpathyTpFilePriv *priv;
543 priv = GET_PRIV (tp_file);
545 /* The channel is closed, do just like if the proxy was destroyed */
546 g_signal_handlers_disconnect_by_func (priv->channel,
549 tp_file_destroy_cb (file_channel, tp_file);
557 g_get_current_time (&tv);
558 return ((gint64) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
562 _get_local_socket (EmpathyTpFile *tp_file)
566 struct sockaddr_un addr;
567 EmpathyTpFilePriv *priv;
569 priv = GET_PRIV (tp_file);
571 if (priv->unix_socket_path == NULL)
574 fd = socket (PF_UNIX, SOCK_STREAM, 0);
578 memset (&addr, 0, sizeof (addr));
579 addr.sun_family = AF_UNIX;
580 path_len = strlen (priv->unix_socket_path);
581 strncpy (addr.sun_path, priv->unix_socket_path, path_len);
583 if (connect (fd, (struct sockaddr*) &addr,
584 G_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
594 send_file (EmpathyTpFile *tp_file)
597 GOutputStream *socket_stream;
598 EmpathyTpFilePriv *priv;
600 priv = GET_PRIV (tp_file);
602 DEBUG ("Sending file content: filename=%s",
605 g_return_if_fail (priv->in_stream);
607 socket_fd = _get_local_socket (tp_file);
610 DEBUG ("failed to get local socket fd");
613 DEBUG ("got local socket fd");
614 socket_stream = g_unix_output_stream_new (socket_fd, TRUE);
616 priv->cancellable = g_cancellable_new ();
618 copy_stream (priv->in_stream, socket_stream, priv->cancellable);
620 g_object_unref (socket_stream);
624 tp_file_state_changed_cb (DBusGProxy *file_iface,
625 EmpFileTransferState state,
626 EmpFileTransferStateChangeReason reason,
627 EmpathyTpFile *tp_file)
629 EmpathyTpFilePriv *priv;
631 priv = GET_PRIV (tp_file);
633 DEBUG ("File transfer state changed: filename=%s, "
634 "old state=%u, state=%u, reason=%u",
635 priv->filename, priv->state, state, reason);
637 if (state == EMP_FILE_TRANSFER_STATE_OPEN)
638 priv->start_time = get_time_msec ();
640 DEBUG ("state = %u, direction = %u, in_stream = %s",
641 state, priv->direction, priv->in_stream ? "present" : "not present");
643 if (state == EMP_FILE_TRANSFER_STATE_OPEN &&
644 priv->direction == EMP_FILE_TRANSFER_DIRECTION_OUTGOING &&
649 priv->state_change_reason = reason;
651 g_object_notify (G_OBJECT (tp_file), "state");
655 tp_file_transferred_bytes_changed_cb (DBusGProxy *file_iface,
656 guint64 transferred_bytes, EmpathyTpFile *tp_file)
658 EmpathyTpFilePriv *priv;
660 priv = GET_PRIV (tp_file);
662 if (priv->transferred_bytes == transferred_bytes)
665 priv->transferred_bytes = transferred_bytes;
667 g_object_notify (G_OBJECT (tp_file), "transferred-bytes");
671 _empathy_tp_file_get_contact (EmpathyTpFile *tp_file)
673 EmpathyTpFilePriv *priv;
675 priv = GET_PRIV (tp_file);
677 return priv->contact;
681 _empathy_tp_file_get_input_stream (EmpathyTpFile *tp_file)
683 EmpathyTpFilePriv *priv;
685 priv = GET_PRIV (tp_file);
687 return priv->in_stream;
691 _empathy_tp_file_get_output_stream (EmpathyTpFile *tp_file)
693 EmpathyTpFilePriv *priv;
695 priv = GET_PRIV (tp_file);
697 return priv->out_stream;
701 _empathy_tp_file_get_filename (EmpathyTpFile *tp_file)
703 EmpathyTpFilePriv *priv;
705 priv = GET_PRIV (tp_file);
707 return priv->filename;
710 EmpFileTransferDirection
711 _empathy_tp_file_get_direction (EmpathyTpFile *tp_file)
713 EmpathyTpFilePriv *priv;
715 priv = GET_PRIV (tp_file);
717 return priv->direction;
721 _empathy_tp_file_get_state (EmpathyTpFile *tp_file)
723 EmpathyTpFilePriv *priv;
725 priv = GET_PRIV (tp_file);
730 EmpFileTransferStateChangeReason
731 _empathy_tp_file_get_state_change_reason (EmpathyTpFile *tp_file)
733 EmpathyTpFilePriv *priv;
735 priv = GET_PRIV (tp_file);
737 g_return_val_if_fail (priv->state_change_reason >= 0,
738 EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE);
740 return priv->state_change_reason;
744 _empathy_tp_file_get_size (EmpathyTpFile *tp_file)
746 EmpathyTpFilePriv *priv;
748 priv = GET_PRIV (tp_file);
754 _empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file)
756 EmpathyTpFilePriv *priv;
758 priv = GET_PRIV (tp_file);
760 return priv->transferred_bytes;
764 _empathy_tp_file_get_remaining_time (EmpathyTpFile *tp_file)
766 EmpathyTpFilePriv *priv;
767 gint64 curr_time, elapsed_time;
768 gdouble time_per_byte;
769 gdouble remaining_time;
771 priv = GET_PRIV (tp_file);
773 if (priv->size == EMPATHY_FILE_UNKNOWN_SIZE)
776 if (priv->transferred_bytes == priv->size)
779 curr_time = get_time_msec ();
780 elapsed_time = curr_time - priv->start_time;
781 time_per_byte = (gdouble) elapsed_time / (gdouble) priv->transferred_bytes;
782 remaining_time = (time_per_byte * (priv->size - priv->transferred_bytes)) / 1000;
784 return (gint) (remaining_time + 0.5);
788 _empathy_tp_file_set_input_stream (EmpathyTpFile *tp_file,
789 GInputStream *in_stream)
791 EmpathyTpFilePriv *priv;
793 priv = GET_PRIV (tp_file);
795 if (priv->in_stream == in_stream)
798 if (priv->direction == EMP_FILE_TRANSFER_DIRECTION_INCOMING)
799 g_warning ("Setting an input stream for incoming file "
800 "transfers is useless");
803 g_object_unref (priv->in_stream);
805 g_object_ref (in_stream);
806 priv->in_stream = in_stream;
808 g_object_notify (G_OBJECT (tp_file), "in-stream");
812 _empathy_tp_file_set_output_stream (EmpathyTpFile *tp_file,
813 GOutputStream *out_stream)
815 EmpathyTpFilePriv *priv;
817 priv = GET_PRIV (tp_file);
819 if (priv->out_stream == out_stream)
822 if (priv->direction == EMP_FILE_TRANSFER_DIRECTION_OUTGOING)
823 g_warning ("Setting an output stream for outgoing file "
824 "transfers is useless");
826 if (priv->out_stream)
827 g_object_unref (priv->out_stream);
829 g_object_ref (out_stream);
830 priv->out_stream = out_stream;
832 g_object_notify (G_OBJECT (tp_file), "output-stream");
836 _empathy_tp_file_set_filename (EmpathyTpFile *tp_file,
837 const gchar *filename)
839 EmpathyTpFilePriv *priv;
841 priv = GET_PRIV (tp_file);
843 g_return_if_fail (filename != NULL);
845 if (priv->filename && strcmp (filename, priv->filename) == 0) {
849 g_free (priv->filename);
850 priv->filename = g_strdup (filename);
852 g_object_notify (G_OBJECT (tp_file), "filename");
855 /* Functions to copy the content of a GInputStream to a GOutputStream */
858 #define BUFFER_SIZE 4096
863 GCancellable *cancellable;
864 char *buff[N_BUFFERS]; /* the temporary buffers */
865 gsize count[N_BUFFERS]; /* how many bytes are used in the buffers */
866 gboolean is_full[N_BUFFERS]; /* whether the buffers contain data */
867 gint curr_read; /* index of the buffer used for reading */
868 gint curr_write; /* index of the buffer used for writing */
869 gboolean is_reading; /* we are reading */
870 gboolean is_writing; /* we are writing */
871 guint n_closed; /* number of streams that have been closed */
874 static void schedule_next (CopyData *copy);
877 free_copy_data_if_closed (CopyData *copy)
881 /* Free the data only if both the input and output streams have
884 if (copy->n_closed < 2)
887 if (copy->in != NULL)
888 g_object_unref (copy->in);
890 if (copy->out != NULL)
891 g_object_unref (copy->out);
893 for (i = 0; i < N_BUFFERS; i++)
894 g_free (copy->buff[i]);
896 g_object_unref (copy->cancellable);
901 io_error (CopyData *copy, GError *error)
903 g_cancellable_cancel (copy->cancellable);
906 g_warning ("I/O error");
907 else if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
908 ; /* Ignore cancellations */
910 g_warning ("I/O error: %d: %s\n", error->code, error->message);
912 if (copy->in != NULL)
913 g_input_stream_close (copy->in, NULL, NULL);
915 if (copy->out != NULL)
916 g_output_stream_close (copy->out, NULL, NULL);
918 free_copy_data_if_closed (copy);
922 close_done (GObject *source_object, GAsyncResult *res, gpointer user_data)
924 CopyData *copy = user_data;
926 g_object_unref (source_object);
927 free_copy_data_if_closed (copy);
931 write_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
933 CopyData *copy = user_data;
935 GError *error = NULL;
937 count_write = g_output_stream_write_finish (copy->out, res, &error);
939 if (count_write <= 0) {
940 io_error (copy, error);
941 g_error_free (error);
945 copy->is_full[copy->curr_write] = FALSE;
946 copy->curr_write = (copy->curr_write + 1) % N_BUFFERS;
947 copy->is_writing = FALSE;
949 schedule_next (copy);
953 read_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
955 CopyData *copy = user_data;
957 GError *error = NULL;
959 count_read = g_input_stream_read_finish (copy->in, res, &error);
961 if (count_read == 0) {
962 g_input_stream_close_async (copy->in, 0, copy->cancellable,
966 else if (count_read < 0) {
967 io_error (copy, error);
968 g_error_free (error);
972 copy->count[copy->curr_read] = count_read;
973 copy->is_full[copy->curr_read] = TRUE;
974 copy->curr_read = (copy->curr_read + 1) % N_BUFFERS;
975 copy->is_reading = FALSE;
977 schedule_next (copy);
981 schedule_next (CopyData *copy)
983 if (copy->in != NULL &&
985 !copy->is_full[copy->curr_read]) {
986 /* We are not reading and the current buffer is empty, so
987 * start an async read. */
988 copy->is_reading = TRUE;
989 g_input_stream_read_async (copy->in,
990 copy->buff[copy->curr_read],
991 BUFFER_SIZE, 0, copy->cancellable,
995 if (!copy->is_writing &&
996 copy->is_full[copy->curr_write]) {
997 if (copy->count[copy->curr_write] == 0) {
998 /* The last read on the buffer read 0 bytes, this
999 * means that we got an EOF, so we can close
1000 * the output channel. */
1001 g_output_stream_close_async (copy->out, 0,
1006 /* We are not writing and the current buffer contains
1007 * data, so start an async write. */
1008 copy->is_writing = TRUE;
1009 g_output_stream_write_async (copy->out,
1010 copy->buff[copy->curr_write],
1011 copy->count[copy->curr_write],
1012 0, copy->cancellable,
1013 write_done_cb, copy);
1019 copy_stream (GInputStream *in, GOutputStream *out, GCancellable *cancellable)
1024 g_return_if_fail (in != NULL);
1025 g_return_if_fail (out != NULL);
1027 copy = g_new0 (CopyData, 1);
1028 copy->in = g_object_ref (in);
1029 copy->out = g_object_ref (out);
1031 if (cancellable != NULL)
1032 copy->cancellable = g_object_ref (cancellable);
1034 copy->cancellable = g_cancellable_new ();
1036 for (i = 0; i < N_BUFFERS; i++)
1037 copy->buff[i] = g_malloc (BUFFER_SIZE);
1039 schedule_next (copy);