summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-24 18:47:07 +0000
committerjknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-24 18:47:07 +0000
commit51b97d1c0b787cb4b403d42880a63370b048916c (patch)
tree84fc0ee58deecb0adca851102d0b90c4f6e69fd1 /tools
parent259084b646d4add5ded8a786ec7f7c23e94b9b57 (diff)
downloadchromium_src-51b97d1c0b787cb4b403d42880a63370b048916c.zip
chromium_src-51b97d1c0b787cb4b403d42880a63370b048916c.tar.gz
chromium_src-51b97d1c0b787cb4b403d42880a63370b048916c.tar.bz2
Allow dynamic device-port allocation for Android port forwarder.
Allow one to specify 0 for the device port to allow the a port on the device to be dynamically allocated. This should help reduce flakiness on the bots due to trying to forward a port to the host that is actually in use already. BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10452010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/android/forwarder/forwarder.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/tools/android/forwarder/forwarder.cc b/tools/android/forwarder/forwarder.cc
index e19fe65..e8cee3fb 100644
--- a/tools/android/forwarder/forwarder.cc
+++ b/tools/android/forwarder/forwarder.cc
@@ -299,7 +299,7 @@ void* Server::ServerThread(void* arg) {
bool Server::InitSocket(const char* arg) {
char* endptr;
int local_port = static_cast<int>(strtol(arg, &endptr, 10));
- if (local_port <= 0)
+ if (local_port < 0)
return false;
if (*endptr != ':') {
@@ -333,6 +333,18 @@ bool Server::InitSocket(const char* arg) {
return false;
}
+ if (local_port == 0) {
+ socklen_t addrlen = sizeof(addr);
+ if (getsockname(socket_, reinterpret_cast<sockaddr*>(&addr), &addrlen)
+ != 0) {
+ perror("get listen address");
+ HANDLE_EINTR(close(socket_));
+ socket_ = -1;
+ return false;
+ }
+ local_port = ntohs(addr.sin_port);
+ }
+
printf("Forwarding device port %d to host %s\n", local_port, forward_to_);
return true;
}
@@ -364,7 +376,8 @@ int main(int argc, char** argv) {
argv[0],
"<Device port>[:<Forward to port>:<Forward to address>] ...",
" <Forward to port> default is <Device port>\n"
- " <Forward to address> default is 127.0.0.1\n");
+ " <Forward to address> default is 127.0.0.1\n"
+ "If <Device port> is 0, a port will by dynamically allocated.\n");
return 0;
}