| OLD | NEW |
| 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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // connections ready to be accepted. | 266 // connections ready to be accepted. |
| 267 if (event->filter == EVFILT_READ) { | 267 if (event->filter == EVFILT_READ) { |
| 268 if ((event->flags & EV_EOF) != 0) { | 268 if ((event->flags & EV_EOF) != 0) { |
| 269 if (event->fflags != 0) { | 269 if (event->fflags != 0) { |
| 270 event_mask |= (1 << kErrorEvent); | 270 event_mask |= (1 << kErrorEvent); |
| 271 } else { | 271 } else { |
| 272 event_mask |= (1 << kCloseEvent); | 272 event_mask |= (1 << kCloseEvent); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 if (event_mask == 0) event_mask |= (1 << kInEvent); | 275 if (event_mask == 0) event_mask |= (1 << kInEvent); |
| 276 } else { |
| 277 UNREACHABLE(); |
| 276 } | 278 } |
| 277 } else { | 279 } else { |
| 278 // Prioritize data events over close and error events. | 280 // Prioritize data events over close and error events. |
| 279 if (event->filter == EVFILT_READ) { | 281 if (event->filter == EVFILT_READ) { |
| 280 if (FDUtils::AvailableBytes(sd->fd()) != 0) { | 282 if (FDUtils::AvailableBytes(sd->fd()) != 0) { |
| 281 event_mask = (1 << kInEvent); | 283 event_mask = (1 << kInEvent); |
| 282 } else if ((event->flags & EV_EOF) != 0) { | 284 } else if ((event->flags & EV_EOF) != 0) { |
| 283 if (event->fflags != 0) { | 285 if (event->fflags != 0) { |
| 284 event_mask |= (1 << kErrorEvent); | 286 event_mask |= (1 << kErrorEvent); |
| 285 } else { | 287 } else { |
| 286 event_mask |= (1 << kCloseEvent); | 288 event_mask |= (1 << kCloseEvent); |
| 287 } | 289 } |
| 288 sd->MarkClosedRead(); | 290 sd->MarkClosedRead(); |
| 289 } | 291 } |
| 290 } | 292 } else if (event->filter == EVFILT_WRITE) { |
| 291 | |
| 292 if (event->filter == EVFILT_WRITE) { | |
| 293 if ((event->flags & EV_EOF) != 0) { | 293 if ((event->flags & EV_EOF) != 0) { |
| 294 if (event->fflags != 0) { | 294 if (event->fflags != 0) { |
| 295 event_mask |= (1 << kErrorEvent); | 295 event_mask |= (1 << kErrorEvent); |
| 296 } else { | 296 } else { |
| 297 event_mask |= (1 << kCloseEvent); | 297 event_mask |= (1 << kCloseEvent); |
| 298 } | 298 } |
| 299 // If the receiver closed for reading, close for writing, | 299 // If the receiver closed for reading, close for writing, |
| 300 // update the registration with kqueue, and do not report a | 300 // update the registration with kqueue, and do not report a |
| 301 // write event. | 301 // write event. |
| 302 sd->MarkClosedWrite(); | 302 sd->MarkClosedWrite(); |
| 303 UpdateKqueue(kqueue_fd_, sd); | 303 UpdateKqueue(kqueue_fd_, sd); |
| 304 } else { | 304 } else { |
| 305 event_mask |= (1 << kOutEvent); | 305 event_mask |= (1 << kOutEvent); |
| 306 } | 306 } |
| 307 } else { |
| 308 UNREACHABLE(); |
| 307 } | 309 } |
| 308 } | 310 } |
| 309 | 311 |
| 310 return event_mask; | 312 return event_mask; |
| 311 } | 313 } |
| 312 | 314 |
| 313 | 315 |
| 314 void EventHandlerImplementation::HandleEvents(struct kevent* events, | 316 void EventHandlerImplementation::HandleEvents(struct kevent* events, |
| 315 int size) { | 317 int size) { |
| 316 for (int i = 0; i < size; i++) { | 318 for (int i = 0; i < size; i++) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return reinterpret_cast<void*>(fd + 1); | 419 return reinterpret_cast<void*>(fd + 1); |
| 418 } | 420 } |
| 419 | 421 |
| 420 | 422 |
| 421 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 423 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 422 // The hashmap does not support keys with value 0. | 424 // The hashmap does not support keys with value 0. |
| 423 return dart::Utils::WordHash(fd + 1); | 425 return dart::Utils::WordHash(fd + 1); |
| 424 } | 426 } |
| 425 | 427 |
| 426 #endif // defined(TARGET_OS_MACOS) | 428 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |