89dba57bcf
The finalizer sends the "close" message to the EventHandler for the file descriptor in the _NativeSocket's native field. To avoid races and spurious messages, this CL stores a pointer to a wrapper object in the native field instead of the file descriptor. All messsages about the _NativeSocket sent to the EventHandler use the wrapper object instead of the file descriptor. When the EventHandler closes the file, the file descriptor in the wrapper object is set to -1 so that the finalizer will instead do nothing. On Windows, there is another level of indirection since the OS HANDLEs were already wrapped in various kinds of Handle objects. As an additional complication, ClientSocket close on Windows is asynchronous, so the EventHandler may shutdown before all of the ClientSocket Handles can be destroyed. related #27898, #28081 R=johnmccutchan@google.com Review-Url: https://codereview.chromium.org/2760293002 .
43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "bin/error_exit.h"
|
|
|
|
#include "bin/log.h"
|
|
#include "bin/platform.h"
|
|
#include "bin/process.h"
|
|
#include "bin/eventhandler.h"
|
|
#include "include/dart_api.h"
|
|
#include "platform/assert.h"
|
|
#include "platform/globals.h"
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
void ErrorExit(int exit_code, const char* format, ...) {
|
|
va_list arguments;
|
|
va_start(arguments, format);
|
|
Log::VPrintErr(format, arguments);
|
|
va_end(arguments);
|
|
|
|
Dart_ExitScope();
|
|
Dart_ShutdownIsolate();
|
|
|
|
// Terminate process exit-code handler.
|
|
Process::TerminateExitCodeHandler();
|
|
|
|
char* error = Dart_Cleanup();
|
|
if (error != NULL) {
|
|
Log::PrintErr("VM cleanup failed: %s\n", error);
|
|
free(error);
|
|
}
|
|
|
|
Process::ClearAllSignalHandlers();
|
|
EventHandler::Stop();
|
|
Platform::Exit(exit_code);
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|