[gtk+] Test connection to all given addresses when printing



commit f8ac1231923fe77eb243fe2333e83b03c29c8868
Author: Marek Kasik <mkasik redhat com>
Date:   Thu Jun 3 10:13:17 2010 +0200

    Test connection to all given addresses when printing
    
    Go to the next address given by CUPS if we fail to connect to
    previous address (#603637).

 modules/printbackends/cups/gtkcupsutils.c |   18 ++++++++++++++++--
 modules/printbackends/cups/gtkcupsutils.h |    1 +
 2 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/modules/printbackends/cups/gtkcupsutils.c b/modules/printbackends/cups/gtkcupsutils.c
index cd97f10..1023da0 100644
--- a/modules/printbackends/cups/gtkcupsutils.c
+++ b/modules/printbackends/cups/gtkcupsutils.c
@@ -1502,6 +1502,7 @@ gtk_cups_connection_test_new (const char *server)
 
   result->socket = -1;
   result->current_addr = NULL;
+  result->last_wrong_addr = NULL;
   result->at_init = GTK_CUPS_CONNECTION_NOT_AVAILABLE;
 
   result->at_init = gtk_cups_connection_test_get_state (result);
@@ -1540,7 +1541,14 @@ gtk_cups_connection_test_get_state (GtkCupsConnectionTest *test)
     {
       if (test->socket == -1)
         {
-          iter = test->addrlist;
+          if (test->last_wrong_addr != NULL && test->last_wrong_addr->next != NULL)
+            iter = test->last_wrong_addr->next;
+          else
+            {
+              test->last_wrong_addr = NULL;
+              iter = test->addrlist;
+            }
+
           while (iter)
             {
               test->socket = socket (iter->addr.addr.sa_family,
@@ -1584,7 +1592,12 @@ gtk_cups_connection_test_get_state (GtkCupsConnectionTest *test)
               if (error_code == EALREADY || error_code == EINPROGRESS)
                 result = GTK_CUPS_CONNECTION_IN_PROGRESS;
               else
-                result = GTK_CUPS_CONNECTION_NOT_AVAILABLE;
+                {
+                  close (test->socket);
+                  test->socket = -1;
+                  test->last_wrong_addr = test->current_addr;
+                  result = GTK_CUPS_CONNECTION_NOT_AVAILABLE;
+                }
             }
          }
 
@@ -1605,6 +1618,7 @@ gtk_cups_connection_test_free (GtkCupsConnectionTest *test)
 
 #ifdef HAVE_CUPS_API_1_2
   test->current_addr = NULL;
+  test->last_wrong_addr = NULL;
   httpAddrFreeList (test->addrlist);
   if (test->socket != -1)
     {
diff --git a/modules/printbackends/cups/gtkcupsutils.h b/modules/printbackends/cups/gtkcupsutils.h
index ba43f87..2438b86 100644
--- a/modules/printbackends/cups/gtkcupsutils.h
+++ b/modules/printbackends/cups/gtkcupsutils.h
@@ -111,6 +111,7 @@ struct _GtkCupsConnectionTest
   GtkCupsConnectionState at_init;
   http_addrlist_t       *addrlist;
   http_addrlist_t       *current_addr;
+  http_addrlist_t       *last_wrong_addr;
   gint                   socket;
 #endif
 };



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