| 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 "base/message_pump_libevent.h" | 5 #include "base/message_pump_libevent.h" |
| 6 | 6 |
| 7 #include <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 protected: | 23 protected: |
| 24 MessagePumpLibeventTest() | 24 MessagePumpLibeventTest() |
| 25 : ui_loop_(MessageLoop::TYPE_UI), | 25 : ui_loop_(MessageLoop::TYPE_UI), |
| 26 io_thread_("MessagePumpLibeventTestIOThread") {} | 26 io_thread_("MessagePumpLibeventTestIOThread") {} |
| 27 virtual ~MessagePumpLibeventTest() {} | 27 virtual ~MessagePumpLibeventTest() {} |
| 28 | 28 |
| 29 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() OVERRIDE { |
| 30 Thread::Options options(MessageLoop::TYPE_IO, 0); | 30 Thread::Options options(MessageLoop::TYPE_IO, 0); |
| 31 ASSERT_TRUE(io_thread_.StartWithOptions(options)); | 31 ASSERT_TRUE(io_thread_.StartWithOptions(options)); |
| 32 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type()); | 32 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type()); |
| 33 int err = pipe(pipefds_); | 33 int ret = pipe(pipefds_); |
| 34 ASSERT_EQ(0, err); | 34 ASSERT_EQ(0, ret); |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual void TearDown() OVERRIDE { | 37 virtual void TearDown() OVERRIDE { |
| 38 if (HANDLE_EINTR(close(pipefds_[0])) < 0) | 38 if (HANDLE_EINTR(close(pipefds_[0])) < 0) |
| 39 PLOG(ERROR) << "close"; | 39 PLOG(ERROR) << "close"; |
| 40 if (HANDLE_EINTR(close(pipefds_[1])) < 0) | 40 if (HANDLE_EINTR(close(pipefds_[1])) < 0) |
| 41 PLOG(ERROR) << "close"; | 41 PLOG(ERROR) << "close"; |
| 42 } | 42 } |
| 43 | 43 |
| 44 MessageLoop* ui_loop() { return &ui_loop_; } | 44 MessageLoop* ui_loop() { return &ui_loop_; } |
| 45 MessageLoopForIO* io_loop() const { | 45 MessageLoopForIO* io_loop() const { |
| 46 return static_cast<MessageLoopForIO*>(io_thread_.message_loop()); | 46 return static_cast<MessageLoopForIO*>(io_thread_.message_loop()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void OnLibeventNotification( | 49 void OnLibeventNotification( |
| 50 MessagePumpLibevent* pump, | 50 MessagePumpLibevent* pump, |
| 51 MessagePumpLibevent::FileDescriptorWatcher* controller) { | 51 MessagePumpLibevent::FileDescriptorWatcher* controller) { |
| 52 pump->OnLibeventNotification(0, EV_WRITE | EV_READ, controller); | 52 pump->OnLibeventNotification(0, EV_WRITE | EV_READ, controller); |
| 53 } | 53 } |
| 54 | 54 |
| 55 int pipefds_[2]; |
| 56 |
| 57 private: |
| 55 MessageLoop ui_loop_; | 58 MessageLoop ui_loop_; |
| 56 Thread io_thread_; | 59 Thread io_thread_; |
| 57 int pipefds_[2]; | |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 namespace { | 62 namespace { |
| 61 | 63 |
| 62 // Concrete implementation of MessagePumpLibevent::Watcher that does | 64 // Concrete implementation of MessagePumpLibevent::Watcher that does |
| 63 // nothing useful. | 65 // nothing useful. |
| 64 class StupidWatcher : public MessagePumpLibevent::Watcher { | 66 class StupidWatcher : public MessagePumpLibevent::Watcher { |
| 65 public: | 67 public: |
| 66 virtual ~StupidWatcher() {} | 68 virtual ~StupidWatcher() {} |
| 67 | 69 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 pump->WatchFileDescriptor(pipefds_[1], | 158 pump->WatchFileDescriptor(pipefds_[1], |
| 157 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate); | 159 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate); |
| 158 | 160 |
| 159 // Spoof a libevent notification. | 161 // Spoof a libevent notification. |
| 160 OnLibeventNotification(pump, &watcher); | 162 OnLibeventNotification(pump, &watcher); |
| 161 } | 163 } |
| 162 | 164 |
| 163 } // namespace | 165 } // namespace |
| 164 | 166 |
| 165 } // namespace base | 167 } // namespace base |
| OLD | NEW |