| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <errno.h> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/scoped_nsautorelease_pool.h" | 11 #include "base/scoped_nsautorelease_pool.h" |
| 11 #include "base/time.h" | 12 #include "base/time.h" |
| 12 #include "third_party/libevent/event.h" | 13 #include "third_party/libevent/event.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 | 16 |
| 16 // Return 0 on success | 17 // Return 0 on success |
| 17 // Too small a function to bother putting in a library? | 18 // Too small a function to bother putting in a library? |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 in_run_(false), | 75 in_run_(false), |
| 75 event_base_(event_base_new()), | 76 event_base_(event_base_new()), |
| 76 wakeup_pipe_in_(-1), | 77 wakeup_pipe_in_(-1), |
| 77 wakeup_pipe_out_(-1) { | 78 wakeup_pipe_out_(-1) { |
| 78 if (!Init()) | 79 if (!Init()) |
| 79 NOTREACHED(); | 80 NOTREACHED(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool MessagePumpLibevent::Init() { | 83 bool MessagePumpLibevent::Init() { |
| 83 int fds[2]; | 84 int fds[2]; |
| 84 if (pipe(fds)) | 85 if (pipe(fds)) { |
| 86 DLOG(ERROR) << "pipe() failed, errno: " << errno; |
| 85 return false; | 87 return false; |
| 86 if (SetNonBlocking(fds[0])) | 88 } |
| 89 if (SetNonBlocking(fds[0])) { |
| 90 DLOG(ERROR) << "SetNonBlocking for pipe fd[0] failed, errno: " << errno; |
| 87 return false; | 91 return false; |
| 88 if (SetNonBlocking(fds[1])) | 92 } |
| 93 if (SetNonBlocking(fds[1])) { |
| 94 DLOG(ERROR) << "SetNonBlocking for pipe fd[1] failed, errno: " << errno; |
| 89 return false; | 95 return false; |
| 96 } |
| 90 wakeup_pipe_out_ = fds[0]; | 97 wakeup_pipe_out_ = fds[0]; |
| 91 wakeup_pipe_in_ = fds[1]; | 98 wakeup_pipe_in_ = fds[1]; |
| 92 | 99 |
| 93 wakeup_event_ = new event; | 100 wakeup_event_ = new event; |
| 94 event_set(wakeup_event_, wakeup_pipe_out_, EV_READ | EV_PERSIST, | 101 event_set(wakeup_event_, wakeup_pipe_out_, EV_READ | EV_PERSIST, |
| 95 OnWakeup, this); | 102 OnWakeup, this); |
| 96 event_base_set(event_base_, wakeup_event_); | 103 event_base_set(event_base_, wakeup_event_); |
| 97 | 104 |
| 98 if (event_add(wakeup_event_, 0)) | 105 if (event_add(wakeup_event_, 0)) |
| 99 return false; | 106 return false; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 250 } |
| 244 | 251 |
| 245 void MessagePumpLibevent::ScheduleDelayedWork(const Time& delayed_work_time) { | 252 void MessagePumpLibevent::ScheduleDelayedWork(const Time& delayed_work_time) { |
| 246 // We know that we can't be blocked on Wait right now since this method can | 253 // We know that we can't be blocked on Wait right now since this method can |
| 247 // only be called on the same thread as Run, so we only need to update our | 254 // only be called on the same thread as Run, so we only need to update our |
| 248 // record of how long to sleep when we do sleep. | 255 // record of how long to sleep when we do sleep. |
| 249 delayed_work_time_ = delayed_work_time; | 256 delayed_work_time_ = delayed_work_time; |
| 250 } | 257 } |
| 251 | 258 |
| 252 } // namespace base | 259 } // namespace base |
| OLD | NEW |