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_loop/message_pump_libevent.h" | 5 #include "base/message_loop/message_pump_libevent.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 void MessagePumpLibevent::ScheduleDelayedWork( | 283 void MessagePumpLibevent::ScheduleDelayedWork( |
284 const TimeTicks& delayed_work_time) { | 284 const TimeTicks& delayed_work_time) { |
285 // We know that we can't be blocked on Wait right now since this method can | 285 // We know that we can't be blocked on Wait right now since this method can |
286 // only be called on the same thread as Run, so we only need to update our | 286 // only be called on the same thread as Run, so we only need to update our |
287 // record of how long to sleep when we do sleep. | 287 // record of how long to sleep when we do sleep. |
288 delayed_work_time_ = delayed_work_time; | 288 delayed_work_time_ = delayed_work_time; |
289 } | 289 } |
290 | 290 |
291 bool MessagePumpLibevent::Init() { | 291 bool MessagePumpLibevent::Init() { |
292 int fds[2]; | 292 int fds[2]; |
293 if (!CreateLocalNonBlockingPipe(fds)) { | 293 if (pipe(fds)) { |
294 DPLOG(ERROR) << "pipe creation failed"; | 294 DLOG(ERROR) << "pipe() failed, errno: " << errno; |
| 295 return false; |
| 296 } |
| 297 if (!SetNonBlocking(fds[0])) { |
| 298 DLOG(ERROR) << "SetNonBlocking for pipe fd[0] failed, errno: " << errno; |
| 299 return false; |
| 300 } |
| 301 if (!SetNonBlocking(fds[1])) { |
| 302 DLOG(ERROR) << "SetNonBlocking for pipe fd[1] failed, errno: " << errno; |
295 return false; | 303 return false; |
296 } | 304 } |
297 wakeup_pipe_out_ = fds[0]; | 305 wakeup_pipe_out_ = fds[0]; |
298 wakeup_pipe_in_ = fds[1]; | 306 wakeup_pipe_in_ = fds[1]; |
299 | 307 |
300 wakeup_event_ = new event; | 308 wakeup_event_ = new event; |
301 event_set(wakeup_event_, wakeup_pipe_out_, EV_READ | EV_PERSIST, | 309 event_set(wakeup_event_, wakeup_pipe_out_, EV_READ | EV_PERSIST, |
302 OnWakeup, this); | 310 OnWakeup, this); |
303 event_base_set(event_base_, wakeup_event_); | 311 event_base_set(event_base_, wakeup_event_); |
304 | 312 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 // Remove and discard the wakeup byte. | 354 // Remove and discard the wakeup byte. |
347 char buf; | 355 char buf; |
348 int nread = HANDLE_EINTR(read(socket, &buf, 1)); | 356 int nread = HANDLE_EINTR(read(socket, &buf, 1)); |
349 DCHECK_EQ(nread, 1); | 357 DCHECK_EQ(nread, 1); |
350 that->processed_io_events_ = true; | 358 that->processed_io_events_ = true; |
351 // Tell libevent to break out of inner loop. | 359 // Tell libevent to break out of inner loop. |
352 event_base_loopbreak(that->event_base_); | 360 event_base_loopbreak(that->event_base_); |
353 } | 361 } |
354 | 362 |
355 } // namespace base | 363 } // namespace base |
OLD | NEW |