[gvfs] afp: Try to prevent idle disconnects



commit a4016460538ea8be22aa0d8289922b389a93ef78
Author: Ross Lagerwall <rosslagerwall gmail com>
Date:   Sun Aug 3 11:03:28 2014 +0100

    afp: Try to prevent idle disconnects
    
    Some servers (e.g. OS X 10.8) disconnect clients who don't respond to
    server notifications.  Prevent this by sending FPGetVolParms, as the
    spec suggests.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=734194

 daemon/gvfsafpconnection.h |    1 +
 daemon/gvfsafpvolume.c     |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/daemon/gvfsafpconnection.h b/daemon/gvfsafpconnection.h
index 367f983..5d90cf6 100644
--- a/daemon/gvfsafpconnection.h
+++ b/daemon/gvfsafpconnection.h
@@ -165,6 +165,7 @@ enum
 enum
 {
   AFP_ATTENTION_CODE_MESSAGE_AVAILABLE     = 0x2,
+  AFP_ATTENTION_CODE_SERVER_NOTIFICATION   = 0x3,
   AFP_ATTENTION_CODE_IMMEDIATE_SHUTDOWN    = 0x4,
   AFP_ATTENTION_CODE_SHUTDOWN_NO_MESSAGE   = 0x8,
   AFP_ATTENTION_CODE_DISCONNECT_NO_MESSAGE = 0x9,
diff --git a/daemon/gvfsafpvolume.c b/daemon/gvfsafpvolume.c
index b0e44de..1a0b667 100644
--- a/daemon/gvfsafpvolume.c
+++ b/daemon/gvfsafpvolume.c
@@ -41,6 +41,9 @@ struct _GVfsAfpVolumePrivate
 };
 
 static void
+attention_cb (GVfsAfpConnection *conn, guint attention, GVfsAfpVolume *volume);
+
+static void
 g_vfs_afp_volume_init (GVfsAfpVolume *volume)
 {
   GVfsAfpVolumePrivate *priv;
@@ -53,7 +56,13 @@ g_vfs_afp_volume_init (GVfsAfpVolume *volume)
 static void
 g_vfs_afp_volume_finalize (GObject *object)
 {
+  GVfsAfpVolume *volume;
+  GVfsAfpVolumePrivate *priv;
+
   /* TODO: Add deinitalization code here */
+  volume = G_VFS_AFP_VOLUME (object);
+  priv = volume->priv;
+  g_signal_handlers_disconnect_by_func (priv->conn, attention_cb, volume);
 
   G_OBJECT_CLASS (g_vfs_afp_volume_parent_class)->finalize (object);
 }
@@ -82,6 +91,7 @@ g_vfs_afp_volume_new (GVfsAfpServer *server, GVfsAfpConnection *conn)
 
   priv->server = server;
   priv->conn = conn;
+  g_signal_connect (priv->conn, "attention", G_CALLBACK (attention_cb), volume);
 
   return volume;
 }
@@ -2887,3 +2897,14 @@ g_vfs_afp_volume_read_from_fork_finish (GVfsAfpVolume  *volume,
   
   return TRUE;
 }
+
+static void
+attention_cb (GVfsAfpConnection *conn, guint attention, GVfsAfpVolume *volume)
+{
+  /* Respond to the server notification with FPGetVolParms as the spec
+   * suggests.  Some servers disconnect us if we don't. */
+  if (attention == AFP_ATTENTION_CODE_SERVER_NOTIFICATION)
+    g_vfs_afp_volume_get_parms (volume,
+                                AFP_VOLUME_BITMAP_VOL_ID_BIT,
+                                NULL, NULL, NULL);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]