| 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 "tools/android/forwarder2/daemon.h" | 5 #include "tools/android/forwarder2/daemon.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <sys/file.h> | 10 #include <sys/file.h> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS)); | 49 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool RunServerAcceptLoop(const std::string& welcome_message, | 52 bool RunServerAcceptLoop(const std::string& welcome_message, |
| 53 Socket* server_socket, | 53 Socket* server_socket, |
| 54 Daemon::ServerDelegate* server_delegate) { | 54 Daemon::ServerDelegate* server_delegate) { |
| 55 bool failed = false; | 55 bool failed = false; |
| 56 for (;;) { | 56 for (;;) { |
| 57 scoped_ptr<Socket> client_socket(new Socket()); | 57 scoped_ptr<Socket> client_socket(new Socket()); |
| 58 if (!server_socket->Accept(client_socket.get())) { | 58 if (!server_socket->Accept(client_socket.get())) { |
| 59 if (server_socket->exited()) | 59 if (server_socket->DidReceiveEvent()) |
| 60 break; | 60 break; |
| 61 PError("Accept()"); | 61 PError("Accept()"); |
| 62 failed = true; | 62 failed = true; |
| 63 break; | 63 break; |
| 64 } | 64 } |
| 65 if (!client_socket->Write(welcome_message.c_str(), | 65 if (!client_socket->Write(welcome_message.c_str(), |
| 66 welcome_message.length() + 1)) { | 66 welcome_message.length() + 1)) { |
| 67 PError("Write()"); | 67 PError("Write()"); |
| 68 failed = true; | 68 failed = true; |
| 69 continue; | 69 continue; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 scoped_ptr<Socket> client_socket = ConnectToUnixDomainSocket( | 200 scoped_ptr<Socket> client_socket = ConnectToUnixDomainSocket( |
| 201 identifier_, kSingleTry, kNoIdleTime, identifier_); | 201 identifier_, kSingleTry, kNoIdleTime, identifier_); |
| 202 if (client_socket.get()) { | 202 if (client_socket.get()) { |
| 203 // The daemon was spawned by a concurrent process. | 203 // The daemon was spawned by a concurrent process. |
| 204 exit(0); | 204 exit(0); |
| 205 } | 205 } |
| 206 PError("bind()"); | 206 PError("bind()"); |
| 207 exit(1); | 207 exit(1); |
| 208 } | 208 } |
| 209 server_delegate_->Init(); | 209 server_delegate_->Init(); |
| 210 command_socket.set_exit_notifier_fd(get_exit_fd_callback_()); | 210 command_socket.AddEventFd(get_exit_fd_callback_()); |
| 211 exit(!RunServerAcceptLoop(identifier_, &command_socket, | 211 exit(!RunServerAcceptLoop(identifier_, &command_socket, |
| 212 server_delegate_)); | 212 server_delegate_)); |
| 213 } | 213 } |
| 214 default: | 214 default: |
| 215 break; | 215 break; |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 // Parent. | 218 // Parent. |
| 219 // Install the custom SIGCHLD handler. | 219 // Install the custom SIGCHLD handler. |
| 220 sigset_t blocked_signals_set; | 220 sigset_t blocked_signals_set; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 return true; | 278 return true; |
| 279 } | 279 } |
| 280 usleep(kIdleTimeMSec * 1000); | 280 usleep(kIdleTimeMSec * 1000); |
| 281 } | 281 } |
| 282 LOG(ERROR) << "Timed out while killing daemon. " | 282 LOG(ERROR) << "Timed out while killing daemon. " |
| 283 "It might still be tearing down."; | 283 "It might still be tearing down."; |
| 284 return false; | 284 return false; |
| 285 } | 285 } |
| 286 | 286 |
| 287 } // namespace forwarder2 | 287 } // namespace forwarder2 |
| OLD | NEW |