| 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 "bin/eventhandler.h" | 5 #include "bin/eventhandler.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <sys/event.h> | 11 #include <sys/event.h> |
| 12 #include <sys/time.h> | 12 #include <sys/time.h> |
| 13 #include <unistd.h> | 13 #include <unistd.h> |
| 14 | 14 |
| 15 #include "bin/dartutils.h" | 15 #include "bin/dartutils.h" |
| 16 #include "bin/fdutils.h" | 16 #include "bin/fdutils.h" |
| 17 #include "bin/log.h" |
| 17 #include "platform/hashmap.h" | 18 #include "platform/hashmap.h" |
| 18 #include "platform/thread.h" | 19 #include "platform/thread.h" |
| 19 #include "platform/utils.h" | 20 #include "platform/utils.h" |
| 20 | 21 |
| 21 | 22 |
| 22 int64_t GetCurrentTimeMilliseconds() { | 23 int64_t GetCurrentTimeMilliseconds() { |
| 23 struct timeval tv; | 24 struct timeval tv; |
| 24 if (gettimeofday(&tv, NULL) < 0) { | 25 if (gettimeofday(&tv, NULL) < 0) { |
| 25 UNREACHABLE(); | 26 UNREACHABLE(); |
| 26 return 0; | 27 return 0; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Setup events to wait for. | 234 // Setup events to wait for. |
| 234 sd->SetPortAndMask(msg.dart_port, msg.data); | 235 sd->SetPortAndMask(msg.dart_port, msg.data); |
| 235 UpdateKqueue(kqueue_fd_, sd); | 236 UpdateKqueue(kqueue_fd_, sd); |
| 236 } | 237 } |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 } | 240 } |
| 240 | 241 |
| 241 #ifdef DEBUG_KQUEUE | 242 #ifdef DEBUG_KQUEUE |
| 242 static void PrintEventMask(intptr_t fd, struct kevent* event) { | 243 static void PrintEventMask(intptr_t fd, struct kevent* event) { |
| 243 printf("%d ", static_cast<int>(fd)); | 244 Log::Print("%d ", static_cast<int>(fd)); |
| 244 if (event->filter == EVFILT_READ) printf("EVFILT_READ "); | 245 if (event->filter == EVFILT_READ) Log::Print("EVFILT_READ "); |
| 245 if (event->filter == EVFILT_WRITE) printf("EVFILT_WRITE "); | 246 if (event->filter == EVFILT_WRITE) Log::Print("EVFILT_WRITE "); |
| 246 printf("flags: %x: ", event->flags); | 247 Log::Print("flags: %x: ", event->flags); |
| 247 if ((event->flags & EV_EOF) != 0) printf("EV_EOF "); | 248 if ((event->flags & EV_EOF) != 0) Log::Print("EV_EOF "); |
| 248 if ((event->flags & EV_ERROR) != 0) printf("EV_ERROR "); | 249 if ((event->flags & EV_ERROR) != 0) Log::Print("EV_ERROR "); |
| 249 printf("- fflags: %d ", event->fflags); | 250 Log::Print("- fflags: %d ", event->fflags); |
| 250 printf("(available %d) ", static_cast<int>(FDUtils::AvailableBytes(fd))); | 251 Log::Print("(available %d) ", |
| 251 printf("\n"); | 252 static_cast<int>(FDUtils::AvailableBytes(fd))); |
| 253 Log::Print("\n"); |
| 252 } | 254 } |
| 253 #endif | 255 #endif |
| 254 | 256 |
| 255 | 257 |
| 256 intptr_t EventHandlerImplementation::GetEvents(struct kevent* event, | 258 intptr_t EventHandlerImplementation::GetEvents(struct kevent* event, |
| 257 SocketData* sd) { | 259 SocketData* sd) { |
| 258 #ifdef DEBUG_KQUEUE | 260 #ifdef DEBUG_KQUEUE |
| 259 PrintEventMask(sd->fd(), event); | 261 PrintEventMask(sd->fd(), event); |
| 260 #endif | 262 #endif |
| 261 intptr_t event_mask = 0; | 263 intptr_t event_mask = 0; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { | 415 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { |
| 414 // The hashmap does not support keys with value 0. | 416 // The hashmap does not support keys with value 0. |
| 415 return reinterpret_cast<void*>(fd + 1); | 417 return reinterpret_cast<void*>(fd + 1); |
| 416 } | 418 } |
| 417 | 419 |
| 418 | 420 |
| 419 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 421 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 420 // The hashmap does not support keys with value 0. | 422 // The hashmap does not support keys with value 0. |
| 421 return dart::Utils::WordHash(fd + 1); | 423 return dart::Utils::WordHash(fd + 1); |
| 422 } | 424 } |
| OLD | NEW |