From: Timo Sirainen Date: Wed, 4 Feb 2009 20:36:34 +0000 (-0500) Subject: pop3: If client idles for 10 seconds, commit transaction (allowing mbox to become... X-Git-Tag: 1.2.beta1~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2d45f08ca975c72034bfe2779962b80ac480fe12;p=thirdparty%2Fdovecot%2Fcore.git pop3: If client idles for 10 seconds, commit transaction (allowing mbox to become unlocked). --HG-- branch : HEAD --- diff --git a/src/pop3/client.c b/src/pop3/client.c index 1e18b51f17..ff3599ffa0 100644 --- a/src/pop3/client.c +++ b/src/pop3/client.c @@ -28,12 +28,26 @@ /* 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) { if (client->cmd != NULL) { @@ -162,6 +176,10 @@ struct client *client_create(int fd_in, int fd_out, struct mail_user *user) 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 *client, const char *reason) 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) 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) 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 --git a/src/pop3/client.h b/src/pop3/client.h index b0a26c94d7..e2bcef55b4 100644 --- a/src/pop3/client.h +++ b/src/pop3/client.h @@ -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;