[dovecot-cvs]
dovecot/src/lib-storage/index index-mailbox-check.c,1.4,1.5
index-storage.h,1.47,1.48 index-sync.c,1.26,1.27
cras at procontrol.fi
cras at procontrol.fi
Sun Aug 24 16:45:36 EEST 2003
Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv7906/src/lib-storage/index
Modified Files:
index-mailbox-check.c index-storage.h index-sync.c
Log Message:
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Index: index-mailbox-check.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mailbox-check.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- index-mailbox-check.c 14 Feb 2003 10:46:44 -0000 1.4
+++ index-mailbox-check.c 24 Aug 2003 12:45:33 -0000 1.5
@@ -12,7 +12,7 @@
struct index_mailbox *ibox = context;
struct index_autosync_file *file;
struct stat st;
- int synced, sync_expunges;
+ int sync;
/* check changes only when we can also notify of new mail */
if ((unsigned int) (ioloop_time - ibox->sync_last_check) <
@@ -21,29 +21,61 @@
ibox->sync_last_check = ioloop_time;
- synced = FALSE;
- sync_expunges = ibox->autosync_type != MAILBOX_SYNC_NO_EXPUNGES;
-
+ sync = ibox->autosync_pending;
for (file = ibox->autosync_files; file != NULL; file = file->next) {
if (stat(file->path, &st) == 0 &&
- file->last_stamp != st.st_mtime) {
+ file->last_stamp != st.st_mtime)
file->last_stamp = st.st_mtime;
- if (!synced) {
- ibox->box.sync(&ibox->box, sync_expunges);
- synced = TRUE;
- }
- }
+ }
+
+ if (sync) {
+ ibox->box.sync(&ibox->box, ibox->autosync_flags);
+ ibox->autosync_pending = FALSE;
}
}
-void index_mailbox_check_add(struct index_mailbox *ibox, const char *path)
+static void notify_callback(void *context)
+{
+ struct index_mailbox *ibox = context;
+
+ if ((unsigned int) (ioloop_time - ibox->sync_last_check) >=
+ ibox->min_newmail_notify_interval) {
+ ibox->sync_last_check = ioloop_time;
+ ibox->box.sync(&ibox->box, ibox->autosync_flags);
+ ibox->autosync_pending = FALSE;
+ } else {
+ ibox->autosync_pending = TRUE;
+ }
+}
+
+void index_mailbox_check_add(struct index_mailbox *ibox,
+ const char *path, int dir)
{
struct index_autosync_file *file;
struct stat st;
+ struct io *io;
+ struct index_autosync_io *aio;
+ int fd;
+
+ fd = open(path, O_RDONLY);
+ if (fd >= 0) {
+ io = io_add(fd, dir ? IO_DIR_NOTIFY : IO_FILE_NOTIFY,
+ notify_callback, ibox);
+ if (io != NULL) {
+ aio = i_new(struct index_autosync_io, 1);
+ aio->io = io;
+ aio->fd = fd;
+ aio->next = ibox->autosync_ios;
+ ibox->autosync_ios = aio;
+ }
+ }
file = i_new(struct index_autosync_file, 1);
file->path = i_strdup(path);
- file->last_stamp = stat(path, &st) < 0 ? 0 : st.st_mtime;
+ if (fd < 0)
+ file->last_stamp = stat(path, &st) < 0 ? 0 : st.st_mtime;
+ else
+ file->last_stamp = fstat(fd, &st) < 0 ? 0 : st.st_mtime;
file->next = ibox->autosync_files;
ibox->autosync_files = file;
@@ -55,6 +87,7 @@
void index_mailbox_check_remove_all(struct index_mailbox *ibox)
{
struct index_autosync_file *file;
+ struct index_autosync_io *aio;
while (ibox->autosync_files != NULL) {
file = ibox->autosync_files;
@@ -62,6 +95,16 @@
i_free(file->path);
i_free(file);
+ }
+
+ while (ibox->autosync_ios != NULL) {
+ aio = ibox->autosync_ios;
+ ibox->autosync_ios = aio->next;
+
+ io_remove(aio->io);
+ if (close(aio->fd) < 0)
+ i_error("close(autosync_io) failed: %m");
+ i_free(aio);
}
if (ibox->autosync_to != NULL) {
Index: index-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- index-storage.h 6 Aug 2003 20:15:33 -0000 1.47
+++ index-storage.h 24 Aug 2003 12:45:33 -0000 1.48
@@ -12,6 +12,12 @@
time_t last_stamp;
};
+struct index_autosync_io {
+ struct index_autosync_io *next;
+ struct io *io;
+ int fd;
+};
+
struct index_mailbox {
struct mailbox box;
@@ -24,8 +30,9 @@
struct mail_cache_transaction_ctx *trans_ctx;
struct timeout *autosync_to;
- struct index_autosync_file *autosync_files;
- enum mailbox_sync_type autosync_type;
+ struct index_autosync_file *autosync_files;
+ struct index_autosync_io *autosync_ios;
+ enum mailbox_sync_flags autosync_flags;
time_t sync_last_check;
unsigned int min_newmail_notify_interval;
@@ -39,6 +46,7 @@
unsigned int inconsistent:1;
unsigned int sent_diskspace_warning:1;
unsigned int sent_readonly_flags_warning:1;
+ unsigned int autosync_pending:1;
};
int mail_storage_set_index_error(struct index_mailbox *ibox);
@@ -76,7 +84,8 @@
unsigned int index_storage_get_recent_count(struct mail_index *index);
-void index_mailbox_check_add(struct index_mailbox *ibox, const char *path);
+void index_mailbox_check_add(struct index_mailbox *ibox,
+ const char *path, int dir);
void index_mailbox_check_remove_all(struct index_mailbox *ibox);
/* mailbox methods: */
@@ -86,7 +95,7 @@
int index_storage_get_status(struct mailbox *box,
enum mailbox_status_items items,
struct mailbox_status *status);
-int index_storage_sync(struct mailbox *box, enum mail_sync_flags flags);
+int index_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags);
struct mail_fetch_context *
index_storage_fetch_init(struct mailbox *box,
Index: index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-sync.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- index-sync.c 23 Jul 2003 01:44:16 -0000 1.26
+++ index-sync.c 24 Aug 2003 12:45:33 -0000 1.27
@@ -213,12 +213,12 @@
return TRUE;
}
-int index_storage_sync(struct mailbox *box, enum mail_sync_flags flags)
+int index_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags)
{
struct index_mailbox *ibox = (struct index_mailbox *) box;
int ret;
- if ((flags & MAIL_SYNC_FLAG_FAST) == 0 ||
+ if ((flags & MAILBOX_SYNC_FAST) == 0 ||
ibox->sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= ioloop_time) {
ibox->sync_last_check = ioloop_time;
@@ -235,7 +235,7 @@
/* FIXME: we could sync flags always, but expunges in the middle
could make it a bit more difficult and slower */
- if ((flags & MAIL_SYNC_FLAG_NO_EXPUNGES) == 0 ||
+ if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) == 0 ||
mail_modifylog_get_expunge_count(ibox->index->modifylog) == 0)
ret = index_storage_sync_modifylog(ibox, FALSE);
else
More information about the dovecot-cvs
mailing list