summaryrefslogtreecommitdiff
path: root/adb_client.cpp
diff options
context:
space:
mode:
authorSpencer Low <CompareAndSwap@gmail.com>2015-07-30 23:07:55 -0700
committerSpencer Low <CompareAndSwap@gmail.com>2015-07-30 23:07:55 -0700
commitc4841c6eb75e2a78bfacc78cef9977066630ef81 (patch)
tree7dfddab77e98b5fa205a0aed70ff8c6d0d5285e2 /adb_client.cpp
parentcc4634cbd4dd7d9855c56240341a316bfc5c1c70 (diff)
downloadadb-c4841c6eb75e2a78bfacc78cef9977066630ef81.tar.gz
adb: win32: initial IPv6 support and improved Winsock error reporting
Call getaddrinfo() for connecting to IPv6 destinations. Winsock APIs do not set errno. WSAGetLastError() returns Winsock errors that are more numerous than BSD sockets, so it really doesn't make sense to map those to BSD socket errors. Plus, even if we did that, the Windows C Runtime (that mingw binaries use) has a strerror() that does not recognize BSD socket error codes. The solution is to wrap the various libcutils socket_* APIs with sysdeps.h network_* APIs. For POSIX, the network_* APIs just call strerror(). For Windows, they call SystemErrorCodeToString() (adapted from Chromium). Also in this change: - Various other code was modified to return errors in a std::string* argument, to be able to surface the error string to the end-user. - Improved error checking and use of D() to log Winsock errors for improved debuggability. - For sysdeps_win32.cpp, added unique_fh class that works like std::unique_ptr, for calling _fh_close(). - Fix win32 adb_socketpair() setting of errno in error case. - Improve _socket_set_errno() D() logging to reduce confusion. Map a few extra error codes. - Move adb_shutdown() lower in sysdeps_win32.cpp so it can call _socket_set_errno(). - Move network_connect() from adb_utils.cpp to sysdeps.h. - Merge socket_loopback_server() and socket_inaddr_any_server() into _network_server() since most of the code was identical. Change-Id: I945f36870f320578b3a11ba093852ba6f7b93400 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
Diffstat (limited to 'adb_client.cpp')
-rw-r--r--adb_client.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/adb_client.cpp b/adb_client.cpp
index 418662c..6d75966 100644
--- a/adb_client.cpp
+++ b/adb_client.cpp
@@ -153,8 +153,8 @@ int _adb_connect(const std::string& service, std::string* error) {
}
int fd;
+ std::string reason;
if (__adb_server_name) {
- std::string reason;
fd = network_connect(__adb_server_name, __adb_server_port, SOCK_STREAM, 0, &reason);
if (fd == -1) {
*error = android::base::StringPrintf("can't connect to %s:%d: %s",
@@ -163,9 +163,10 @@ int _adb_connect(const std::string& service, std::string* error) {
return -2;
}
} else {
- fd = socket_loopback_client(__adb_server_port, SOCK_STREAM);
+ fd = network_loopback_client(__adb_server_port, SOCK_STREAM, &reason);
if (fd == -1) {
- *error = perror_str("cannot connect to daemon");
+ *error = android::base::StringPrintf("cannot connect to daemon: %s",
+ reason.c_str());
return -2;
}
}