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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 InterruptMessage msg[MAX_MESSAGES]; | 185 InterruptMessage msg[MAX_MESSAGES]; |
186 ssize_t bytes = TEMP_FAILURE_RETRY( | 186 ssize_t bytes = TEMP_FAILURE_RETRY( |
187 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize)); | 187 read(interrupt_fds_[0], msg, MAX_MESSAGES * kInterruptMessageSize)); |
188 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { | 188 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { |
189 if (msg[i].id == kTimerId) { | 189 if (msg[i].id == kTimerId) { |
190 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); | 190 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); |
191 } else if (msg[i].id == kShutdownId) { | 191 } else if (msg[i].id == kShutdownId) { |
192 shutdown_ = true; | 192 shutdown_ = true; |
193 } else { | 193 } else { |
194 SocketData* sd = GetSocketData(msg[i].id); | 194 SocketData* sd = GetSocketData(msg[i].id); |
195 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) { | 195 if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { |
196 ASSERT(msg[i].data == (1 << kShutdownReadCommand)); | |
197 // Close the socket for reading. | 196 // Close the socket for reading. |
198 shutdown(sd->fd(), SHUT_RD); | 197 shutdown(sd->fd(), SHUT_RD); |
199 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) { | 198 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { |
200 ASSERT(msg[i].data == (1 << kShutdownWriteCommand)); | |
201 // Close the socket for writing. | 199 // Close the socket for writing. |
202 shutdown(sd->fd(), SHUT_WR); | 200 shutdown(sd->fd(), SHUT_WR); |
203 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { | 201 } else if (IS_COMMAND(msg[i].data, kCloseCommand)) { |
204 ASSERT(msg[i].data == (1 << kCloseCommand)); | |
205 // Close the socket and free system resources. | 202 // Close the socket and free system resources. |
206 RemoveFromKqueue(kqueue_fd_, sd); | 203 RemoveFromKqueue(kqueue_fd_, sd); |
207 intptr_t fd = sd->fd(); | 204 intptr_t fd = sd->fd(); |
208 VOID_TEMP_FAILURE_RETRY(close(fd)); | 205 VOID_TEMP_FAILURE_RETRY(close(fd)); |
209 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 206 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
210 delete sd; | 207 delete sd; |
211 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); | 208 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); |
212 } else if ((msg[i].data & (1 << kReturnTokenCommand)) != 0) { | 209 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { |
213 int count = msg[i].data & ((1 << kReturnTokenCommand) - 1); | 210 int count = TOKEN_COUNT(msg[i].data); |
214 for (int i = 0; i < count; i++) { | 211 for (int i = 0; i < count; i++) { |
215 if (sd->ReturnToken()) { | 212 if (sd->ReturnToken()) { |
216 AddToKqueue(kqueue_fd_, sd); | 213 AddToKqueue(kqueue_fd_, sd); |
217 } | 214 } |
218 } | 215 } |
219 } else { | 216 } else { |
| 217 ASSERT_NO_COMMAND(msg[i].data); |
220 // Setup events to wait for. | 218 // Setup events to wait for. |
221 ASSERT((msg[i].data > 0) && (msg[i].data < kIntptrMax)); | 219 ASSERT((msg[i].data > 0) && (msg[i].data < kIntptrMax)); |
222 ASSERT(sd->port() == 0); | 220 ASSERT(sd->port() == 0); |
223 sd->SetPortAndMask(msg[i].dart_port, | 221 sd->SetPortAndMask(msg[i].dart_port, |
224 static_cast<intptr_t>(msg[i].data)); | 222 static_cast<intptr_t>(msg[i].data)); |
225 AddToKqueue(kqueue_fd_, sd); | 223 AddToKqueue(kqueue_fd_, sd); |
226 } | 224 } |
227 } | 225 } |
228 } | 226 } |
229 } | 227 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 421 |
424 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 422 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
425 // The hashmap does not support keys with value 0. | 423 // The hashmap does not support keys with value 0. |
426 return dart::Utils::WordHash(fd + 1); | 424 return dart::Utils::WordHash(fd + 1); |
427 } | 425 } |
428 | 426 |
429 } // namespace bin | 427 } // namespace bin |
430 } // namespace dart | 428 } // namespace dart |
431 | 429 |
432 #endif // defined(TARGET_OS_MACOS) | 430 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |