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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 EPOLL_CTL_ADD, | 106 EPOLL_CTL_ADD, |
107 interrupt_fds_[0], | 107 interrupt_fds_[0], |
108 &event)); | 108 &event)); |
109 if (status == -1) { | 109 if (status == -1) { |
110 FATAL("Failed adding interrupt fd to epoll instance"); | 110 FATAL("Failed adding interrupt fd to epoll instance"); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 EventHandlerImplementation::~EventHandlerImplementation() { | 115 EventHandlerImplementation::~EventHandlerImplementation() { |
116 VOID_TEMP_FAILURE_RETRY(close(epoll_fd_)); | |
116 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[0])); | 117 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[0])); |
117 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[1])); | 118 VOID_TEMP_FAILURE_RETRY(close(interrupt_fds_[1])); |
118 } | 119 } |
119 | 120 |
120 | 121 |
121 SocketData* EventHandlerImplementation::GetSocketData(intptr_t fd) { | 122 SocketData* EventHandlerImplementation::GetSocketData( |
123 intptr_t fd, bool listening_socket) { | |
122 ASSERT(fd >= 0); | 124 ASSERT(fd >= 0); |
123 HashMap::Entry* entry = socket_map_.Lookup( | 125 HashMap::Entry* entry = socket_map_.Lookup( |
124 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd), true); | 126 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd), true); |
125 ASSERT(entry != NULL); | 127 ASSERT(entry != NULL); |
126 SocketData* sd = reinterpret_cast<SocketData*>(entry->value); | 128 SocketData* sd = reinterpret_cast<SocketData*>(entry->value); |
127 if (sd == NULL) { | 129 if (sd == NULL) { |
128 // If there is no data in the hash map for this file descriptor a | 130 // If there is no data in the hash map for this file descriptor a |
129 // new SocketData for the file descriptor is inserted. | 131 // new SocketData for the file descriptor is inserted. |
130 sd = new SocketData(fd); | 132 sd = new SocketData(fd, listening_socket); |
131 entry->value = sd; | 133 entry->value = sd; |
132 } | 134 } |
133 ASSERT(fd == sd->fd()); | 135 ASSERT(fd == sd->fd()); |
134 return sd; | 136 return sd; |
135 } | 137 } |
136 | 138 |
137 | 139 |
138 void EventHandlerImplementation::WakeupHandler(intptr_t id, | 140 void EventHandlerImplementation::WakeupHandler(intptr_t id, |
139 Dart_Port dart_port, | 141 Dart_Port dart_port, |
140 int64_t data) { | 142 int64_t data) { |
(...skipping 19 matching lines...) Expand all Loading... | |
160 void EventHandlerImplementation::HandleInterruptFd() { | 162 void EventHandlerImplementation::HandleInterruptFd() { |
161 const intptr_t MAX_MESSAGES = kInterruptMessageSize; | 163 const intptr_t MAX_MESSAGES = kInterruptMessageSize; |
162 InterruptMessage msg[MAX_MESSAGES]; | 164 InterruptMessage msg[MAX_MESSAGES]; |
163 ssize_t bytes = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER( | 165 ssize_t bytes = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER( |
164 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize)); | 166 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize)); |
165 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { | 167 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { |
166 if (msg[i].id == kTimerId) { | 168 if (msg[i].id == kTimerId) { |
167 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); | 169 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); |
168 } else if (msg[i].id == kShutdownId) { | 170 } else if (msg[i].id == kShutdownId) { |
169 shutdown_ = true; | 171 shutdown_ = true; |
170 } else { | 172 } else { |
Søren Gjesse
2015/02/06 08:09:25
Maybe also add an assert that (msg[i].data & COMMA
kustermann
2015/02/06 09:36:47
Done - although I find the UNREACHABLE enough.
Th
| |
171 SocketData* sd = GetSocketData(msg[i].id); | 173 SocketData* sd = GetSocketData( |
174 msg[i].id, (msg[i].data & (1 << kListeningSocket)) != 0); | |
Søren Gjesse
2015/02/06 08:09:25
Maybe add LISTENING_MASK (defined as (1 << kListen
kustermann
2015/02/06 09:36:47
I defined a IS_LISTENING_SOCKET.
| |
172 | 175 |
173 if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { | 176 if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { |
174 // Close the socket for reading. | 177 // Close the socket for reading. |
175 shutdown(sd->fd(), SHUT_RD); | 178 shutdown(sd->fd(), SHUT_RD); |
176 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { | 179 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { |
177 // Close the socket for writing. | 180 // Close the socket for writing. |
178 shutdown(sd->fd(), SHUT_WR); | 181 shutdown(sd->fd(), SHUT_WR); |
179 } else if (IS_COMMAND(msg[i].data, kCloseCommand)) { | 182 } else if (IS_COMMAND(msg[i].data, kCloseCommand)) { |
180 // Close the socket and free system resources and move on to | 183 // Close the socket and free system resources and move on to |
181 // next message. | 184 // next message. |
182 RemoveFromEpollInstance(epoll_fd_, sd); | 185 RemoveFromEpollInstance(epoll_fd_, sd); |
183 intptr_t fd = sd->fd(); | 186 intptr_t fd = sd->fd(); |
184 sd->Close(); | 187 sd->Close(); |
185 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 188 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
186 delete sd; | 189 delete sd; |
187 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); | 190 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); |
188 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { | 191 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { |
189 int count = TOKEN_COUNT(msg[i].data); | 192 int count = TOKEN_COUNT(msg[i].data); |
190 | 193 |
191 for (int i = 0; i < count; i++) { | 194 for (int i = 0; i < count; i++) { |
192 if (sd->ReturnToken()) { | 195 if (sd->ReturnToken()) { |
193 AddToEpollInstance(epoll_fd_, sd); | 196 AddToEpollInstance(epoll_fd_, sd); |
194 } | 197 } |
195 } | 198 } |
199 } else if (IS_COMMAND(msg[i].data, kSetEventMaskCommand)) { | |
200 // `events` can only have kInEvent/kOutEvent flags set. | |
201 intptr_t events = msg[i].data & EVENT_MASK; | |
202 ASSERT(0 == (events & ~(1 << kInEvent) & ~(1 << kOutEvent))); | |
Søren Gjesse
2015/02/06 08:09:25
I think
(events & ~(1 << kInEvent) | 1 << kOutEve
kustermann
2015/02/06 09:36:47
Done.
| |
203 | |
204 // Setup events to wait for. | |
205 sd->SetPortAndMask(msg[i].dart_port, events); | |
206 AddToEpollInstance(epoll_fd_, sd); | |
196 } else { | 207 } else { |
197 ASSERT_NO_COMMAND(msg[i].data); | 208 UNREACHABLE(); |
198 // Setup events to wait for. | |
199 sd->SetPortAndMask(msg[i].dart_port, msg[i].data); | |
200 AddToEpollInstance(epoll_fd_, sd); | |
201 } | 209 } |
202 } | 210 } |
203 } | 211 } |
204 } | 212 } |
205 | 213 |
206 #ifdef DEBUG_POLL | 214 #ifdef DEBUG_POLL |
207 static void PrintEventMask(intptr_t fd, intptr_t events) { | 215 static void PrintEventMask(intptr_t fd, intptr_t events) { |
208 Log::Print("%d ", fd); | 216 Log::Print("%d ", fd); |
209 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); | 217 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN "); |
210 if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI "); | 218 if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI "); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 | 355 |
348 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 356 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
349 // The hashmap does not support keys with value 0. | 357 // The hashmap does not support keys with value 0. |
350 return dart::Utils::WordHash(fd + 1); | 358 return dart::Utils::WordHash(fd + 1); |
351 } | 359 } |
352 | 360 |
353 } // namespace bin | 361 } // namespace bin |
354 } // namespace dart | 362 } // namespace dart |
355 | 363 |
356 #endif // defined(TARGET_OS_ANDROID) | 364 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |