diff options
author | Florian Bezold <florian.bezold@esrlabs.com> | 2018-02-09 15:32:36 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-02-10 07:45:56 +0000 |
commit | 02a3056af383f4230873d7cd1a76654e1ab19969 (patch) | |
tree | 692d1d29a7a63bb03965e0b1fc469073686c64c8 | |
parent | bfef57ebb708445c55876b8768aad1a0b98cd29d (diff) |
androiddump: Fix non-blocking connect on Windows
Commit 043ed1f6 enabled non-blocking connect on Windows. This seems to
break androiddump on Windows completely, since a successful connection
always returns SOCKET_ERROR on connect, with WSAGetLastError() set to
WSAEWOULDBLOCK.
Apparently, the only way to check for a real connection is to try a
write select on the socket:
https://stackoverflow.com/questions/35370239/timeout-in-connect-function-from-winsock
This fixes androiddump on Windows:
- If ADB server is running, extcap interfaces are listed
- If ADB is not running, there is no noticeable delay in Wireshark
Change-Id: I6bd772215c7b232c8fe8e840cb7ad1d54c7d8860
Reviewed-on: https://code.wireshark.org/review/25715
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | extcap/androiddump.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/extcap/androiddump.c b/extcap/androiddump.c index 15d9d9c2a6..d7c6627ac9 100644 --- a/extcap/androiddump.c +++ b/extcap/androiddump.c @@ -547,6 +547,22 @@ static socket_handle_t adb_connect(const char *server_ip, unsigned short *server while (tries < SOCKET_CONNECT_TIMEOUT_TRIES) { status = connect(sock, (struct sockaddr *) &server, (socklen_t)sizeof(server)); tries += 1; + +#ifdef _WIN32 + if ((status == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK)) { + const struct timeval timeout = { + .tv_sec = 0, + .tv_usec = SOCKET_CONNECT_DELAY_US, + }; + fd_set fdset; + FD_ZERO(&fdset); + FD_SET(sock, &fdset); + if ((select(0, NULL, &fdset, NULL, &timeout) != 0) && (FD_ISSET(sock, &fdset))) { + status = 0; + } + } +#endif + if (status != SOCKET_ERROR) break; g_usleep(SOCKET_CONNECT_DELAY_US); |