OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <errno.h> | 5 #include <errno.h> |
6 #include <signal.h> | 6 #include <signal.h> |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <sys/wait.h> | 8 #include <sys/wait.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 SendMessage( | 127 SendMessage( |
128 !removed_elements ? "ERROR: could not unmap port" : "OK", | 128 !removed_elements ? "ERROR: could not unmap port" : "OK", |
129 client_socket.get()); | 129 client_socket.get()); |
130 return; | 130 return; |
131 } | 131 } |
132 int host_port; | 132 int host_port; |
133 if (!pickle_it.ReadInt(&host_port)) { | 133 if (!pickle_it.ReadInt(&host_port)) { |
134 SendMessage("ERROR: missing host port", client_socket.get()); | 134 SendMessage("ERROR: missing host port", client_socket.get()); |
135 return; | 135 return; |
136 } | 136 } |
137 const std::string controller_key = MakeHostControllerMapKey( | |
138 adb_port, device_port); | |
139 if (controllers_.find(controller_key) != controllers_.end()) { | |
140 // The port is already forwarded. | |
bulach
2013/07/08 14:35:36
nit: maybe expand this a little bit, and add a log
Philippe
2013/07/08 15:47:50
Note that this wasn't unfortunately doing what you
Philippe
2013/07/08 17:00:38
The other patch set I mentioned is a much bigger c
bulach
2013/07/08 17:40:35
sgtm.. would you like to add the LOG just in case,
| |
141 SendMessage(base::StringPrintf("%d:%d", device_port, host_port), | |
142 client_socket.get()); | |
143 return; | |
144 } | |
137 // Create a new host controller. | 145 // Create a new host controller. |
138 scoped_ptr<HostController> host_controller( | 146 scoped_ptr<HostController> host_controller( |
139 new HostController(device_port, "127.0.0.1", host_port, adb_port, | 147 new HostController(device_port, "127.0.0.1", host_port, adb_port, |
140 GetExitNotifierFD())); | 148 GetExitNotifierFD())); |
141 if (!host_controller->Connect()) { | 149 if (!host_controller->Connect()) { |
142 has_failed_ = true; | 150 has_failed_ = true; |
143 SendMessage("ERROR: Connection to device failed.", client_socket.get()); | 151 SendMessage("ERROR: Connection to device failed.", client_socket.get()); |
144 return; | 152 return; |
145 } | 153 } |
146 // Get the current allocated port. | 154 // Get the current allocated port. |
147 device_port = host_controller->device_port(); | 155 device_port = host_controller->device_port(); |
148 LOG(INFO) << "Forwarding device port " << device_port << " to host port " | 156 LOG(INFO) << "Forwarding device port " << device_port << " to host port " |
149 << host_port; | 157 << host_port; |
150 const std::string msg = base::StringPrintf("%d:%d", device_port, host_port); | 158 const std::string msg = base::StringPrintf("%d:%d", device_port, host_port); |
151 if (!SendMessage(msg, client_socket.get())) | 159 if (!SendMessage(msg, client_socket.get())) |
152 return; | 160 return; |
153 host_controller->Start(); | 161 host_controller->Start(); |
154 const std::string controller_key = MakeHostControllerMapKey( | |
155 adb_port, device_port); | |
156 controllers_.insert( | 162 controllers_.insert( |
157 std::make_pair(controller_key, | 163 std::make_pair(controller_key, |
158 linked_ptr<HostController>(host_controller.release()))); | 164 linked_ptr<HostController>(host_controller.release()))); |
159 } | 165 } |
160 | 166 |
161 virtual void OnServerExited() OVERRIDE { | 167 virtual void OnServerExited() OVERRIDE { |
162 for (HostControllerMap::iterator it = controllers_.begin(); | 168 for (HostControllerMap::iterator it = controllers_.begin(); |
163 it != controllers_.end(); ++it) { | 169 it != controllers_.end(); ++it) { |
164 linked_ptr<HostController> host_controller = it->second; | 170 linked_ptr<HostController> host_controller = it->second; |
165 host_controller->Join(); | 171 host_controller->Join(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 | 321 |
316 return client_delegate.has_failed() || daemon_delegate.has_failed(); | 322 return client_delegate.has_failed() || daemon_delegate.has_failed(); |
317 } | 323 } |
318 | 324 |
319 } // namespace | 325 } // namespace |
320 } // namespace forwarder2 | 326 } // namespace forwarder2 |
321 | 327 |
322 int main(int argc, char** argv) { | 328 int main(int argc, char** argv) { |
323 return forwarder2::RunHostForwarder(argc, argv); | 329 return forwarder2::RunHostForwarder(argc, argv); |
324 } | 330 } |
OLD | NEW |