| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 it.it_value.tv_sec = millis / 1000; | 192 it.it_value.tv_sec = millis / 1000; |
| 193 it.it_value.tv_nsec = (millis % 1000) * 1000000; | 193 it.it_value.tv_nsec = (millis % 1000) * 1000000; |
| 194 } | 194 } |
| 195 VOID_NO_RETRY_EXPECTED( | 195 VOID_NO_RETRY_EXPECTED( |
| 196 timerfd_settime(timer_fd_, TFD_TIMER_ABSTIME, &it, NULL)); | 196 timerfd_settime(timer_fd_, TFD_TIMER_ABSTIME, &it, NULL)); |
| 197 } else if (msg[i].id == kShutdownId) { | 197 } else if (msg[i].id == kShutdownId) { |
| 198 shutdown_ = true; | 198 shutdown_ = true; |
| 199 } else { | 199 } else { |
| 200 SocketData* sd = GetSocketData( | 200 SocketData* sd = GetSocketData( |
| 201 msg[i].id, (msg[i].data & (1 << kListeningSocket)) != 0); | 201 msg[i].id, (msg[i].data & (1 << kListeningSocket)) != 0); |
| 202 if ((msg[i].data & (1 << kShutdownReadCommand)) != 0) { | 202 if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { |
| 203 ASSERT(msg[i].data == (1 << kShutdownReadCommand)); | |
| 204 ASSERT(!sd->IsListeningSocket()); | 203 ASSERT(!sd->IsListeningSocket()); |
| 205 // Close the socket for reading. | 204 // Close the socket for reading. |
| 206 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_RD)); | 205 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_RD)); |
| 207 } else if ((msg[i].data & (1 << kShutdownWriteCommand)) != 0) { | 206 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { |
| 208 ASSERT(msg[i].data == (1 << kShutdownWriteCommand)); | |
| 209 ASSERT(!sd->IsListeningSocket()); | 207 ASSERT(!sd->IsListeningSocket()); |
| 210 // Close the socket for writing. | 208 // Close the socket for writing. |
| 211 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_WR)); | 209 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_WR)); |
| 212 } else if ((msg[i].data & (1 << kCloseCommand)) != 0) { | 210 } else if (IS_COMMAND(msg[i].data, kCloseCommand)) { |
| 213 ASSERT(msg[i].data == (1 << kCloseCommand)); | 211 // Close the socket and free system resources and move on to next |
| 214 // Close the socket and free system resources and move on to | 212 // message. |
| 215 // next message. | |
| 216 if (sd->RemovePort(msg[i].dart_port)) { | 213 if (sd->RemovePort(msg[i].dart_port)) { |
| 217 RemoveFromEpollInstance(epoll_fd_, sd); | 214 RemoveFromEpollInstance(epoll_fd_, sd); |
| 218 intptr_t fd = sd->fd(); | 215 intptr_t fd = sd->fd(); |
| 219 sd->Close(); | 216 sd->Close(); |
| 220 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 217 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 221 delete sd; | 218 delete sd; |
| 222 } | 219 } |
| 223 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); | 220 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); |
| 224 } else if ((msg[i].data & (1 << kReturnTokenCommand)) != 0) { | 221 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { |
| 225 int count = msg[i].data & ((1 << kReturnTokenCommand) - 1); | 222 int count = TOKEN_COUNT(msg[i].data); |
| 226 if (sd->ReturnToken(msg[i].dart_port, count)) { | 223 if (sd->ReturnToken(msg[i].dart_port, count)) { |
| 227 AddToEpollInstance(epoll_fd_, sd); | 224 AddToEpollInstance(epoll_fd_, sd); |
| 228 } | 225 } |
| 229 } else { | 226 } else { |
| 227 ASSERT_NO_COMMAND(msg[i].data); |
| 230 // Setup events to wait for. | 228 // Setup events to wait for. |
| 231 if (sd->AddPort(msg[i].dart_port)) { | 229 if (sd->AddPort(msg[i].dart_port)) { |
| 232 sd->SetMask(msg[i].data); | 230 sd->SetMask(msg[i].data); |
| 233 AddToEpollInstance(epoll_fd_, sd); | 231 AddToEpollInstance(epoll_fd_, sd); |
| 234 } | 232 } |
| 235 } | 233 } |
| 236 } | 234 } |
| 237 } | 235 } |
| 238 } | 236 } |
| 239 | 237 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 360 |
| 363 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 361 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 364 // The hashmap does not support keys with value 0. | 362 // The hashmap does not support keys with value 0. |
| 365 return dart::Utils::WordHash(fd + 1); | 363 return dart::Utils::WordHash(fd + 1); |
| 366 } | 364 } |
| 367 | 365 |
| 368 } // namespace bin | 366 } // namespace bin |
| 369 } // namespace dart | 367 } // namespace dart |
| 370 | 368 |
| 371 #endif // defined(TARGET_OS_LINUX) | 369 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |