Change next_proto member type.
[chromium-blink-merge.git] / tools / android / forwarder2 / pipe_notifier.cc
blob02842bd9b7cea1e9829b0a829268fb67990139aa
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
3 // found in the LICENSE file.
5 #include "tools/android/forwarder2/pipe_notifier.h"
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <sys/socket.h>
10 #include <sys/types.h>
12 #include "base/logging.h"
13 #include "base/posix/eintr_wrapper.h"
14 #include "base/safe_strerror_posix.h"
16 namespace forwarder2 {
18 PipeNotifier::PipeNotifier() {
19 int pipe_fd[2];
20 int ret = pipe(pipe_fd);
21 CHECK_EQ(0, ret);
22 receiver_fd_ = pipe_fd[0];
23 sender_fd_ = pipe_fd[1];
24 fcntl(sender_fd_, F_SETFL, O_NONBLOCK);
27 PipeNotifier::~PipeNotifier() {
28 close(receiver_fd_);
29 close(sender_fd_);
32 bool PipeNotifier::Notify() {
33 CHECK_NE(-1, sender_fd_);
34 errno = 0;
35 int ret = HANDLE_EINTR(write(sender_fd_, "1", 1));
36 if (ret < 0) {
37 PLOG(ERROR) << "write";
38 return false;
40 return true;
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;
50 DCHECK_EQ(1, ret);
51 DCHECK_EQ('1', c);
54 } // namespace forwarder