]> Pileus Git - ~andy/gtk/commitdiff
Test connection to all given addresses when printing
authorMarek Kasik <mkasik@redhat.com>
Thu, 3 Jun 2010 08:13:17 +0000 (10:13 +0200)
committerMarek Kasik <mkasik@redhat.com>
Thu, 3 Jun 2010 08:13:17 +0000 (10:13 +0200)
Go to the next address given by CUPS if we fail to connect to
previous address (#603637).

modules/printbackends/cups/gtkcupsutils.c
modules/printbackends/cups/gtkcupsutils.h

index cd97f10efd6ec62370d9888bb7f354a45327f0b9..1023da09e6d0ceef4be37ecc6234a97e1c0b8301 100644 (file)
@@ -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)
     {
index ba43f875f7044ec647fbf621298605fe1433a31a..2438b866967c6f514ff1538668facf5372696f96 100644 (file)
@@ -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
 };