| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 class ServerDelegate : public Daemon::ServerDelegate { | 307 class ServerDelegate : public Daemon::ServerDelegate { |
| 308 public: | 308 public: |
| 309 ServerDelegate(const std::string& adb_path) | 309 ServerDelegate(const std::string& adb_path) |
| 310 : adb_path_(adb_path), has_failed_(false) {} | 310 : adb_path_(adb_path), has_failed_(false) {} |
| 311 | 311 |
| 312 bool has_failed() const { | 312 bool has_failed() const { |
| 313 return has_failed_ || controllers_manager_.has_failed(); | 313 return has_failed_ || controllers_manager_.has_failed(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 // Daemon::ServerDelegate: | 316 // Daemon::ServerDelegate: |
| 317 virtual void Init() override { | 317 void Init() override { |
| 318 LOG(INFO) << "Starting host process daemon (pid=" << getpid() << ")"; | 318 LOG(INFO) << "Starting host process daemon (pid=" << getpid() << ")"; |
| 319 DCHECK(!g_notifier); | 319 DCHECK(!g_notifier); |
| 320 g_notifier = new PipeNotifier(); | 320 g_notifier = new PipeNotifier(); |
| 321 signal(SIGTERM, KillHandler); | 321 signal(SIGTERM, KillHandler); |
| 322 signal(SIGINT, KillHandler); | 322 signal(SIGINT, KillHandler); |
| 323 } | 323 } |
| 324 | 324 |
| 325 virtual void OnClientConnected(scoped_ptr<Socket> client_socket) override { | 325 void OnClientConnected(scoped_ptr<Socket> client_socket) override { |
| 326 char buf[kBufSize]; | 326 char buf[kBufSize]; |
| 327 const int bytes_read = client_socket->Read(buf, sizeof(buf)); | 327 const int bytes_read = client_socket->Read(buf, sizeof(buf)); |
| 328 if (bytes_read <= 0) { | 328 if (bytes_read <= 0) { |
| 329 if (client_socket->DidReceiveEvent()) | 329 if (client_socket->DidReceiveEvent()) |
| 330 return; | 330 return; |
| 331 PError("Read()"); | 331 PError("Read()"); |
| 332 has_failed_ = true; | 332 has_failed_ = true; |
| 333 return; | 333 return; |
| 334 } | 334 } |
| 335 const Pickle command_pickle(buf, bytes_read); | 335 const Pickle command_pickle(buf, bytes_read); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 359 class ClientDelegate : public Daemon::ClientDelegate { | 359 class ClientDelegate : public Daemon::ClientDelegate { |
| 360 public: | 360 public: |
| 361 ClientDelegate(const Pickle& command_pickle) | 361 ClientDelegate(const Pickle& command_pickle) |
| 362 : command_pickle_(command_pickle), | 362 : command_pickle_(command_pickle), |
| 363 has_failed_(false) { | 363 has_failed_(false) { |
| 364 } | 364 } |
| 365 | 365 |
| 366 bool has_failed() const { return has_failed_; } | 366 bool has_failed() const { return has_failed_; } |
| 367 | 367 |
| 368 // Daemon::ClientDelegate: | 368 // Daemon::ClientDelegate: |
| 369 virtual void OnDaemonReady(Socket* daemon_socket) override { | 369 void OnDaemonReady(Socket* daemon_socket) override { |
| 370 // Send the forward command to the daemon. | 370 // Send the forward command to the daemon. |
| 371 CHECK_EQ(static_cast<long>(command_pickle_.size()), | 371 CHECK_EQ(static_cast<long>(command_pickle_.size()), |
| 372 daemon_socket->WriteNumBytes(command_pickle_.data(), | 372 daemon_socket->WriteNumBytes(command_pickle_.data(), |
| 373 command_pickle_.size())); | 373 command_pickle_.size())); |
| 374 char buf[kBufSize]; | 374 char buf[kBufSize]; |
| 375 const int bytes_read = daemon_socket->Read( | 375 const int bytes_read = daemon_socket->Read( |
| 376 buf, sizeof(buf) - 1 /* leave space for null terminator */); | 376 buf, sizeof(buf) - 1 /* leave space for null terminator */); |
| 377 CHECK_GT(bytes_read, 0); | 377 CHECK_GT(bytes_read, 0); |
| 378 DCHECK(static_cast<size_t>(bytes_read) < sizeof(buf)); | 378 DCHECK(static_cast<size_t>(bytes_read) < sizeof(buf)); |
| 379 buf[bytes_read] = 0; | 379 buf[bytes_read] = 0; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 | 461 |
| 462 return client_delegate.has_failed() || daemon_delegate.has_failed(); | 462 return client_delegate.has_failed() || daemon_delegate.has_failed(); |
| 463 } | 463 } |
| 464 | 464 |
| 465 } // namespace | 465 } // namespace |
| 466 } // namespace forwarder2 | 466 } // namespace forwarder2 |
| 467 | 467 |
| 468 int main(int argc, char** argv) { | 468 int main(int argc, char** argv) { |
| 469 return forwarder2::RunHostForwarder(argc, argv); | 469 return forwarder2::RunHostForwarder(argc, argv); |
| 470 } | 470 } |
| OLD | NEW |