Chromium Code Reviews| 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 #include "bin/eventhandler_linux.h" | |
| 9 | 10 |
| 10 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
| 11 #include <pthread.h> // NOLINT | 12 #include <pthread.h> // NOLINT |
| 12 #include <stdio.h> // NOLINT | 13 #include <stdio.h> // NOLINT |
| 13 #include <string.h> // NOLINT | 14 #include <string.h> // NOLINT |
| 14 #include <sys/epoll.h> // NOLINT | 15 #include <sys/epoll.h> // NOLINT |
| 15 #include <sys/stat.h> // NOLINT | 16 #include <sys/stat.h> // NOLINT |
| 16 #include <sys/timerfd.h> // NOLINT | 17 #include <sys/timerfd.h> // NOLINT |
| 17 #include <unistd.h> // NOLINT | 18 #include <unistd.h> // NOLINT |
| 18 #include <fcntl.h> // NOLINT | 19 #include <fcntl.h> // NOLINT |
| 19 | 20 |
| 20 #include "bin/dartutils.h" | 21 #include "bin/dartutils.h" |
| 21 #include "bin/fdutils.h" | 22 #include "bin/fdutils.h" |
| 22 #include "bin/log.h" | 23 #include "bin/log.h" |
| 24 #include "bin/lockers.h" | |
| 23 #include "bin/socket.h" | 25 #include "bin/socket.h" |
| 24 #include "bin/thread.h" | 26 #include "bin/thread.h" |
| 25 #include "platform/utils.h" | 27 #include "platform/utils.h" |
| 26 | 28 |
| 27 | 29 |
| 28 namespace dart { | 30 namespace dart { |
| 29 namespace bin { | 31 namespace bin { |
| 30 | 32 |
| 31 static const int kInterruptMessageSize = sizeof(InterruptMessage); | 33 static const int kInterruptMessageSize = sizeof(InterruptMessage); |
| 32 static const int kTimerId = -1; | 34 static const int kTimerId = -1; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 ASSERT(!sd->IsListeningSocket()); | 205 ASSERT(!sd->IsListeningSocket()); |
| 204 // Close the socket for reading. | 206 // Close the socket for reading. |
| 205 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_RD)); | 207 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_RD)); |
| 206 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { | 208 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { |
| 207 ASSERT(!sd->IsListeningSocket()); | 209 ASSERT(!sd->IsListeningSocket()); |
| 208 // Close the socket for writing. | 210 // Close the socket for writing. |
| 209 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_WR)); | 211 VOID_NO_RETRY_EXPECTED(shutdown(sd->fd(), SHUT_WR)); |
| 210 } else if (IS_COMMAND(msg[i].data, kCloseCommand)) { | 212 } else if (IS_COMMAND(msg[i].data, kCloseCommand)) { |
| 211 // Close the socket and free system resources and move on to next | 213 // Close the socket and free system resources and move on to next |
| 212 // message. | 214 // message. |
| 213 if (sd->RemovePort(msg[i].dart_port)) { | 215 bool no_more_listeners = sd->RemovePort(msg[i].dart_port); |
| 216 if (no_more_listeners) { | |
| 214 RemoveFromEpollInstance(epoll_fd_, sd); | 217 RemoveFromEpollInstance(epoll_fd_, sd); |
| 218 } | |
| 219 | |
| 220 if (sd->IsListeningSocket()) { | |
| 215 intptr_t fd = sd->fd(); | 221 intptr_t fd = sd->fd(); |
| 216 sd->Close(); | 222 // We only close the socket file descriptor from the operating |
| 217 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 223 // system if there are no other dart socket objects which |
| 218 delete sd; | 224 // are listening on the same (address, port) combination. |
| 225 { | |
| 226 MutexLocker ml(globalTcpListeningSocketRegistry.mutex()); | |
| 227 if (globalTcpListeningSocketRegistry.CloseSafe(sd->fd())) { | |
| 228 ASSERT(no_more_listeners); | |
| 229 socket_map_.Remove( | |
| 230 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | |
| 231 sd->Close(); | |
| 232 delete sd; | |
| 233 } | |
| 234 } | |
| 235 } else { | |
| 236 if (no_more_listeners) { | |
| 237 intptr_t fd = sd->fd(); | |
| 238 sd->Close(); | |
|
Søren Gjesse
2015/01/29 09:05:51
Move sd->Close() down below the removal from the m
wibling
2015/01/29 09:42:01
Since it was closed before removal before shouldn'
Søren Gjesse
2015/01/29 10:12:55
As far as I can see this could be a potential bug
kustermann
2015/01/29 11:14:04
Yes, because only one thread owns/touches this, it
| |
| 239 socket_map_.Remove( | |
| 240 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | |
| 241 delete sd; | |
| 242 } | |
| 219 } | 243 } |
| 220 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); | 244 DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent); |
| 221 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { | 245 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { |
| 222 int count = TOKEN_COUNT(msg[i].data); | 246 int count = TOKEN_COUNT(msg[i].data); |
| 223 if (sd->ReturnToken(msg[i].dart_port, count)) { | 247 if (sd->ReturnToken(msg[i].dart_port, count)) { |
| 224 AddToEpollInstance(epoll_fd_, sd); | 248 AddToEpollInstance(epoll_fd_, sd); |
| 225 } | 249 } |
| 226 } else { | 250 } else { |
| 227 ASSERT_NO_COMMAND(msg[i].data); | 251 ASSERT_NO_COMMAND(msg[i].data); |
| 228 // Setup events to wait for. | 252 // Setup events to wait for. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 | 384 |
| 361 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 385 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 362 // The hashmap does not support keys with value 0. | 386 // The hashmap does not support keys with value 0. |
| 363 return dart::Utils::WordHash(fd + 1); | 387 return dart::Utils::WordHash(fd + 1); |
| 364 } | 388 } |
| 365 | 389 |
| 366 } // namespace bin | 390 } // namespace bin |
| 367 } // namespace dart | 391 } // namespace dart |
| 368 | 392 |
| 369 #endif // defined(TARGET_OS_LINUX) | 393 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |