dovecot-1.2: pop3: If client idles for 10 seconds, commit transa...

dovecot at dovecot.org dovecot at dovecot.org
Wed Feb 4 22:36:40 EET 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/ea9a186d64f9
changeset: 8718:ea9a186d64f9
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Feb 04 15:36:34 2009 -0500
description:
pop3: If client idles for 10 seconds, commit transaction (allowing mbox to become unlocked).

diffstat:

2 files changed, 25 insertions(+), 1 deletion(-)
src/pop3/client.c |   24 ++++++++++++++++++++++++
src/pop3/client.h |    2 +-

diffs (79 lines):

diff -r 6f29380ba3a0 -r ea9a186d64f9 src/pop3/client.c
--- a/src/pop3/client.c	Wed Feb 04 15:28:31 2009 -0500
+++ b/src/pop3/client.c	Wed Feb 04 15:36:34 2009 -0500
@@ -28,11 +28,25 @@
 
 /* Disconnect client after idling this many milliseconds */
 #define CLIENT_IDLE_TIMEOUT_MSECS (10*60*1000)
+/* If client starts idling for this many milliseconds, commit the current
+   transaction. This allows the mailbox to become unlocked. */
+#define CLIENT_COMMIT_TIMEOUT_MSECS (10*1000)
 
 static struct client *my_client; /* we don't need more than one currently */
 
 static void client_input(struct client *client);
 static int client_output(struct client *client);
+
+static void client_commit_timeout(struct client *client)
+{
+	if (client->cmd != NULL) {
+		/* Can't commit while commands are running */
+		return;
+	}
+
+	(void)mailbox_transaction_commit(&client->trans);
+	client->trans = mailbox_transaction_begin(client->mailbox, 0);
+}
 
 static void client_idle_timeout(struct client *client)
 {
@@ -162,6 +176,10 @@ struct client *client_create(int fd_in, 
         client->last_input = ioloop_time;
 	client->to_idle = timeout_add(CLIENT_IDLE_TIMEOUT_MSECS,
 				      client_idle_timeout, client);
+	if (!lock_session) {
+		client->to_commit = timeout_add(CLIENT_COMMIT_TIMEOUT_MSECS,
+						client_commit_timeout, client);
+	}
 
 	client->user = user;
 
@@ -284,6 +302,8 @@ void client_destroy(struct client *clien
 	if (client->io != NULL)
 		io_remove(&client->io);
 	timeout_remove(&client->to_idle);
+	if (client->to_commit != NULL)
+		timeout_remove(&client->to_commit);
 
 	i_stream_destroy(&client->input);
 	o_stream_destroy(&client->output);
@@ -429,6 +449,8 @@ static void client_input(struct client *
 	client->waiting_input = FALSE;
 	client->last_input = ioloop_time;
 	timeout_reset(client->to_idle);
+	if (client->to_commit != NULL)
+		timeout_reset(client->to_commit);
 
 	switch (i_stream_read(client->input)) {
 	case -1:
@@ -456,6 +478,8 @@ static int client_output(struct client *
 
 	client->last_output = ioloop_time;
 	timeout_reset(client->to_idle);
+	if (client->to_commit != NULL)
+		timeout_reset(client->to_commit);
 
 	if (client->cmd != NULL) {
 		o_stream_cork(client->output);
diff -r 6f29380ba3a0 -r ea9a186d64f9 src/pop3/client.h
--- a/src/pop3/client.h	Wed Feb 04 15:28:31 2009 -0500
+++ b/src/pop3/client.h	Wed Feb 04 15:36:34 2009 -0500
@@ -14,7 +14,7 @@ struct client {
 	struct io *io;
 	struct istream *input;
 	struct ostream *output;
-	struct timeout *to_idle;
+	struct timeout *to_idle, *to_commit;
 
 	command_func_t *cmd;
 	void *cmd_context;


More information about the dovecot-cvs mailing list