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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 class ServerDelegate : public Daemon::ServerDelegate { | 305 class ServerDelegate : public Daemon::ServerDelegate { |
306 public: | 306 public: |
307 ServerDelegate() : has_failed_(false) {} | 307 ServerDelegate() : has_failed_(false) {} |
308 | 308 |
309 bool has_failed() const { | 309 bool has_failed() const { |
310 return has_failed_ || controllers_manager_.has_failed(); | 310 return has_failed_ || controllers_manager_.has_failed(); |
311 } | 311 } |
312 | 312 |
313 // Daemon::ServerDelegate: | 313 // Daemon::ServerDelegate: |
314 virtual void Init() OVERRIDE { | 314 virtual void Init() override { |
315 LOG(INFO) << "Starting host process daemon (pid=" << getpid() << ")"; | 315 LOG(INFO) << "Starting host process daemon (pid=" << getpid() << ")"; |
316 DCHECK(!g_notifier); | 316 DCHECK(!g_notifier); |
317 g_notifier = new PipeNotifier(); | 317 g_notifier = new PipeNotifier(); |
318 signal(SIGTERM, KillHandler); | 318 signal(SIGTERM, KillHandler); |
319 signal(SIGINT, KillHandler); | 319 signal(SIGINT, KillHandler); |
320 } | 320 } |
321 | 321 |
322 virtual void OnClientConnected(scoped_ptr<Socket> client_socket) OVERRIDE { | 322 virtual void OnClientConnected(scoped_ptr<Socket> client_socket) override { |
323 char buf[kBufSize]; | 323 char buf[kBufSize]; |
324 const int bytes_read = client_socket->Read(buf, sizeof(buf)); | 324 const int bytes_read = client_socket->Read(buf, sizeof(buf)); |
325 if (bytes_read <= 0) { | 325 if (bytes_read <= 0) { |
326 if (client_socket->DidReceiveEvent()) | 326 if (client_socket->DidReceiveEvent()) |
327 return; | 327 return; |
328 PError("Read()"); | 328 PError("Read()"); |
329 has_failed_ = true; | 329 has_failed_ = true; |
330 return; | 330 return; |
331 } | 331 } |
332 const Pickle command_pickle(buf, bytes_read); | 332 const Pickle command_pickle(buf, bytes_read); |
(...skipping 22 matching lines...) Expand all Loading... |
355 class ClientDelegate : public Daemon::ClientDelegate { | 355 class ClientDelegate : public Daemon::ClientDelegate { |
356 public: | 356 public: |
357 ClientDelegate(const Pickle& command_pickle) | 357 ClientDelegate(const Pickle& command_pickle) |
358 : command_pickle_(command_pickle), | 358 : command_pickle_(command_pickle), |
359 has_failed_(false) { | 359 has_failed_(false) { |
360 } | 360 } |
361 | 361 |
362 bool has_failed() const { return has_failed_; } | 362 bool has_failed() const { return has_failed_; } |
363 | 363 |
364 // Daemon::ClientDelegate: | 364 // Daemon::ClientDelegate: |
365 virtual void OnDaemonReady(Socket* daemon_socket) OVERRIDE { | 365 virtual void OnDaemonReady(Socket* daemon_socket) override { |
366 // Send the forward command to the daemon. | 366 // Send the forward command to the daemon. |
367 CHECK_EQ(command_pickle_.size(), | 367 CHECK_EQ(command_pickle_.size(), |
368 daemon_socket->WriteNumBytes(command_pickle_.data(), | 368 daemon_socket->WriteNumBytes(command_pickle_.data(), |
369 command_pickle_.size())); | 369 command_pickle_.size())); |
370 char buf[kBufSize]; | 370 char buf[kBufSize]; |
371 const int bytes_read = daemon_socket->Read( | 371 const int bytes_read = daemon_socket->Read( |
372 buf, sizeof(buf) - 1 /* leave space for null terminator */); | 372 buf, sizeof(buf) - 1 /* leave space for null terminator */); |
373 CHECK_GT(bytes_read, 0); | 373 CHECK_GT(bytes_read, 0); |
374 DCHECK(bytes_read < sizeof(buf)); | 374 DCHECK(bytes_read < sizeof(buf)); |
375 buf[bytes_read] = 0; | 375 buf[bytes_read] = 0; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 451 |
452 return client_delegate.has_failed() || daemon_delegate.has_failed(); | 452 return client_delegate.has_failed() || daemon_delegate.has_failed(); |
453 } | 453 } |
454 | 454 |
455 } // namespace | 455 } // namespace |
456 } // namespace forwarder2 | 456 } // namespace forwarder2 |
457 | 457 |
458 int main(int argc, char** argv) { | 458 int main(int argc, char** argv) { |
459 return forwarder2::RunHostForwarder(argc, argv); | 459 return forwarder2::RunHostForwarder(argc, argv); |
460 } | 460 } |
OLD | NEW |