Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: base/message_pump_libevent.cc

Issue 7473017: Cleanup for r93201. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/message_pump_libevent_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 int flags = fcntl(fd, F_GETFL, 0); 47 int flags = fcntl(fd, F_GETFL, 0);
48 if (flags == -1) 48 if (flags == -1)
49 flags = 0; 49 flags = 0;
50 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); 50 return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
51 } 51 }
52 52
53 MessagePumpLibevent::FileDescriptorWatcher::FileDescriptorWatcher() 53 MessagePumpLibevent::FileDescriptorWatcher::FileDescriptorWatcher()
54 : is_persistent_(false), 54 : is_persistent_(false),
55 event_(NULL), 55 event_(NULL),
56 pump_(NULL), 56 pump_(NULL),
57 watcher_(NULL),
57 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 58 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
58 } 59 }
59 60
60 MessagePumpLibevent::FileDescriptorWatcher::~FileDescriptorWatcher() { 61 MessagePumpLibevent::FileDescriptorWatcher::~FileDescriptorWatcher() {
61 if (event_) { 62 if (event_) {
62 StopWatchingFileDescriptor(); 63 StopWatchingFileDescriptor();
63 } 64 }
64 } 65 }
65 66
66 bool MessagePumpLibevent::FileDescriptorWatcher::StopWatchingFileDescriptor() { 67 bool MessagePumpLibevent::FileDescriptorWatcher::StopWatchingFileDescriptor() {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 base::WeakPtr<FileDescriptorWatcher> controller = 344 base::WeakPtr<FileDescriptorWatcher> controller =
344 static_cast<FileDescriptorWatcher*>(context)->weak_factory_.GetWeakPtr(); 345 static_cast<FileDescriptorWatcher*>(context)->weak_factory_.GetWeakPtr();
345 DCHECK(controller.get()); 346 DCHECK(controller.get());
346 347
347 MessagePumpLibevent* pump = controller->pump(); 348 MessagePumpLibevent* pump = controller->pump();
348 pump->processed_io_events_ = true; 349 pump->processed_io_events_ = true;
349 350
350 if (flags & EV_WRITE) { 351 if (flags & EV_WRITE) {
351 controller->OnFileCanWriteWithoutBlocking(fd, pump); 352 controller->OnFileCanWriteWithoutBlocking(fd, pump);
352 } 353 }
353 // Check |controller| in case it's been deleted in this callback. 354 // Check |controller| in case it's been deleted in
355 // controller->OnFileCanWriteWithoutBlocking().
354 if (controller.get() && flags & EV_READ) { 356 if (controller.get() && flags & EV_READ) {
355 controller->OnFileCanReadWithoutBlocking(fd, pump); 357 controller->OnFileCanReadWithoutBlocking(fd, pump);
356 } 358 }
357 } 359 }
358 360
359 // Called if a byte is received on the wakeup pipe. 361 // Called if a byte is received on the wakeup pipe.
360 // static 362 // static
361 void MessagePumpLibevent::OnWakeup(int socket, short flags, void* context) { 363 void MessagePumpLibevent::OnWakeup(int socket, short flags, void* context) {
362 base::MessagePumpLibevent* that = 364 base::MessagePumpLibevent* that =
363 static_cast<base::MessagePumpLibevent*>(context); 365 static_cast<base::MessagePumpLibevent*>(context);
364 DCHECK(that->wakeup_pipe_out_ == socket); 366 DCHECK(that->wakeup_pipe_out_ == socket);
365 367
366 // Remove and discard the wakeup byte. 368 // Remove and discard the wakeup byte.
367 char buf; 369 char buf;
368 int nread = HANDLE_EINTR(read(socket, &buf, 1)); 370 int nread = HANDLE_EINTR(read(socket, &buf, 1));
369 DCHECK_EQ(nread, 1); 371 DCHECK_EQ(nread, 1);
370 that->processed_io_events_ = true; 372 that->processed_io_events_ = true;
371 // Tell libevent to break out of inner loop. 373 // Tell libevent to break out of inner loop.
372 event_base_loopbreak(that->event_base_); 374 event_base_loopbreak(that->event_base_);
373 } 375 }
374 376
375 } // namespace base 377 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/message_pump_libevent_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698