| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 for (int i = 0; i < tries_count; ++i) { | 134 for (int i = 0; i < tries_count; ++i) { |
| 135 scoped_ptr<Socket> socket(new Socket()); | 135 scoped_ptr<Socket> socket(new Socket()); |
| 136 if (!socket->ConnectUnix(socket_name)) { | 136 if (!socket->ConnectUnix(socket_name)) { |
| 137 if (idle_time_msec) | 137 if (idle_time_msec) |
| 138 usleep(idle_time_msec * 1000); | 138 usleep(idle_time_msec * 1000); |
| 139 continue; | 139 continue; |
| 140 } | 140 } |
| 141 char buf[kBufferSize]; | 141 char buf[kBufferSize]; |
| 142 DCHECK(expected_welcome_message.length() + 1 <= sizeof(buf)); | 142 DCHECK(expected_welcome_message.length() + 1 <= sizeof(buf)); |
| 143 memset(buf, 0, sizeof(buf)); | 143 memset(buf, 0, sizeof(buf)); |
| 144 if (socket->Read(buf, sizeof(buf)) < 0) { | 144 if (socket->Read(buf, expected_welcome_message.length() + 1) < 0) { |
| 145 perror("read"); | 145 perror("read"); |
| 146 continue; | 146 continue; |
| 147 } | 147 } |
| 148 if (expected_welcome_message != buf) { | 148 if (expected_welcome_message != buf) { |
| 149 LOG(ERROR) << "Unexpected message read from daemon: " << buf; | 149 LOG(ERROR) << "Unexpected message read from daemon: " << buf; |
| 150 break; | 150 break; |
| 151 } | 151 } |
| 152 return socket.Pass(); | 152 return socket.Pass(); |
| 153 } | 153 } |
| 154 return scoped_ptr<Socket>(); | 154 return scoped_ptr<Socket>(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 return true; | 280 return true; |
| 281 } | 281 } |
| 282 usleep(kIdleTimeMSec * 1000); | 282 usleep(kIdleTimeMSec * 1000); |
| 283 } | 283 } |
| 284 LOG(ERROR) << "Timed out while killing daemon. " | 284 LOG(ERROR) << "Timed out while killing daemon. " |
| 285 "It might still be tearing down."; | 285 "It might still be tearing down."; |
| 286 return false; | 286 return false; |
| 287 } | 287 } |
| 288 | 288 |
| 289 } // namespace forwarder2 | 289 } // namespace forwarder2 |
| OLD | NEW |