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

Side by Side Diff: base/message_pump_libevent.cc

Issue 11412101: Provide an iOS message pump for IO implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to wtc's review Created 8 years 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
« no previous file with comments | « base/message_pump_libevent.h ('k') | 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) 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 <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 if (wakeup_pipe_out_ >= 0) { 138 if (wakeup_pipe_out_ >= 0) {
139 if (HANDLE_EINTR(close(wakeup_pipe_out_)) < 0) 139 if (HANDLE_EINTR(close(wakeup_pipe_out_)) < 0)
140 DPLOG(ERROR) << "close"; 140 DPLOG(ERROR) << "close";
141 } 141 }
142 event_base_free(event_base_); 142 event_base_free(event_base_);
143 } 143 }
144 144
145 bool MessagePumpLibevent::WatchFileDescriptor(int fd, 145 bool MessagePumpLibevent::WatchFileDescriptor(int fd,
146 bool persistent, 146 bool persistent,
147 Mode mode, 147 int mode,
148 FileDescriptorWatcher *controller, 148 FileDescriptorWatcher *controller,
149 Watcher *delegate) { 149 Watcher *delegate) {
150 DCHECK_GE(fd, 0); 150 DCHECK_GE(fd, 0);
151 DCHECK(controller); 151 DCHECK(controller);
152 DCHECK(delegate); 152 DCHECK(delegate);
153 DCHECK(mode == WATCH_READ || mode == WATCH_WRITE || mode == WATCH_READ_WRITE); 153 DCHECK(mode == WATCH_READ || mode == WATCH_WRITE || mode == WATCH_READ_WRITE);
154 // WatchFileDescriptor should be called on the pump thread. It is not 154 // WatchFileDescriptor should be called on the pump thread. It is not
155 // threadsafe, and your watcher may never be registered. 155 // threadsafe, and your watcher may never be registered.
156 DCHECK(watch_file_descriptor_caller_checker_.CalledOnValidThread()); 156 DCHECK(watch_file_descriptor_caller_checker_.CalledOnValidThread());
157 157
158 int event_mask = persistent ? EV_PERSIST : 0; 158 int event_mask = persistent ? EV_PERSIST : 0;
159 if ((mode & WATCH_READ) != 0) { 159 if (mode & WATCH_READ) {
160 event_mask |= EV_READ; 160 event_mask |= EV_READ;
161 } 161 }
162 if ((mode & WATCH_WRITE) != 0) { 162 if (mode & WATCH_WRITE) {
163 event_mask |= EV_WRITE; 163 event_mask |= EV_WRITE;
164 } 164 }
165 165
166 scoped_ptr<event> evt(controller->ReleaseEvent()); 166 scoped_ptr<event> evt(controller->ReleaseEvent());
167 if (evt.get() == NULL) { 167 if (evt.get() == NULL) {
168 // Ownership is transferred to the controller. 168 // Ownership is transferred to the controller.
169 evt.reset(new event); 169 evt.reset(new event);
170 } else { 170 } else {
171 // Make sure we don't pick up any funky internal libevent masks. 171 // Make sure we don't pick up any funky internal libevent masks.
172 int old_interest_mask = evt.get()->ev_events & 172 int old_interest_mask = evt.get()->ev_events &
(...skipping 10 matching lines...) Expand all
183 if (EVENT_FD(evt.get()) != fd) { 183 if (EVENT_FD(evt.get()) != fd) {
184 NOTREACHED() << "FDs don't match" << EVENT_FD(evt.get()) << "!=" << fd; 184 NOTREACHED() << "FDs don't match" << EVENT_FD(evt.get()) << "!=" << fd;
185 return false; 185 return false;
186 } 186 }
187 } 187 }
188 188
189 // Set current interest mask and message pump for this event. 189 // Set current interest mask and message pump for this event.
190 event_set(evt.get(), fd, event_mask, OnLibeventNotification, controller); 190 event_set(evt.get(), fd, event_mask, OnLibeventNotification, controller);
191 191
192 // Tell libevent which message pump this socket will belong to when we add it. 192 // Tell libevent which message pump this socket will belong to when we add it.
193 if (event_base_set(event_base_, evt.get()) != 0) { 193 if (event_base_set(event_base_, evt.get())) {
194 return false; 194 return false;
195 } 195 }
196 196
197 // Add this socket to the list of monitored sockets. 197 // Add this socket to the list of monitored sockets.
198 if (event_add(evt.get(), NULL) != 0) { 198 if (event_add(evt.get(), NULL)) {
199 return false; 199 return false;
200 } 200 }
201 201
202 // Transfer ownership of evt to controller. 202 // Transfer ownership of evt to controller.
203 controller->Init(evt.release()); 203 controller->Init(evt.release());
204 204
205 controller->set_watcher(delegate); 205 controller->set_watcher(delegate);
206 controller->set_pump(this); 206 controller->set_pump(this);
207 207
208 return true; 208 return true;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // Remove and discard the wakeup byte. 374 // Remove and discard the wakeup byte.
375 char buf; 375 char buf;
376 int nread = HANDLE_EINTR(read(socket, &buf, 1)); 376 int nread = HANDLE_EINTR(read(socket, &buf, 1));
377 DCHECK_EQ(nread, 1); 377 DCHECK_EQ(nread, 1);
378 that->processed_io_events_ = true; 378 that->processed_io_events_ = true;
379 // Tell libevent to break out of inner loop. 379 // Tell libevent to break out of inner loop.
380 event_base_loopbreak(that->event_base_); 380 event_base_loopbreak(that->event_base_);
381 } 381 }
382 382
383 } // namespace base 383 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_libevent.h ('k') | base/message_pump_libevent_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698