[gvfs] daemon: Rate limit progress callbacks
- From: Ross Lagerwall <rossl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs] daemon: Rate limit progress callbacks
- Date: Thu, 23 Jan 2014 10:11:26 +0000 (UTC)
commit 44b66a906c302bd1340fe22b0f6d39f7be6f403e
Author: Ross Lagerwall <rosslagerwall gmail com>
Date: Tue Dec 3 21:34:54 2013 +0000
daemon: Rate limit progress callbacks
To prevent flooding the dbus daemon with messages, rate limit the
progress callbacks to 10 per second (i.e. every 100 milliseconds).
https://bugzilla.gnome.org/show_bug.cgi?id=719807
daemon/gvfsjobprogress.c | 16 ++++++++++++++++
daemon/gvfsjobprogress.h | 3 +++
2 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/daemon/gvfsjobprogress.c b/daemon/gvfsjobprogress.c
index d6395df..a9caace 100644
--- a/daemon/gvfsjobprogress.c
+++ b/daemon/gvfsjobprogress.c
@@ -31,6 +31,13 @@
#include <glib/gi18n.h>
#include "gvfsjobprogress.h"
+#define RATE_LIMIT_TIME 100000
+
+struct _GVfsJobProgressPrivate
+{
+ gint64 last_time;
+};
+
G_DEFINE_TYPE (GVfsJobProgress, g_vfs_job_progress, G_VFS_TYPE_JOB_DBUS)
static void
@@ -51,6 +58,8 @@ static void
g_vfs_job_progress_class_init (GVfsJobProgressClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (GVfsJobProgressPrivate));
gobject_class->finalize = g_vfs_job_progress_finalize;
}
@@ -58,6 +67,7 @@ g_vfs_job_progress_class_init (GVfsJobProgressClass *klass)
static void
g_vfs_job_progress_init (GVfsJobProgress *job)
{
+ job->priv = G_TYPE_INSTANCE_GET_PRIVATE (job, G_VFS_TYPE_JOB_PROGRESS, GVfsJobProgressPrivate);
}
void
@@ -67,6 +77,12 @@ g_vfs_job_progress_callback (goffset current_num_bytes,
{
GVfsJobProgress *job = G_VFS_JOB_PROGRESS (user_data);
GVfsJobDBus *dbus_job = G_VFS_JOB_DBUS (job);
+ gint64 current_time = g_get_monotonic_time ();
+
+ if (current_time - job->priv->last_time < RATE_LIMIT_TIME &&
+ current_num_bytes != total_num_bytes)
+ return;
+ job->priv->last_time = current_time;
g_debug ("g_vfs_job_progress_callback %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT "\n", current_num_bytes,
total_num_bytes);
diff --git a/daemon/gvfsjobprogress.h b/daemon/gvfsjobprogress.h
index 0e4d35b..36d2dfc 100644
--- a/daemon/gvfsjobprogress.h
+++ b/daemon/gvfsjobprogress.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
typedef struct _GVfsJobProgress GVfsJobProgress;
typedef struct _GVfsJobProgressClass GVfsJobProgressClass;
+typedef struct _GVfsJobProgressPrivate GVfsJobProgressPrivate;
struct _GVfsJobProgress
{
@@ -46,6 +47,8 @@ struct _GVfsJobProgress
gboolean send_progress;
char *callback_obj_path;
GVfsDBusProgress *progress_proxy;
+
+ GVfsJobProgressPrivate *priv;
};
struct _GVfsJobProgressClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]