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 <string.h> | 10 #include <string.h> |
11 #include <sys/file.h> | 11 #include <sys/file.h> |
12 #include <sys/stat.h> | 12 #include <sys/stat.h> |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #include <sys/wait.h> | 14 #include <sys/wait.h> |
15 #include <unistd.h> | 15 #include <unistd.h> |
16 | |
17 #include <cstdlib> | 16 #include <cstdlib> |
18 #include <cstring> | 17 #include <cstring> |
19 #include <string> | 18 #include <string> |
| 19 #include <utility> |
20 | 20 |
21 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
22 #include "base/files/file_util.h" | 22 #include "base/files/file_util.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
25 #include "base/posix/eintr_wrapper.h" | 25 #include "base/posix/eintr_wrapper.h" |
26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
28 #include "tools/android/forwarder2/common.h" | 28 #include "tools/android/forwarder2/common.h" |
29 #include "tools/android/forwarder2/socket.h" | 29 #include "tools/android/forwarder2/socket.h" |
(...skipping 30 matching lines...) Expand all Loading... |
60 PError("Accept()"); | 60 PError("Accept()"); |
61 failed = true; | 61 failed = true; |
62 break; | 62 break; |
63 } | 63 } |
64 if (!client_socket->Write(welcome_message.c_str(), | 64 if (!client_socket->Write(welcome_message.c_str(), |
65 welcome_message.length() + 1)) { | 65 welcome_message.length() + 1)) { |
66 PError("Write()"); | 66 PError("Write()"); |
67 failed = true; | 67 failed = true; |
68 continue; | 68 continue; |
69 } | 69 } |
70 server_delegate->OnClientConnected(client_socket.Pass()); | 70 server_delegate->OnClientConnected(std::move(client_socket)); |
71 } | 71 } |
72 return !failed; | 72 return !failed; |
73 } | 73 } |
74 | 74 |
75 void SigChildHandler(int signal_number) { | 75 void SigChildHandler(int signal_number) { |
76 DCHECK_EQ(signal_number, SIGCHLD); | 76 DCHECK_EQ(signal_number, SIGCHLD); |
77 int status; | 77 int status; |
78 pid_t child_pid = waitpid(-1 /* any child */, &status, WNOHANG); | 78 pid_t child_pid = waitpid(-1 /* any child */, &status, WNOHANG); |
79 if (child_pid < 0) { | 79 if (child_pid < 0) { |
80 PError("waitpid"); | 80 PError("waitpid"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 DCHECK(expected_welcome_message.length() + 1 <= sizeof(buf)); | 113 DCHECK(expected_welcome_message.length() + 1 <= sizeof(buf)); |
114 memset(buf, 0, sizeof(buf)); | 114 memset(buf, 0, sizeof(buf)); |
115 if (socket->Read(buf, expected_welcome_message.length() + 1) < 0) { | 115 if (socket->Read(buf, expected_welcome_message.length() + 1) < 0) { |
116 perror("read"); | 116 perror("read"); |
117 continue; | 117 continue; |
118 } | 118 } |
119 if (expected_welcome_message != buf) { | 119 if (expected_welcome_message != buf) { |
120 LOG(ERROR) << "Unexpected message read from daemon: " << buf; | 120 LOG(ERROR) << "Unexpected message read from daemon: " << buf; |
121 break; | 121 break; |
122 } | 122 } |
123 return socket.Pass(); | 123 return socket; |
124 } | 124 } |
125 return scoped_ptr<Socket>(); | 125 return scoped_ptr<Socket>(); |
126 } | 126 } |
127 | 127 |
128 } // namespace | 128 } // namespace |
129 | 129 |
130 Daemon::Daemon(const std::string& log_file_path, | 130 Daemon::Daemon(const std::string& log_file_path, |
131 const std::string& identifier, | 131 const std::string& identifier, |
132 ClientDelegate* client_delegate, | 132 ClientDelegate* client_delegate, |
133 ServerDelegate* server_delegate, | 133 ServerDelegate* server_delegate, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return true; | 255 return true; |
256 } | 256 } |
257 usleep(kIdleTimeMSec * 1000); | 257 usleep(kIdleTimeMSec * 1000); |
258 } | 258 } |
259 LOG(ERROR) << "Timed out while killing daemon. " | 259 LOG(ERROR) << "Timed out while killing daemon. " |
260 "It might still be tearing down."; | 260 "It might still be tearing down."; |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 } // namespace forwarder2 | 264 } // namespace forwarder2 |
OLD | NEW |