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

Side by Side Diff: runtime/bin/eventhandler_android.cc

Issue 234843003: Make server-sockets level triggered. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix platforms. Created 6 years, 8 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 | runtime/bin/eventhandler_linux.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 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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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 25 matching lines...) Expand all
36 36
37 static const int kInterruptMessageSize = sizeof(InterruptMessage); 37 static const int kInterruptMessageSize = sizeof(InterruptMessage);
38 static const int kInfinityTimeout = -1; 38 static const int kInfinityTimeout = -1;
39 static const int kTimerId = -1; 39 static const int kTimerId = -1;
40 static const int kShutdownId = -2; 40 static const int kShutdownId = -2;
41 41
42 42
43 intptr_t SocketData::GetPollEvents() { 43 intptr_t SocketData::GetPollEvents() {
44 // Do not ask for EPOLLERR and EPOLLHUP explicitly as they are 44 // Do not ask for EPOLLERR and EPOLLHUP explicitly as they are
45 // triggered anyway. 45 // triggered anyway.
46 intptr_t events = EPOLLET | EPOLLRDHUP; 46 intptr_t events = 0;
47 if ((mask_ & (1 << kInEvent)) != 0) { 47 if ((mask_ & (1 << kInEvent)) != 0) {
48 events |= EPOLLIN; 48 events |= EPOLLIN;
49 } 49 }
50 if ((mask_ & (1 << kOutEvent)) != 0) { 50 if ((mask_ & (1 << kOutEvent)) != 0) {
51 events |= EPOLLOUT; 51 events |= EPOLLOUT;
52 } 52 }
53 return events; 53 return events;
54 } 54 }
55 55
56 56
57 // Unregister the file descriptor for a SocketData structure with epoll. 57 // Unregister the file descriptor for a SocketData structure with epoll.
58 static void RemoveFromEpollInstance(intptr_t epoll_fd_, SocketData* sd) { 58 static void RemoveFromEpollInstance(intptr_t epoll_fd_, SocketData* sd) {
59 VOID_NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_, 59 VOID_NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_,
60 EPOLL_CTL_DEL, 60 EPOLL_CTL_DEL,
61 sd->fd(), 61 sd->fd(),
62 NULL)); 62 NULL));
63 } 63 }
64 64
65 65
66 static void AddToEpollInstance(intptr_t epoll_fd_, SocketData* sd) { 66 static void AddToEpollInstance(intptr_t epoll_fd_, SocketData* sd) {
67 struct epoll_event event; 67 struct epoll_event event;
68 event.events = sd->GetPollEvents(); 68 event.events = EPOLLRDHUP | sd->GetPollEvents();
69 if (!sd->IsListeningSocket()) {
70 event.events |= EPOLLET;
71 }
69 event.data.ptr = sd; 72 event.data.ptr = sd;
70 int status = NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_, 73 int status = NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_,
71 EPOLL_CTL_ADD, 74 EPOLL_CTL_ADD,
72 sd->fd(), 75 sd->fd(),
73 &event)); 76 &event));
74 if (status == -1) { 77 if (status == -1) {
75 // Epoll does not accept the file descriptor. It could be due to 78 // Epoll does not accept the file descriptor. It could be due to
76 // already closed file descriptor, or unuspported devices, such 79 // already closed file descriptor, or unuspported devices, such
77 // as /dev/null. In such case, mark the file descriptor as closed, 80 // as /dev/null. In such case, mark the file descriptor as closed,
78 // so dart will handle it accordingly. 81 // so dart will handle it accordingly.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, 248 void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
246 int size) { 249 int size) {
247 bool interrupt_seen = false; 250 bool interrupt_seen = false;
248 for (int i = 0; i < size; i++) { 251 for (int i = 0; i < size; i++) {
249 if (events[i].data.ptr == NULL) { 252 if (events[i].data.ptr == NULL) {
250 interrupt_seen = true; 253 interrupt_seen = true;
251 } else { 254 } else {
252 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr); 255 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr);
253 intptr_t event_mask = GetPollEvents(events[i].events, sd); 256 intptr_t event_mask = GetPollEvents(events[i].events, sd);
254 if (event_mask != 0) { 257 if (event_mask != 0) {
255 if (!sd->IsListeningSocket() && sd->TakeToken()) { 258 if (sd->TakeToken()) {
256 // Took last token, remove from epoll. 259 // Took last token, remove from epoll.
257 RemoveFromEpollInstance(epoll_fd_, sd); 260 RemoveFromEpollInstance(epoll_fd_, sd);
258 } 261 }
259 Dart_Port port = sd->port(); 262 Dart_Port port = sd->port();
260 ASSERT(port != 0); 263 ASSERT(port != 0);
261 DartUtils::PostInt32(port, event_mask); 264 DartUtils::PostInt32(port, event_mask);
262 } 265 }
263 } 266 }
264 } 267 }
265 if (interrupt_seen) { 268 if (interrupt_seen) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 350
348 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 351 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
349 // The hashmap does not support keys with value 0. 352 // The hashmap does not support keys with value 0.
350 return dart::Utils::WordHash(fd + 1); 353 return dart::Utils::WordHash(fd + 1);
351 } 354 }
352 355
353 } // namespace bin 356 } // namespace bin
354 } // namespace dart 357 } // namespace dart
355 358
356 #endif // defined(TARGET_OS_ANDROID) 359 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698