9
9
#include <fcntl.h>
10
10
#include <sys/stat.h>
11
11
12
+ #define NOTIFY_DELAY_MSECS 500
13
+
12
14
struct index_notify_file {
13
15
struct index_notify_file * next ;
14
16
@@ -25,9 +27,8 @@ static void check_timeout(struct index_mailbox *ibox)
25
27
{
26
28
struct index_notify_file * file ;
27
29
struct stat st ;
28
- bool notify ;
30
+ bool notify = FALSE ;
29
31
30
- notify = ibox -> notify_pending ;
31
32
for (file = ibox -> notify_files ; file != NULL ; file = file -> next ) {
32
33
if (stat (file -> path , & st ) == 0 &&
33
34
file -> last_stamp != st .st_mtime ) {
@@ -37,23 +38,25 @@ static void check_timeout(struct index_mailbox *ibox)
37
38
}
38
39
39
40
if (notify ) {
40
- ibox -> notify_last_sent = ioloop_time ;
41
- ibox -> notify_pending = FALSE ;
41
+ if ( ibox -> notify_delay_to != NULL )
42
+ timeout_remove ( & ibox -> notify_delay_to ) ;
42
43
ibox -> box .notify_callback (& ibox -> box , ibox -> box .notify_context );
43
44
}
44
45
}
45
46
47
+ static void notify_delay_callback (struct index_mailbox * ibox )
48
+ {
49
+ ibox -> box .notify_callback (& ibox -> box , ibox -> box .notify_context );
50
+ }
51
+
46
52
static void notify_callback (struct index_mailbox * ibox )
47
53
{
48
54
timeout_reset (ibox -> notify_to );
49
55
50
- /* don't notify more often than once a second */
51
- if (ioloop_time > ibox -> notify_last_sent ) {
52
- ibox -> notify_last_sent = ioloop_time ;
53
- ibox -> notify_pending = FALSE;
54
- ibox -> box .notify_callback (& ibox -> box , ibox -> box .notify_context );
55
- } else {
56
- ibox -> notify_pending = TRUE;
56
+ if (ibox -> notify_delay_to == NULL ) {
57
+ ibox -> notify_delay_to =
58
+ timeout_add (NOTIFY_DELAY_MSECS ,
59
+ notify_delay_callback , ibox );
57
60
}
58
61
}
59
62
@@ -95,9 +98,6 @@ void index_mailbox_check_remove_all(struct index_mailbox *ibox)
95
98
struct index_notify_file * file ;
96
99
struct index_notify_io * aio ;
97
100
98
- /* reset notify stamp */
99
- ibox -> notify_last_sent = 0 ;
100
-
101
101
while (ibox -> notify_files != NULL ) {
102
102
file = ibox -> notify_files ;
103
103
ibox -> notify_files = file -> next ;
@@ -114,6 +114,8 @@ void index_mailbox_check_remove_all(struct index_mailbox *ibox)
114
114
i_free (aio );
115
115
}
116
116
117
+ if (ibox -> notify_delay_to != NULL )
118
+ timeout_remove (& ibox -> notify_delay_to );
117
119
if (ibox -> notify_to != NULL )
118
120
timeout_remove (& ibox -> notify_to );
119
121
}
0 commit comments