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

Side by Side Diff: runtime/bin/eventhandler_linux.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 | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_macos.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_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 18 matching lines...) Expand all
29 namespace bin { 29 namespace bin {
30 30
31 static const int kInterruptMessageSize = sizeof(InterruptMessage); 31 static const int kInterruptMessageSize = sizeof(InterruptMessage);
32 static const int kTimerId = -1; 32 static const int kTimerId = -1;
33 static const int kShutdownId = -2; 33 static const int kShutdownId = -2;
34 34
35 35
36 intptr_t SocketData::GetPollEvents() { 36 intptr_t SocketData::GetPollEvents() {
37 // Do not ask for EPOLLERR and EPOLLHUP explicitly as they are 37 // Do not ask for EPOLLERR and EPOLLHUP explicitly as they are
38 // triggered anyway. 38 // triggered anyway.
39 intptr_t events = EPOLLET | EPOLLRDHUP; 39 intptr_t events = 0;
40 if ((mask_ & (1 << kInEvent)) != 0) { 40 if ((mask_ & (1 << kInEvent)) != 0) {
41 events |= EPOLLIN; 41 events |= EPOLLIN;
42 } 42 }
43 if ((mask_ & (1 << kOutEvent)) != 0) { 43 if ((mask_ & (1 << kOutEvent)) != 0) {
44 events |= EPOLLOUT; 44 events |= EPOLLOUT;
45 } 45 }
46 return events; 46 return events;
47 } 47 }
48 48
49 49
50 // Unregister the file descriptor for a SocketData structure with epoll. 50 // Unregister the file descriptor for a SocketData structure with epoll.
51 static void RemoveFromEpollInstance(intptr_t epoll_fd_, SocketData* sd) { 51 static void RemoveFromEpollInstance(intptr_t epoll_fd_, SocketData* sd) {
52 VOID_NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_, 52 VOID_NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_,
53 EPOLL_CTL_DEL, 53 EPOLL_CTL_DEL,
54 sd->fd(), 54 sd->fd(),
55 NULL)); 55 NULL));
56 } 56 }
57 57
58 58
59 static void AddToEpollInstance(intptr_t epoll_fd_, SocketData* sd) { 59 static void AddToEpollInstance(intptr_t epoll_fd_, SocketData* sd) {
60 struct epoll_event event; 60 struct epoll_event event;
61 event.events = sd->GetPollEvents(); 61 event.events = EPOLLRDHUP | sd->GetPollEvents();
62 if (!sd->IsListeningSocket()) {
63 event.events |= EPOLLET;
64 }
62 event.data.ptr = sd; 65 event.data.ptr = sd;
63 int status = NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_, 66 int status = NO_RETRY_EXPECTED(epoll_ctl(epoll_fd_,
64 EPOLL_CTL_ADD, 67 EPOLL_CTL_ADD,
65 sd->fd(), 68 sd->fd(),
66 &event)); 69 &event));
67 if (status == -1) { 70 if (status == -1) {
68 // Epoll does not accept the file descriptor. It could be due to 71 // Epoll does not accept the file descriptor. It could be due to
69 // already closed file descriptor, or unuspported devices, such 72 // already closed file descriptor, or unuspported devices, such
70 // as /dev/null. In such case, mark the file descriptor as closed, 73 // as /dev/null. In such case, mark the file descriptor as closed,
71 // so dart will handle it accordingly. 74 // so dart will handle it accordingly.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER( 275 VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
273 read(timer_fd_, &val, sizeof(val))); 276 read(timer_fd_, &val, sizeof(val)));
274 if (timeout_queue_.HasTimeout()) { 277 if (timeout_queue_.HasTimeout()) {
275 DartUtils::PostNull(timeout_queue_.CurrentPort()); 278 DartUtils::PostNull(timeout_queue_.CurrentPort());
276 timeout_queue_.RemoveCurrent(); 279 timeout_queue_.RemoveCurrent();
277 } 280 }
278 } else { 281 } else {
279 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr); 282 SocketData* sd = reinterpret_cast<SocketData*>(events[i].data.ptr);
280 intptr_t event_mask = GetPollEvents(events[i].events, sd); 283 intptr_t event_mask = GetPollEvents(events[i].events, sd);
281 if (event_mask != 0) { 284 if (event_mask != 0) {
282 if (!sd->IsListeningSocket() && sd->TakeToken()) { 285 if (sd->TakeToken()) {
283 // Took last token, remove from epoll. 286 // Took last token, remove from epoll.
284 RemoveFromEpollInstance(epoll_fd_, sd); 287 RemoveFromEpollInstance(epoll_fd_, sd);
285 } 288 }
286 Dart_Port port = sd->port(); 289 Dart_Port port = sd->port();
287 ASSERT(port != 0); 290 ASSERT(port != 0);
288 DartUtils::PostInt32(port, event_mask); 291 DartUtils::PostInt32(port, event_mask);
289 } 292 }
290 } 293 }
291 } 294 }
292 if (interrupt_seen) { 295 if (interrupt_seen) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 352
350 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 353 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
351 // The hashmap does not support keys with value 0. 354 // The hashmap does not support keys with value 0.
352 return dart::Utils::WordHash(fd + 1); 355 return dart::Utils::WordHash(fd + 1);
353 } 356 }
354 357
355 } // namespace bin 358 } // namespace bin
356 } // namespace dart 359 } // namespace dart
357 360
358 #endif // defined(TARGET_OS_LINUX) 361 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698