diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2013-12-03 21:34:54 +0000 |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-01-23 10:27:45 +0200 |
commit | 44b66a906c302bd1340fe22b0f6d39f7be6f403e (patch) | |
tree | 6c22df31f1d81a613f6c7bcf35991ec51ec19193 | |
parent | 31129df79b1f86ccd8fa1a01936fdfa6bc98e83b (diff) | |
download | gvfs-44b66a906c302bd1340fe22b0f6d39f7be6f403e.tar.gz |
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
-rw-r--r-- | daemon/gvfsjobprogress.c | 16 | ||||
-rw-r--r-- | daemon/gvfsjobprogress.h | 3 |
2 files changed, 19 insertions, 0 deletions
diff --git a/daemon/gvfsjobprogress.c b/daemon/gvfsjobprogress.c index d6395dfb..a9caace7 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 0e4d35b4..36d2dfc8 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 |