aboutsummaryrefslogtreecommitdiffstats
path: root/proxy
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2010-07-30 15:35:00 -0700
committerDavid 'Digit' Turner <digit@android.com>2010-07-30 15:35:00 -0700
commit9b98dbde344781e93e2bdcfa599428cda2fda41d (patch)
tree984065a5cd8d66a99000096fb2018f3ba7988320 /proxy
parent7fd67eba0b961d94a5d6baa8e3c3de37b729f738 (diff)
downloadexternal_qemu-9b98dbde344781e93e2bdcfa599428cda2fda41d.zip
external_qemu-9b98dbde344781e93e2bdcfa599428cda2fda41d.tar.gz
external_qemu-9b98dbde344781e93e2bdcfa599428cda2fda41d.tar.bz2
Better detection of incorrect proxy values when starting the emulator.
Change-Id: I344f06fc16e051359669b8fe9b8dcec0ceca377d
Diffstat (limited to 'proxy')
-rw-r--r--proxy/proxy_common.c47
-rw-r--r--proxy/proxy_common.h12
-rw-r--r--proxy/proxy_http_rewriter.c2
3 files changed, 60 insertions, 1 deletions
diff --git a/proxy/proxy_common.c b/proxy/proxy_common.c
index 7794a62..3a04eb8 100644
--- a/proxy/proxy_common.c
+++ b/proxy/proxy_common.c
@@ -17,6 +17,7 @@
#include <errno.h>
#include "android/utils/misc.h"
#include "android/utils/system.h"
+#include "iolooper.h"
#include <stdlib.h>
int proxy_log = 0;
@@ -530,3 +531,49 @@ Exit:
}
+int
+proxy_check_connection( const char* proxyname,
+ int proxyname_len,
+ int proxyport,
+ int timeout_ms )
+{
+ SockAddress addr;
+ int sock;
+ IoLooper* looper;
+ int ret;
+
+ if (proxy_resolve_server(&addr, proxyname, proxyname_len, proxyport) < 0) {
+ return -1;
+ }
+
+ sock = socket_create(addr.family, SOCKET_STREAM);
+ if (sock < 0) {
+ PROXY_LOG("%s: Could not create socket !?: %s", __FUNCTION__, errno_str);
+ return -1;
+ }
+
+ socket_set_nonblock(sock);
+
+ /* An immediate connection is very unlikely, but deal with it, just in case */
+ if (socket_connect(sock, &addr) == 0) {
+ PROXY_LOG("%s: Immediate connection to %.*s:%d: %s !",
+ __FUNCTION__, proxyname_len, proxyname, proxyport);
+ socket_close(sock);
+ return 0;
+ }
+
+ /* Ok, create an IoLooper object to wait for the connection */
+ looper = iolooper_new();
+ iolooper_add_write(looper, sock);
+
+ ret = iolooper_wait(looper, timeout_ms);
+
+ iolooper_free(looper);
+ socket_close(sock);
+
+ if (ret == 0) {
+ errno = ETIMEDOUT;
+ ret = -1;
+ }
+ return ret;
+}
diff --git a/proxy/proxy_common.h b/proxy/proxy_common.h
index 78eddd8..5c5789f 100644
--- a/proxy/proxy_common.h
+++ b/proxy/proxy_common.h
@@ -85,4 +85,16 @@ extern void proxy_manager_poll( fd_set* read_fds,
fd_set* write_fds,
fd_set* err_fds );
+/* this function checks that one can connect to a given proxy. It will simply try to connect()
+ * to it, for a specified timeout, in milliseconds, then close the connection.
+ *
+ * returns 0 in case of success, and -1 in case of error. errno will be set to ETIMEDOUT in
+ * case of timeout, or ECONNREFUSED if the connection is refused.
+ */
+
+extern int proxy_check_connection( const char* proxyname,
+ int proxyname_len,
+ int proxyport,
+ int timeout_ms );
+
#endif /* END */
diff --git a/proxy/proxy_http_rewriter.c b/proxy/proxy_http_rewriter.c
index 7645ecc..af3f5e7 100644
--- a/proxy/proxy_http_rewriter.c
+++ b/proxy/proxy_http_rewriter.c
@@ -1121,7 +1121,7 @@ http_rewriter_connect( HttpService* service,
RewriteConnection* conn;
int s;
- s = socket_create_inet( SOCKET_STREAM );
+ s = socket_create(address->family, SOCKET_STREAM );
if (s < 0)
return NULL;