[evolution-data-server] Cache the host name to avoid lookups for hostname every now and then.



commit 7e7b0649dcadde3db8cb91920211a67a1a17fd9f
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Mon Jul 13 10:43:20 2009 +0530

    Cache the host name to avoid lookups for hostname every now and then.

 camel/camel-mime-utils.c |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c
index 165d5b8..56bff9f 100644
--- a/camel/camel-mime-utils.c
+++ b/camel/camel-mime-utils.c
@@ -4423,20 +4423,25 @@ camel_header_msgid_generate (void)
 	gchar *msgid;
 	gint retval;
 	struct addrinfo *ai = NULL, hints = { 0 };
+	static char *cached_hostname = NULL;
+
+	if (!cached_hostname) {
+		retval = gethostname (host, sizeof (host));
+		if (retval == 0 && *host) {
+			hints.ai_flags = AI_CANONNAME;
+			ai = camel_getaddrinfo(host, NULL, &hints, NULL);
+			if (ai && ai->ai_canonname)
+				name = ai->ai_canonname;
+			else
+				name = host;
+		} else
+			name = "localhost.localdomain";
 
-	retval = gethostname (host, sizeof (host));
-	if (retval == 0 && *host) {
-		hints.ai_flags = AI_CANONNAME;
-		ai = camel_getaddrinfo(host, NULL, &hints, NULL);
-		if (ai && ai->ai_canonname)
-			name = ai->ai_canonname;
-		else
-			name = host;
-	} else
-		name = "localhost.localdomain";
+		cached_hostname = g_strdup (name);
+	}
 
 	COUNT_LOCK ();
-	msgid = g_strdup_printf ("%d %d %d camel %s", (gint) time (NULL), getpid (), count++, name);
+	msgid = g_strdup_printf ("%d %d %d camel %s", (gint) time (NULL), getpid (), count++, cached_hostname);
 	COUNT_UNLOCK ();
 
 	if (ai)



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