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

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 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
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 ||
154 mode == (WATCH_READ_WRITE));
wtc 2012/11/28 00:25:26 Remove the parantheses around WATCH_READ_WRITE. Yo
blundell 2012/11/28 12:25:01 Done.
154 // WatchFileDescriptor should be called on the pump thread. It is not 155 // WatchFileDescriptor should be called on the pump thread. It is not
155 // threadsafe, and your watcher may never be registered. 156 // threadsafe, and your watcher may never be registered.
156 DCHECK(watch_file_descriptor_caller_checker_.CalledOnValidThread()); 157 DCHECK(watch_file_descriptor_caller_checker_.CalledOnValidThread());
157 158
158 int event_mask = persistent ? EV_PERSIST : 0; 159 int event_mask = persistent ? EV_PERSIST : 0;
159 if ((mode & WATCH_READ) != 0) { 160 if (mode & WATCH_READ) {
160 event_mask |= EV_READ; 161 event_mask |= EV_READ;
161 } 162 }
162 if ((mode & WATCH_WRITE) != 0) { 163 if (mode & WATCH_WRITE) {
163 event_mask |= EV_WRITE; 164 event_mask |= EV_WRITE;
164 } 165 }
165 166
166 scoped_ptr<event> evt(controller->ReleaseEvent()); 167 scoped_ptr<event> evt(controller->ReleaseEvent());
167 if (evt.get() == NULL) { 168 if (evt.get() == NULL) {
168 // Ownership is transferred to the controller. 169 // Ownership is transferred to the controller.
169 evt.reset(new event); 170 evt.reset(new event);
170 } else { 171 } else {
171 // Make sure we don't pick up any funky internal libevent masks. 172 // Make sure we don't pick up any funky internal libevent masks.
172 int old_interest_mask = evt.get()->ev_events & 173 int old_interest_mask = evt.get()->ev_events &
(...skipping 10 matching lines...) Expand all
183 if (EVENT_FD(evt.get()) != fd) { 184 if (EVENT_FD(evt.get()) != fd) {
184 NOTREACHED() << "FDs don't match" << EVENT_FD(evt.get()) << "!=" << fd; 185 NOTREACHED() << "FDs don't match" << EVENT_FD(evt.get()) << "!=" << fd;
185 return false; 186 return false;
186 } 187 }
187 } 188 }
188 189
189 // Set current interest mask and message pump for this event. 190 // Set current interest mask and message pump for this event.
190 event_set(evt.get(), fd, event_mask, OnLibeventNotification, controller); 191 event_set(evt.get(), fd, event_mask, OnLibeventNotification, controller);
191 192
192 // Tell libevent which message pump this socket will belong to when we add it. 193 // Tell libevent which message pump this socket will belong to when we add it.
193 if (event_base_set(event_base_, evt.get()) != 0) { 194 if (event_base_set(event_base_, evt.get())) {
194 return false; 195 return false;
195 } 196 }
196 197
197 // Add this socket to the list of monitored sockets. 198 // Add this socket to the list of monitored sockets.
198 if (event_add(evt.get(), NULL) != 0) { 199 if (event_add(evt.get(), NULL)) {
wtc 2012/11/28 00:25:26 Nit: I believe Mark did not ask for these two chan
blundell 2012/11/28 12:25:01 I extrapolated from his request for consistency on
199 return false; 200 return false;
200 } 201 }
201 202
202 // Transfer ownership of evt to controller. 203 // Transfer ownership of evt to controller.
203 controller->Init(evt.release()); 204 controller->Init(evt.release());
204 205
205 controller->set_watcher(delegate); 206 controller->set_watcher(delegate);
206 controller->set_pump(this); 207 controller->set_pump(this);
207 208
208 return true; 209 return true;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // Remove and discard the wakeup byte. 375 // Remove and discard the wakeup byte.
375 char buf; 376 char buf;
376 int nread = HANDLE_EINTR(read(socket, &buf, 1)); 377 int nread = HANDLE_EINTR(read(socket, &buf, 1));
377 DCHECK_EQ(nread, 1); 378 DCHECK_EQ(nread, 1);
378 that->processed_io_events_ = true; 379 that->processed_io_events_ = true;
379 // Tell libevent to break out of inner loop. 380 // Tell libevent to break out of inner loop.
380 event_base_loopbreak(that->event_base_); 381 event_base_loopbreak(that->event_base_);
381 } 382 }
382 383
383 } // namespace base 384 } // namespace base
OLDNEW
« base/message_pump_io_ios_unittest.cc ('K') | « base/message_pump_libevent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698