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"
9 #include <sys/socket.h>
10 #include <sys/types.h>
12 #include "base/logging.h"
13 #include "base/posix/eintr_wrapper.h"
15 namespace forwarder2
{
17 PipeNotifier::PipeNotifier() {
19 int ret
= pipe(pipe_fd
);
21 receiver_fd_
= pipe_fd
[0];
22 sender_fd_
= pipe_fd
[1];
23 fcntl(sender_fd_
, F_SETFL
, O_NONBLOCK
);
26 PipeNotifier::~PipeNotifier() {
31 bool PipeNotifier::Notify() {
32 CHECK_NE(-1, sender_fd_
);
34 int ret
= HANDLE_EINTR(write(sender_fd_
, "1", 1));
36 PLOG(ERROR
) << "write";
42 void PipeNotifier::Reset() {
44 int ret
= HANDLE_EINTR(read(receiver_fd_
, &c
, 1));
46 PLOG(ERROR
) << "read";
53 } // namespace forwarder