Report getaddrinfo failures correctly.
Also move us off the "convenience" function because you can't get useful
error reporting from it.
Change-Id: I5fcc6a6d762f5f60906980a7835f01a35045be65
diff --git a/adb/adb_utils.cpp b/adb/adb_utils.cpp
index e2af045..3846c21 100644
--- a/adb/adb_utils.cpp
+++ b/adb/adb_utils.cpp
@@ -18,6 +18,7 @@
#include "adb_utils.h"
+#include <netdb.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -28,6 +29,7 @@
#include <base/logging.h>
#include <base/stringprintf.h>
#include <base/strings.h>
+#include <cutils/sockets.h>
#include "adb_trace.h"
#include "sysdeps.h"
@@ -158,3 +160,18 @@
<< " (" << *canonical_address << ")";
return true;
}
+
+int network_connect(const std::string& host, int port, int type, int timeout, std::string* error) {
+ int getaddrinfo_error = 0;
+ int fd = socket_network_client_timeout(host.c_str(), port, type, timeout, &getaddrinfo_error);
+ if (fd != -1) {
+ return fd;
+ }
+ if (getaddrinfo_error != 0) {
+ // TODO: not thread safe on Win32.
+ *error = gai_strerror(getaddrinfo_error);
+ } else {
+ *error = strerror(errno);
+ }
+ return -1;
+}