Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: tools/android/forwarder2/host_controller.cc

Issue 2385143003: [android] Don't attempt to read a command on failure to start the forwarder. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/android/forwarder2/host_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "tools/android/forwarder2/host_controller.h" 5 #include "tools/android/forwarder2/host_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return; 116 return;
117 } 117 }
118 OnInternalThreadError(); 118 OnInternalThreadError();
119 return; 119 return;
120 } 120 }
121 LOG(INFO) << device_serial_ 121 LOG(INFO) << device_serial_
122 << ": Will send HOST_SERVER_SUCCESS: " 122 << ": Will send HOST_SERVER_SUCCESS: "
123 << host_port_; 123 << host_port_;
124 SendCommand( 124 SendCommand(
125 command::HOST_SERVER_SUCCESS, device_port_, adb_control_socket_.get()); 125 command::HOST_SERVER_SUCCESS, device_port_, adb_control_socket_.get());
126 StartForwarder(std::move(host_server_data_socket)); 126 if (!StartForwarder(std::move(host_server_data_socket))) {
127 OnInternalThreadError();
128 return;
129 }
127 ReadNextCommandSoon(); 130 ReadNextCommandSoon();
128 } 131 }
129 132
130 void HostController::StartForwarder( 133 bool HostController::StartForwarder(
131 std::unique_ptr<Socket> host_server_data_socket) { 134 std::unique_ptr<Socket> host_server_data_socket) {
132 std::unique_ptr<Socket> adb_data_socket(new Socket()); 135 std::unique_ptr<Socket> adb_data_socket(new Socket());
133 if (!adb_data_socket->ConnectTcp("", adb_port_)) { 136 if (!adb_data_socket->ConnectTcp("", adb_port_)) {
134 LOG(ERROR) << device_serial_ 137 LOG(ERROR) << device_serial_
135 << ": Could not connect AdbDataSocket on port: " 138 << ": Could not connect AdbDataSocket on port: "
136 << adb_port_; 139 << adb_port_;
137 OnInternalThreadError(); 140 return false;
138 return;
139 } 141 }
140 // Open the Adb data connection, and send a command with the 142 // Open the Adb data connection, and send a command with the
141 // |device_forward_port| as a way for the device to identify the connection. 143 // |device_forward_port| as a way for the device to identify the connection.
142 SendCommand(command::DATA_CONNECTION, device_port_, adb_data_socket.get()); 144 SendCommand(command::DATA_CONNECTION, device_port_, adb_data_socket.get());
143 145
144 // Check that the device received the new Adb Data Connection. Note that this 146 // Check that the device received the new Adb Data Connection. Note that this
145 // check is done through the |adb_control_socket_| that is handled in the 147 // check is done through the |adb_control_socket_| that is handled in the
146 // DeviceListener thread just after the call to WaitForAdbDataSocket(). 148 // DeviceListener thread just after the call to WaitForAdbDataSocket().
147 if (!ReceivedCommand(command::ADB_DATA_SOCKET_SUCCESS, 149 if (!ReceivedCommand(command::ADB_DATA_SOCKET_SUCCESS,
148 adb_control_socket_.get())) { 150 adb_control_socket_.get())) {
149 LOG(ERROR) << device_serial_ 151 LOG(ERROR) << device_serial_
150 << ": Device could not handle the new Adb Data Connection."; 152 << ": Device could not handle the new Adb Data Connection.";
151 OnInternalThreadError(); 153 return false;
152 return;
153 } 154 }
154 forwarders_manager_.CreateAndStartNewForwarder( 155 forwarders_manager_.CreateAndStartNewForwarder(
155 std::move(host_server_data_socket), std::move(adb_data_socket)); 156 std::move(host_server_data_socket), std::move(adb_data_socket));
157 return true;
156 } 158 }
157 159
158 void HostController::OnInternalThreadError() { 160 void HostController::OnInternalThreadError() {
159 UnmapPortOnDevice(); 161 UnmapPortOnDevice();
160 self_deleter_helper_.MaybeSelfDeleteSoon(); 162 self_deleter_helper_.MaybeSelfDeleteSoon();
161 } 163 }
162 164
163 void HostController::UnmapPortOnDevice() { 165 void HostController::UnmapPortOnDevice() {
164 Socket socket; 166 Socket socket;
165 if (!socket.ConnectTcp("", adb_port_)) { 167 if (!socket.ConnectTcp("", adb_port_)) {
(...skipping 10 matching lines...) Expand all
176 } 178 }
177 if (!ReceivedCommand(command::UNLISTEN_SUCCESS, &socket)) { 179 if (!ReceivedCommand(command::UNLISTEN_SUCCESS, &socket)) {
178 LOG(ERROR) << device_serial_ 180 LOG(ERROR) << device_serial_
179 << ": Unmap command failed for port " 181 << ": Unmap command failed for port "
180 << device_port_; 182 << device_port_;
181 return; 183 return;
182 } 184 }
183 } 185 }
184 186
185 } // namespace forwarder2 187 } // namespace forwarder2
OLDNEW
« no previous file with comments | « tools/android/forwarder2/host_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698