dovecot-2.0-sslstream: mailbox_notify_changes(): Delay sending n...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:55:45 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/e9c8a21e95e4
changeset: 10203:e9c8a21e95e4
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Oct 27 00:22:25 2009 -0400
description:
mailbox_notify_changes(): Delay sending notifications for 500 msecs.
If the notification is done immediately, IDLE may not notice the change
because it's not finished yet.

diffstat:

2 files changed, 18 insertions(+), 17 deletions(-)
src/lib-storage/index/index-mailbox-check.c |   30 ++++++++++++++-------------
src/lib-storage/index/index-storage.h       |    5 +---

diffs (101 lines):

diff -r b0017c5dd411 -r e9c8a21e95e4 src/lib-storage/index/index-mailbox-check.c
--- a/src/lib-storage/index/index-mailbox-check.c	Mon Oct 26 23:46:53 2009 -0400
+++ b/src/lib-storage/index/index-mailbox-check.c	Tue Oct 27 00:22:25 2009 -0400
@@ -8,6 +8,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+
+#define NOTIFY_DELAY_MSECS 500
 
 struct index_notify_file {
 	struct index_notify_file *next;
@@ -25,9 +27,8 @@ static void check_timeout(struct index_m
 {
 	struct index_notify_file *file;
 	struct stat st;
-	bool notify;
+	bool notify = FALSE;
 
-	notify = ibox->notify_pending;
 	for (file = ibox->notify_files; file != NULL; file = file->next) {
 		if (stat(file->path, &st) == 0 &&
 		    file->last_stamp != st.st_mtime) {
@@ -37,23 +38,25 @@ static void check_timeout(struct index_m
 	}
 
 	if (notify) {
-		ibox->notify_last_sent = ioloop_time;
-		ibox->notify_pending = FALSE;
+		if (ibox->notify_delay_to != NULL)
+			timeout_remove(&ibox->notify_delay_to);
 		ibox->box.notify_callback(&ibox->box, ibox->box.notify_context);
 	}
+}
+
+static void notify_delay_callback(struct index_mailbox *ibox)
+{
+	ibox->box.notify_callback(&ibox->box, ibox->box.notify_context);
 }
 
 static void notify_callback(struct index_mailbox *ibox)
 {
 	timeout_reset(ibox->notify_to);
 
-	/* don't notify more often than once a second */
-	if (ioloop_time > ibox->notify_last_sent) {
-		ibox->notify_last_sent = ioloop_time;
-                ibox->notify_pending = FALSE;
-		ibox->box.notify_callback(&ibox->box, ibox->box.notify_context);
-	} else {
-		ibox->notify_pending = TRUE;
+	if (ibox->notify_delay_to == NULL) {
+		ibox->notify_delay_to =
+			timeout_add(NOTIFY_DELAY_MSECS,
+				    notify_delay_callback, ibox);
 	}
 }
 
@@ -95,9 +98,6 @@ void index_mailbox_check_remove_all(stru
 	struct index_notify_file *file;
 	struct index_notify_io *aio;
 
-	/* reset notify stamp */
-	ibox->notify_last_sent = 0;
-
 	while (ibox->notify_files != NULL) {
 		file = ibox->notify_files;
 		ibox->notify_files = file->next;
@@ -114,6 +114,8 @@ void index_mailbox_check_remove_all(stru
 		i_free(aio);
 	}
 
+	if (ibox->notify_delay_to != NULL)
+		timeout_remove(&ibox->notify_delay_to);
 	if (ibox->notify_to != NULL)
 		timeout_remove(&ibox->notify_to);
 }
diff -r b0017c5dd411 -r e9c8a21e95e4 src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h	Mon Oct 26 23:46:53 2009 -0400
+++ b/src/lib-storage/index/index-storage.h	Tue Oct 27 00:22:25 2009 -0400
@@ -43,10 +43,10 @@ struct index_mailbox {
 	struct mail_cache *cache;
 	struct mail_vfuncs *mail_vfuncs;
 
-	struct timeout *notify_to;
+	struct timeout *notify_to, *notify_delay_to;
 	struct index_notify_file *notify_files;
         struct index_notify_io *notify_ios;
-	time_t notify_last_check, notify_last_sent;
+	time_t notify_last_check;
 
 	time_t next_lock_notify; /* temporary */
 	enum mailbox_lock_notify_type last_notify_type;
@@ -62,7 +62,6 @@ struct index_mailbox {
 
 	/* we've discovered there aren't enough permissions to modify mailbox */
 	unsigned int backend_readonly:1;
-	unsigned int notify_pending:1;
 	unsigned int move_to_memory:1;
 };
 


More information about the dovecot-cvs mailing list