[balsa] use res_init to recover faster after reconnecting



commit 0f83eaadb4f334c902a987e508f9eb9299fef8ee
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Jun 30 12:17:05 2009 -0400

    use res_init to recover faster after reconnecting

 configure.in                |   22 ++++++++++++++++++++++
 libbalsa/imap/imap-handle.c |   13 +++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/configure.in b/configure.in
index d5a28b2..f4eb65f 100644
--- a/configure.in
+++ b/configure.in
@@ -330,6 +330,28 @@ PKG_CHECK_MODULES(BALSA_AB, [
    $gnome_extras
 ])
 
+AC_MSG_CHECKING(whether res_init is available)
+AC_LINK_IFELSE(AC_LANG_PROGRAM([#include <resolv.h>
+                               ],
+                               [res_init();]),
+               have_res_init=yes,
+               have_res_init=no)
+if test $have_res_init = no ; then
+    save_LIBS=$LIBS
+    LIBS="$LIBS -lresolv"
+    AC_LINK_IFELSE(AC_LANG_PROGRAM([#include <resolv.h>
+                                   ],
+                                   [res_init();]),
+                   have_res_init=yes)
+fi
+AC_MSG_RESULT([$have_res_init])
+if test $have_res_init = no ; then
+    LIBS=$save_LIBS
+else
+    AC_DEFINE(HAVE_RES_INIT,1,
+              [Defined when res_init is available.])
+fi
+
 dnl ##########################################################################
 dnl Check versions
 dnl ##########################################################################
diff --git a/libbalsa/imap/imap-handle.c b/libbalsa/imap/imap-handle.c
index 88a9d51..9daeb84 100644
--- a/libbalsa/imap/imap-handle.c
+++ b/libbalsa/imap/imap-handle.c
@@ -20,6 +20,7 @@
 
 #define _POSIX_C_SOURCE 199506L
 #define _XOPEN_SOURCE 500
+#define _BSD_SOURCE     1
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -35,6 +36,12 @@
 #include <unistd.h>
 #include <gmime/gmime-utils.h>
 
+#if defined(HAVE_RES_INIT)
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+#endif                          /* defined(HAVE_RES_INIT) */
+
 #if defined(USE_TLS)
 #include <openssl/ssl.h>
 #include <openssl/err.h>
@@ -687,6 +694,12 @@ imap_socket_open(const char* host, const char *def_port)
     hostname = g_strdup(host);
   }
   rc = getaddrinfo(hostname, port, &hints, &res);
+#if defined(HAVE_RES_INIT)
+  if (rc == EAI_AGAIN) {
+    res_init();
+    rc = getaddrinfo(hostname, port, &hints, &res);
+  }
+#endif                          /* defined(HAVE_RES_INIT) */
   g_free(hostname);
   if(rc)
     return -1;



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