Better detection of incorrect proxy values when starting the emulator.

Change-Id: I344f06fc16e051359669b8fe9b8dcec0ceca377d
diff --git a/android/qemu-setup.c b/android/qemu-setup.c
index 4f05c24..9a41c4d 100644
--- a/android/qemu-setup.c
+++ b/android/qemu-setup.c
@@ -422,19 +422,25 @@
         proxy_name_len = p - env;
         proxy_port     = atoi(p+1);
 
-        /* handle the rare case where the proxy name is omitted, e.g. "http://:8080" */
-        if (proxy_name_len == 0) {
-            proxy_name = "localhost";
-            proxy_name_len = strlen(proxy_name);
-        }
-
         D( "setting up http proxy:  server=%.*s port=%d",
                 proxy_name_len, proxy_name, proxy_port );
 
+        /* Check that we can connect to the proxy in the next second.
+         * If not, the proxy setting is probably garbage !!
+         */
+        if ( proxy_check_connection( proxy_name, proxy_name_len, proxy_port, 1000 ) < 0) {
+            dprint("Could not connect to proxy at %.*s:%d: %s !",
+                   proxy_name_len, proxy_name, proxy_port, errno_str);
+            dprint("Proxy will be ignored !");
+            break;
+        }
+
         if ( proxy_http_setup( proxy_name, proxy_name_len, proxy_port,
                                option - option_tab, option_tab ) < 0 )
         {
-            dprint( "http proxy setup failed, check your $http_proxy variable");
+            dprint( "Http proxy setup failed for '%.*s:%d': %s",
+                    proxy_name_len, proxy_name, proxy_port, errno_str);
+            dprint( "Proxy will be ignored !");
         }
     }
     while (0);