diff --git a/runtime/bin/eventhandler_win.cc b/runtime/bin/eventhandler_win.cc index 3fb27c7ff5b..934c7ca96cd 100644 --- a/runtime/bin/eventhandler_win.cc +++ b/runtime/bin/eventhandler_win.cc @@ -176,17 +176,19 @@ void Handle::Close() { if (!IsClosing()) { // Close the socket and set the closing state. This close method can be // called again if this socket has pending IO operations in flight. - ASSERT(handle_ != INVALID_HANDLE_VALUE); MarkClosing(); // Perform handle type specific closing. DoClose(); } + ASSERT(IsHandleClosed()); } void Handle::DoClose() { - CloseHandle(handle_); - handle_ = INVALID_HANDLE_VALUE; + if (!IsHandleClosed()) { + CloseHandle(handle_); + handle_ = INVALID_HANDLE_VALUE; + } } @@ -424,11 +426,9 @@ void DirectoryWatchHandle::Stop() { if (pending_read_ != NULL) { CancelIoEx(handle(), pending_read_->GetCleanOverlapped()); // Don't dispose of the buffer, as it will still complete (with length 0). - pending_read_ = NULL; } - CloseHandle(handle()); - handle_ = (INVALID_HANDLE_VALUE); + DoClose(); } diff --git a/runtime/bin/eventhandler_win.h b/runtime/bin/eventhandler_win.h index 92741a537e3..121cee43f8e 100644 --- a/runtime/bin/eventhandler_win.h +++ b/runtime/bin/eventhandler_win.h @@ -234,6 +234,8 @@ class Handle { virtual void DoClose(); virtual bool IsClosed() = 0; + bool IsHandleClosed() const { return handle_ == INVALID_HANDLE_VALUE; } + void SetPortAndMask(Dart_Port port, intptr_t mask) { port_ = port; mask_ = mask;