| 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/pipe_notifier.h" | 5 #include "tools/android/forwarder2/pipe_notifier.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 PipeNotifier::~PipeNotifier() { | 27 PipeNotifier::~PipeNotifier() { |
| 28 close(receiver_fd_); | 28 close(receiver_fd_); |
| 29 close(sender_fd_); | 29 close(sender_fd_); |
| 30 } | 30 } |
| 31 | 31 |
| 32 bool PipeNotifier::Notify() { | 32 bool PipeNotifier::Notify() { |
| 33 CHECK_NE(-1, sender_fd_); | 33 CHECK_NE(-1, sender_fd_); |
| 34 errno = 0; | 34 errno = 0; |
| 35 int ret = HANDLE_EINTR(write(sender_fd_, "1", 1)); | 35 int ret = HANDLE_EINTR(write(sender_fd_, "1", 1)); |
| 36 if (ret < 0) { | 36 if (ret < 0) { |
| 37 LOG(WARNING) << "Error while notifying pipe. " << safe_strerror(errno); | 37 PLOG(ERROR) << "write"; |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 return true; | 40 return true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void PipeNotifier::Reset() { |
| 44 char c; |
| 45 int ret = HANDLE_EINTR(read(receiver_fd_, &c, 1)); |
| 46 if (ret < 0) { |
| 47 PLOG(ERROR) << "read"; |
| 48 return; |
| 49 } |
| 50 DCHECK_EQ(1, ret); |
| 51 DCHECK_EQ('1', c); |
| 52 } |
| 53 |
| 43 } // namespace forwarder | 54 } // namespace forwarder |
| OLD | NEW |