| 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> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 | 99 |
| 100 EventHandlerImplementation::EventHandlerImplementation() | 100 EventHandlerImplementation::EventHandlerImplementation() |
| 101 : socket_map_(&HashMap::SamePointerValue, 16) { | 101 : socket_map_(&HashMap::SamePointerValue, 16) { |
| 102 intptr_t result; | 102 intptr_t result; |
| 103 result = TEMP_FAILURE_RETRY(pipe(interrupt_fds_)); | 103 result = TEMP_FAILURE_RETRY(pipe(interrupt_fds_)); |
| 104 if (result != 0) { | 104 if (result != 0) { |
| 105 FATAL("Pipe creation failed"); | 105 FATAL("Pipe creation failed"); |
| 106 } | 106 } |
| 107 FDUtils::SetNonBlocking(interrupt_fds_[0]); | 107 FDUtils::SetNonBlocking(interrupt_fds_[0]); |
| 108 FDUtils::SetCloseOnExec(interrupt_fds_[0]); |
| 109 FDUtils::SetCloseOnExec(interrupt_fds_[1]); |
| 108 timeout_ = kInfinityTimeout; | 110 timeout_ = kInfinityTimeout; |
| 109 timeout_port_ = 0; | 111 timeout_port_ = 0; |
| 110 shutdown_ = false; | 112 shutdown_ = false; |
| 111 // The initial size passed to epoll_create is ignore on newer (>= | 113 // The initial size passed to epoll_create is ignore on newer (>= |
| 112 // 2.6.8) Linux versions | 114 // 2.6.8) Linux versions |
| 113 static const int kEpollInitialSize = 64; | 115 static const int kEpollInitialSize = 64; |
| 114 epoll_fd_ = TEMP_FAILURE_RETRY(epoll_create(kEpollInitialSize)); | 116 epoll_fd_ = TEMP_FAILURE_RETRY(epoll_create(kEpollInitialSize)); |
| 115 if (epoll_fd_ == -1) { | 117 if (epoll_fd_ == -1) { |
| 116 FATAL("Failed creating epoll file descriptor"); | 118 FATAL("Failed creating epoll file descriptor"); |
| 117 } | 119 } |
| 120 FDUtils::SetCloseOnExec(epoll_fd_); |
| 118 // Register the interrupt_fd with the epoll instance. | 121 // Register the interrupt_fd with the epoll instance. |
| 119 struct epoll_event event; | 122 struct epoll_event event; |
| 120 event.events = EPOLLIN; | 123 event.events = EPOLLIN; |
| 121 event.data.ptr = NULL; | 124 event.data.ptr = NULL; |
| 122 int status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, | 125 int status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, |
| 123 EPOLL_CTL_ADD, | 126 EPOLL_CTL_ADD, |
| 124 interrupt_fds_[0], | 127 interrupt_fds_[0], |
| 125 &event)); | 128 &event)); |
| 126 if (status == -1) { | 129 if (status == -1) { |
| 127 FATAL("Failed adding interrupt fd to epoll instance"); | 130 FATAL("Failed adding interrupt fd to epoll instance"); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { | 424 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { |
| 422 // The hashmap does not support keys with value 0. | 425 // The hashmap does not support keys with value 0. |
| 423 return reinterpret_cast<void*>(fd + 1); | 426 return reinterpret_cast<void*>(fd + 1); |
| 424 } | 427 } |
| 425 | 428 |
| 426 | 429 |
| 427 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 430 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 428 // The hashmap does not support keys with value 0. | 431 // The hashmap does not support keys with value 0. |
| 429 return dart::Utils::WordHash(fd + 1); | 432 return dart::Utils::WordHash(fd + 1); |
| 430 } | 433 } |
| OLD | NEW |