[evolution-data-server/gnome-2-28] Bug #604236 - Slow GPG processing



commit 50507d8f1f0b0b14aff26ca245e15eb31b1f62a3
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jan 5 13:41:00 2010 +0100

    Bug #604236 - Slow GPG processing

 camel/camel-gpg-context.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index ccdcf5d..bfa34b3 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -227,6 +227,7 @@ struct _GpgCtx {
 	guint nopubkey:1;
 	guint nodata:1;
 	guint trust:3;
+	guint processing:1;
 
 	guint diagflushed:1;
 
@@ -285,6 +286,7 @@ gpg_ctx_new (CamelSession *session)
 	gpg->validsig = FALSE;
 	gpg->nopubkey = FALSE;
 	gpg->trust = GPG_TRUST_NONE;
+	gpg->processing = FALSE;
 
 	gpg->istream = NULL;
 	gpg->ostream = NULL;
@@ -886,6 +888,12 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 		/* But we ignore it anyway, we should get other response codes to say why */
 		gpg->nodata = TRUE;
 	} else {
+		if (!strncmp ((gchar *) status, "BEGIN_", 6)) {
+			gpg->processing = TRUE;
+		} else if (!strncmp ((gchar *) status, "END_", 4)) {
+			gpg->processing = FALSE;
+		}
+
 		/* check to see if we are complete */
 		switch (gpg->mode) {
 		case GPG_CTX_MODE_SIGN:
@@ -1023,6 +1031,7 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
 #ifndef G_OS_WIN32
 	GPollFD polls[6];
 	gint status, i, cancel_fd;
+	gboolean read_data = FALSE, wrote_data = FALSE;
 
 	for (i=0;i<6;i++) {
 		polls[i].fd = -1;
@@ -1116,6 +1125,8 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
 		} else {
 			gpg->seen_eof1 = TRUE;
 		}
+
+		read_data = TRUE;
 	}
 
 	if (polls[1].revents & (G_IO_IN|G_IO_HUP)) {
@@ -1189,6 +1200,7 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
 				goto exception;
 
 			d(printf ("wrote %d (out of %d) bytes to gpg's stdin\n", nwritten, nread));
+			wrote_data = TRUE;
 		}
 
 		if (camel_stream_eos (gpg->istream)) {
@@ -1198,11 +1210,11 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
 		}
 	}
 
-	if (gpg->need_id) {
-		/* do not ask more than ten times per second when looking for a pass phrase,
+	if (gpg->need_id && !gpg->processing && !read_data && !wrote_data) {
+		/* do not ask more than hundred times per second when looking for a pass phrase,
 		   in case user has the use-agent set, it'll not use the all CPU when
 		   agent is asking for a pass phrase, instead of us */
-		g_usleep (G_USEC_PER_SEC / 10);
+		g_usleep (G_USEC_PER_SEC / 100);
 	}
 
 	return 0;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]