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

Side by Side Diff: dart/runtime/bin/eventhandler_linux.cc

Issue 900363004: Introduce a kSetEventMaskCommand, some cleanups in windows eventhandler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 5 years, 10 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 | « dart/runtime/bin/eventhandler_android.cc ('k') | dart/runtime/bin/eventhandler_macos.h » ('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 Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/eventhandler.h" 8 #include "bin/eventhandler.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (timeout_queue_.HasTimeout()) { 186 if (timeout_queue_.HasTimeout()) {
187 int64_t millis = timeout_queue_.CurrentTimeout(); 187 int64_t millis = timeout_queue_.CurrentTimeout();
188 it.it_value.tv_sec = millis / 1000; 188 it.it_value.tv_sec = millis / 1000;
189 it.it_value.tv_nsec = (millis % 1000) * 1000000; 189 it.it_value.tv_nsec = (millis % 1000) * 1000000;
190 } 190 }
191 VOID_NO_RETRY_EXPECTED( 191 VOID_NO_RETRY_EXPECTED(
192 timerfd_settime(timer_fd_, TFD_TIMER_ABSTIME, &it, NULL)); 192 timerfd_settime(timer_fd_, TFD_TIMER_ABSTIME, &it, NULL));
193 } else if (msg[i].id == kShutdownId) { 193 } else if (msg[i].id == kShutdownId) {
194 shutdown_ = true; 194 shutdown_ = true;
195 } else { 195 } else {
196 ASSERT((msg[i].data & COMMAND_MASK) != 0);
197
196 SocketData* sd = GetSocketData( 198 SocketData* sd = GetSocketData(
197 msg[i].id, (msg[i].data & (1 << kListeningSocket)) != 0); 199 msg[i].id, IS_LISTENING_SOCKET(msg[i].data));
198 if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { 200 if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) {
199 ASSERT(!sd->IsListeningSocket()); 201 ASSERT(!sd->IsListeningSocket());
200 // Close the socket for reading. 202 // Close the socket for reading.
201 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_RD)); 203 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_RD));
202 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { 204 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) {
203 ASSERT(!sd->IsListeningSocket()); 205 ASSERT(!sd->IsListeningSocket());
204 // Close the socket for writing. 206 // Close the socket for writing.
205 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_WR)); 207 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_WR));
206 } else if (IS_COMMAND(msg[i].data, kCloseCommand)) { 208 } else if (IS_COMMAND(msg[i].data, kCloseCommand)) {
207 // Close the socket and free system resources and move on to next 209 // Close the socket and free system resources and move on to next
208 // message. 210 // message.
209 if (sd->RemovePort(msg[i].dart_port)) { 211 if (sd->RemovePort(msg[i].dart_port)) {
210 RemoveFromEpollInstance(epoll_fd_, sd); 212 RemoveFromEpollInstance(epoll_fd_, sd);
211 intptr_t fd = sd->fd(); 213 intptr_t fd = sd->fd();
212 sd->Close(); 214 sd->Close();
213 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); 215 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
214 delete sd; 216 delete sd;
215 } 217 }
216 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); 218 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent);
217 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { 219 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) {
218 int count = TOKEN_COUNT(msg[i].data); 220 int count = TOKEN_COUNT(msg[i].data);
219 if (sd->ReturnToken(msg[i].dart_port, count)) { 221 if (sd->ReturnToken(msg[i].dart_port, count)) {
220 AddToEpollInstance(epoll_fd_, sd); 222 AddToEpollInstance(epoll_fd_, sd);
221 } 223 }
222 } else { 224 } else if (IS_COMMAND(msg[i].data, kSetEventMaskCommand)) {
223 ASSERT_NO_COMMAND(msg[i].data); 225 // `events` can only have kInEvent/kOutEvent flags set.
226 intptr_t events = msg[i].data & EVENT_MASK;
227 ASSERT(0 == (events & ~(1 << kInEvent | 1 << kOutEvent)));
228
224 // Setup events to wait for. 229 // Setup events to wait for.
225 if (sd->AddPort(msg[i].dart_port)) { 230 if (sd->AddPort(msg[i].dart_port)) {
226 sd->SetMask(msg[i].data); 231 sd->SetMask(events);
227 AddToEpollInstance(epoll_fd_, sd); 232 AddToEpollInstance(epoll_fd_, sd);
228 } 233 }
234 } else {
235 UNREACHABLE();
229 } 236 }
230 } 237 }
231 } 238 }
232 } 239 }
233 240
234 #ifdef DEBUG_POLL 241 #ifdef DEBUG_POLL
235 static void PrintEventMask(intptr_t fd, intptr_t events) { 242 static void PrintEventMask(intptr_t fd, intptr_t events) {
236 Log::Print("%d ", fd); 243 Log::Print("%d ", fd);
237 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); 244 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN ");
238 if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI "); 245 if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI ");
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 364
358 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 365 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
359 // The hashmap does not support keys with value 0. 366 // The hashmap does not support keys with value 0.
360 return dart::Utils::WordHash(fd + 1); 367 return dart::Utils::WordHash(fd + 1);
361 } 368 }
362 369
363 } // namespace bin 370 } // namespace bin
364 } // namespace dart 371 } // namespace dart
365 372
366 #endif // defined(TARGET_OS_LINUX) 373 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « dart/runtime/bin/eventhandler_android.cc ('k') | dart/runtime/bin/eventhandler_macos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698