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

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

Issue 167193004: Remove 'mask' from SocketData, as it's not required. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | « runtime/bin/eventhandler_linux.h ('k') | no next file » | 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 30 matching lines...) Expand all
41 EPOLL_CTL_DEL, 41 EPOLL_CTL_DEL,
42 sd->fd(), 42 sd->fd(),
43 NULL)); 43 NULL));
44 if (status == -1) { 44 if (status == -1) {
45 FATAL("Failed unregistering events for file descriptor"); 45 FATAL("Failed unregistering events for file descriptor");
46 } 46 }
47 sd->set_tracked_by_epoll(false); 47 sd->set_tracked_by_epoll(false);
48 } 48 }
49 49
50 50
51 static void AddToEpollInstance(intptr_t epoll_fd_, SocketData* sd) { 51 static void AddToEpollInstance(intptr_t epoll_fd_, SocketData* sd, int mask) {
52 ASSERT(!sd->tracked_by_epoll()); 52 ASSERT(!sd->tracked_by_epoll());
53 struct epoll_event event; 53 struct epoll_event event;
54 event.events = EPOLLET | EPOLLRDHUP; 54 event.events = EPOLLET | EPOLLRDHUP;
55 if ((sd->mask() & (1 << kInEvent)) != 0) event.events |= EPOLLIN; 55 if ((mask & (1 << kInEvent)) != 0) event.events |= EPOLLIN;
56 if ((sd->mask() & (1 << kOutEvent)) != 0) event.events |= EPOLLOUT; 56 if ((mask & (1 << kOutEvent)) != 0) event.events |= EPOLLOUT;
57 event.data.ptr = sd; 57 event.data.ptr = sd;
58 int status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, 58 int status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_,
59 EPOLL_CTL_ADD, 59 EPOLL_CTL_ADD,
60 sd->fd(), 60 sd->fd(),
61 &event)); 61 &event));
62 if (status == -1) { 62 if (status == -1) {
63 // Epoll does not accept the file descriptor. It could be due to 63 // Epoll does not accept the file descriptor. It could be due to
64 // already closed file descriptor, or unuspported devices, such 64 // already closed file descriptor, or unuspported devices, such
65 // as /dev/null. In such case, mark the file descriptor as closed, 65 // as /dev/null. In such case, mark the file descriptor as closed,
66 // so dart will handle it accordingly. 66 // so dart will handle it accordingly.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 it.it_value.tv_sec = millis / 1000; 183 it.it_value.tv_sec = millis / 1000;
184 it.it_value.tv_nsec = (millis % 1000) * 1000000; 184 it.it_value.tv_nsec = (millis % 1000) * 1000000;
185 } 185 }
186 timerfd_settime(timer_fd_, TFD_TIMER_ABSTIME, &it, NULL); 186 timerfd_settime(timer_fd_, TFD_TIMER_ABSTIME, &it, NULL);
187 } else if (msg[i].id == kShutdownId) { 187 } else if (msg[i].id == kShutdownId) {
188 shutdown_ = true; 188 shutdown_ = true;
189 } else { 189 } else {
190 bool is_new = false; 190 bool is_new = false;
191 SocketData* sd = GetSocketData(msg[i].id, &is_new); 191 SocketData* sd = GetSocketData(msg[i].id, &is_new);
192 if (is_new) { 192 if (is_new) {
193 sd->SetPortAndMask(msg[i].dart_port, msg[i].data); 193 sd->SetPort(msg[i].dart_port);
194 AddToEpollInstance(epoll_fd_, sd); 194 AddToEpollInstance(epoll_fd_, sd, msg[i].data);
195 } 195 }
196 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) { 196 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) {
197 ASSERT(msg[i].data == (1 << kShutdownReadCommand)); 197 ASSERT(msg[i].data == (1 << kShutdownReadCommand));
198 // Close the socket for reading. 198 // Close the socket for reading.
199 sd->ShutdownRead(); 199 sd->ShutdownRead();
200 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) { 200 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) {
201 ASSERT(msg[i].data == (1 << kShutdownWriteCommand)); 201 ASSERT(msg[i].data == (1 << kShutdownWriteCommand));
202 // Close the socket for writing. 202 // Close the socket for writing.
203 sd->ShutdownWrite(); 203 sd->ShutdownWrite();
204 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { 204 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) {
(...skipping 25 matching lines...) Expand all
230 if ((events & ~all_events) != 0) { 230 if ((events & ~all_events) != 0) {
231 Log::Print("(and %08x) ", events & ~all_events); 231 Log::Print("(and %08x) ", events & ~all_events);
232 } 232 }
233 Log::Print("(available %d) ", FDUtils::AvailableBytes(fd)); 233 Log::Print("(available %d) ", FDUtils::AvailableBytes(fd));
234 234
235 Log::Print("\n"); 235 Log::Print("\n");
236 } 236 }
237 #endif 237 #endif
238 238
239 intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events, 239 intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events,
240 SocketData* sd) { 240 SocketData* sd) {
Søren Gjesse 2014/02/19 15:53:25 Maybe I am wrong, but it seems like this is now ec
Anders Johnsen 2014/02/19 16:08:29 Done.
241 #ifdef DEBUG_POLL 241 #ifdef DEBUG_POLL
242 PrintEventMask(sd->fd(), events); 242 PrintEventMask(sd->fd(), events);
243 #endif 243 #endif
244 intptr_t event_mask = 0; 244 intptr_t event_mask = 0;
245 if (sd->IsListeningSocket()) { 245 // Prioritize data events over close and error events.
Søren Gjesse 2014/02/19 15:53:25 This comment seems wrong. We are not prioritizing
Anders Johnsen 2014/02/19 16:08:29 Done.
246 // For listening sockets the EPOLLIN event indicate that there are 246 if ((events & (EPOLLIN | EPOLLHUP | EPOLLRDHUP)) != 0) {
Søren Gjesse 2014/02/19 15:53:25 Is this if statement actually needed?
Anders Johnsen 2014/02/19 16:08:29 Done.
247 // connections ready for accept unless accompanied with one of the 247 // If we have EPOLLIN and we have available bytes, report that.
248 // other flags.
249 if ((events & EPOLLIN) != 0) { 248 if ((events & EPOLLIN) != 0) {
250 if ((events & EPOLLHUP) != 0) event_mask |= (1 << kCloseEvent); 249 event_mask = (1 << kInEvent);
251 if ((events & EPOLLERR) != 0) event_mask |= (1 << kErrorEvent);
252 if (event_mask == 0) event_mask |= (1 << kInEvent);
253 } 250 }
254 } else { 251 if ((events & (EPOLLHUP | EPOLLRDHUP)) != 0) {
255 // Prioritize data events over close and error events. 252 // If both EPOLLHUP and EPOLLERR are reported treat it as an
256 if ((events & (EPOLLIN | EPOLLHUP | EPOLLRDHUP)) != 0) { 253 // error.
257 // If we have EPOLLIN and we have available bytes, report that. 254 if ((events & EPOLLERR) != 0) {
258 if ((events & EPOLLIN) != 0) { 255 event_mask = (1 << kErrorEvent);
259 event_mask = (1 << kInEvent); 256 } else {
257 event_mask |= (1 << kCloseEvent);
260 } 258 }
261 if ((events & (EPOLLHUP | EPOLLRDHUP)) != 0) { 259 } else if ((events & EPOLLERR) != 0) {
262 // If both EPOLLHUP and EPOLLERR are reported treat it as an 260 event_mask = (1 << kErrorEvent);
263 // error.
264 if ((events & EPOLLERR) != 0) {
265 event_mask = (1 << kErrorEvent);
266 } else {
267 event_mask |= (1 << kCloseEvent);
268 }
269 } else if ((events & EPOLLERR) != 0) {
270 event_mask = (1 << kErrorEvent);
271 }
272 } 261 }
262 }
273 263
274 if ((events & EPOLLOUT) != 0) { 264 if ((events & EPOLLOUT) != 0 && (events & EPOLLERR) == 0) {
Søren Gjesse 2014/02/19 15:53:25 Can't this move up after line 250?
Anders Johnsen 2014/02/19 16:08:29 Done.
275 if ((events & EPOLLERR) != 0) { 265 event_mask |= (1 << kOutEvent);
276 if (!sd->IsPipe()) {
277 event_mask = (1 << kErrorEvent);
278 }
279 } else {
280 event_mask |= (1 << kOutEvent);
281 }
282 }
283 } 266 }
284 267
285 return event_mask; 268 return event_mask;
286 } 269 }
287 270
288 271
289 void EventHandlerImplementation::HandleEvents(struct epoll_event* events, 272 void EventHandlerImplementation::HandleEvents(struct epoll_event* events,
290 int size) { 273 int size) {
291 bool interrupt_seen = false; 274 bool interrupt_seen = false;
292 for (int i = 0; i < size; i++) { 275 for (int i = 0; i < size; i++) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 353
371 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 354 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
372 // The hashmap does not support keys with value 0. 355 // The hashmap does not support keys with value 0.
373 return dart::Utils::WordHash(fd + 1); 356 return dart::Utils::WordHash(fd + 1);
374 } 357 }
375 358
376 } // namespace bin 359 } // namespace bin
377 } // namespace dart 360 } // namespace dart
378 361
379 #endif // defined(TARGET_OS_LINUX) 362 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698