0d501ad53d
This change add the ability to restart the vm through the service protocol. All isolates are killed, and then the main isolate is restarted cooperatively by the embedder. This change also fixes the message handler to prevent it from accidentally ignoring vm shutdown messages. Previously, we would stop handling messages whenever we hit an error (such as a compile error or an unhandled exception). This would leave shutdown requests sitting the oob queue, neglected. We now process *all* oob requests, up to the first shutdown request. When we hit a shutdown request, we clear the oob queue and process no more messages. To make all of this work, we had to change the return value of HandleMessage from bool to a new enum type, allowing the message handler to distinguish *normal* error cases from the more rarified shutdown and restart cases. R=johnmccutchan@google.com, zra@google.com Review URL: https://codereview.chromium.org/1371193005 .
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
// Copyright (c) 2012, 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 "vm/native_message_handler.h"
|
|
|
|
#include "vm/dart_api_message.h"
|
|
#include "vm/isolate.h"
|
|
#include "vm/message.h"
|
|
#include "vm/snapshot.h"
|
|
|
|
namespace dart {
|
|
|
|
NativeMessageHandler::NativeMessageHandler(const char* name,
|
|
Dart_NativeMessageHandler func)
|
|
: name_(strdup(name)),
|
|
func_(func) {
|
|
// A NativeMessageHandler always has one live port.
|
|
increment_live_ports();
|
|
}
|
|
|
|
|
|
NativeMessageHandler::~NativeMessageHandler() {
|
|
free(name_);
|
|
}
|
|
|
|
|
|
#if defined(DEBUG)
|
|
void NativeMessageHandler::CheckAccess() {
|
|
ASSERT(Isolate::Current() == NULL);
|
|
}
|
|
#endif
|
|
|
|
|
|
MessageHandler::MessageStatus NativeMessageHandler::HandleMessage(
|
|
Message* message) {
|
|
if (message->IsOOB()) {
|
|
// We currently do not use OOB messages for native ports.
|
|
UNREACHABLE();
|
|
}
|
|
// We create a native scope for handling the message.
|
|
// All allocation of objects for decoding the message is done in the
|
|
// zone associated with this scope.
|
|
ApiNativeScope scope;
|
|
ApiMessageReader reader(message->data(), message->len());
|
|
Dart_CObject* object = reader.ReadMessage();
|
|
(*func())(message->dest_port(), object);
|
|
delete message;
|
|
return kOK;
|
|
}
|
|
|
|
} // namespace dart
|