[gvfs] [FTP] reuse cancellable instead of creating a new one
- From: Benjamin Otte <otte src gnome org>
- To: svn-commits-list gnome org
- Subject: [gvfs] [FTP] reuse cancellable instead of creating a new one
- Date: Thu, 11 Jun 2009 05:21:08 -0400 (EDT)
commit 9d7a1de3017e240b0af23d2a51237d75fb14ae09
Author: Benjamin Otte <otte gnome org>
Date: Tue Jun 9 12:24:09 2009 +0200
[FTP] reuse cancellable instead of creating a new one
Now that a corner case in glib was fixed, it's possible to use
g_cancellable_reset() and reuse the cancellable after timeouts instead
of creating a new one.
If you want to avoid random hangs and g_critical()s when transferring
files, you need glib commit ced88fd0de4aedb537552561582875b427081eeb
I've update the glib requirements accordingly.
---
configure.ac | 2 +-
daemon/gvfsbackendftp.c | 37 +++++++++++++++++++------------------
2 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/configure.ac b/configure.ac
index 80341eb..f1dd70b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ GTK_DOC_CHECK
DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc"
AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.21.1 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0 )
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.21.2 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0 )
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
diff --git a/daemon/gvfsbackendftp.c b/daemon/gvfsbackendftp.c
index b63a66a..0c35fa3 100644
--- a/daemon/gvfsbackendftp.c
+++ b/daemon/gvfsbackendftp.c
@@ -1187,23 +1187,29 @@ ftp_output_stream_splice (GOutputStream *output,
gssize n_read, n_written;
gssize bytes_copied;
char buffer[8192], *p;
- GCancellable *timer_cancel;
+ GCancellable *current, *timer_cancel;
gulong cancel_cb_id;
bytes_copied = 0;
- timer_cancel = NULL;
-
+ if (progress_callback)
+ {
+ timer_cancel = g_cancellable_new ();
+ cancel_cb_id = g_cancellable_connect (cancellable,
+ G_CALLBACK (cancel_timer_cb),
+ timer_cancel,
+ NULL);
+ }
+ current = cancellable;
for (;;)
{
- n_read = g_input_stream_read (input, buffer, sizeof (buffer), timer_cancel ? timer_cancel : cancellable, error);
+ n_read = g_input_stream_read (input, buffer, sizeof (buffer), current, error);
if (n_read == -1)
{
if (g_cancellable_is_cancelled (timer_cancel) &&
!g_cancellable_is_cancelled (cancellable))
{
- g_cancellable_disconnect (cancellable, cancel_cb_id);
- g_object_unref (timer_cancel);
- timer_cancel = NULL;
+ g_cancellable_reset (timer_cancel);
+ current = cancellable;
g_clear_error (error);
progress_callback (bytes_copied, total_size, progress_callback_data);
}
@@ -1219,17 +1225,16 @@ ftp_output_stream_splice (GOutputStream *output,
p = buffer;
while (n_read > 0)
{
- n_written = g_output_stream_write (output, p, n_read, timer_cancel ? timer_cancel : cancellable, error);
+ n_written = g_output_stream_write (output, p, n_read, current, error);
if (n_written == -1)
{
if (g_cancellable_is_cancelled (timer_cancel) &&
!g_cancellable_is_cancelled (cancellable))
{
- g_cancellable_disconnect (cancellable, cancel_cb_id);
- g_object_unref (timer_cancel);
- timer_cancel = NULL;
+ g_cancellable_reset (timer_cancel);
+ current = cancellable;
g_clear_error (error);
- progress_callback (bytes_copied + n_written, total_size, progress_callback_data);
+ progress_callback (bytes_copied, total_size, progress_callback_data);
}
else
{
@@ -1241,19 +1246,15 @@ ftp_output_stream_splice (GOutputStream *output,
p += n_written;
n_read -= n_written;
bytes_copied += n_written;
- if (progress_callback && timer_cancel == NULL)
+ if (progress_callback && current != timer_cancel)
{
- timer_cancel = g_cancellable_new ();
- cancel_cb_id = g_cancellable_connect (cancellable,
- G_CALLBACK (cancel_timer_cb),
- timer_cancel,
- NULL);
g_object_ref (timer_cancel);
g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
1,
cancel_cancellable,
timer_cancel,
g_object_unref);
+ current = timer_cancel;
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]