aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/ext/server.cc
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2017-04-10 15:43:09 -0700
committerGravatar murgatroid99 <mlumish@google.com>2017-04-10 15:43:09 -0700
commit42cfaa99bd3490bb0849fd66aa56016e763a56a8 (patch)
tree6882a327568a1d3b97c419f5f421c252d313eedb /src/node/ext/server.cc
parent79962f33c71e248276486122097e33b038e537df (diff)
Add native tag completion callbacks, dispose of server after tryShutdown succeeds
Diffstat (limited to 'src/node/ext/server.cc')
-rw-r--r--src/node/ext/server.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc
index f0920c842a..22c89c5862 100644
--- a/src/node/ext/server.cc
+++ b/src/node/ext/server.cc
@@ -117,6 +117,8 @@ class NewCallOp : public Op {
bool IsFinalOp() {
return false;
}
+ void OnComplete() {
+ }
grpc_call *call;
grpc_call_details details;
@@ -126,6 +128,32 @@ class NewCallOp : public Op {
std::string GetTypeString() const { return "new_call"; }
};
+class TryShutdownOp: public Op {
+ public:
+ TryShutdownOp(Server *server, Local<Value> server_value) : server(server) {
+ server_persist.Reset(server_value);
+ }
+ Local<Value> GetNodeValue() const {
+ EscapableHandleScope scope;
+ return scope.Escape(Nan::New(server_persist));
+ }
+ bool ParseOp(Local<Value> value, grpc_op *out) {
+ return true;
+ }
+ bool IsFinalOp() {
+ return false;
+ }
+ void OnComplete() {
+ server->DestroyWrappedServer();
+ }
+ protected:
+ std::string GetTypeString() const { return "try_shutdown"; }
+ private:
+ Server *server;
+ Nan::Persistent<v8::Value, Nan::CopyablePersistentTraits<v8::Value>>
+ server_persist;
+};
+
void Server::Init(Local<Object> exports) {
HandleScope scope;
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
@@ -147,6 +175,13 @@ bool Server::HasInstance(Local<Value> val) {
return Nan::New(fun_tpl)->HasInstance(val);
}
+void Server::DestroyWrappedServer() {
+ if (this->wrapped_server != NULL) {
+ grpc_server_destroy(this->wrapped_server);
+ this->wrapped_server = NULL;
+ }
+}
+
NAN_METHOD(Server::New) {
/* If this is not a constructor call, make a constructor call and return
the result */
@@ -242,7 +277,9 @@ NAN_METHOD(Server::TryShutdown) {
return Nan::ThrowTypeError("tryShutdown can only be called on a Server");
}
Server *server = ObjectWrap::Unwrap<Server>(info.This());
+ TryShutdownOp *op = new TryShutdownOp(server, info.This());
unique_ptr<OpVec> ops(new OpVec());
+ ops->push_back(unique_ptr<Op>(op));
grpc_server_shutdown_and_notify(
server->wrapped_server, GetCompletionQueue(),
new struct tag(new Nan::Callback(info[0].As<Function>()), ops.release(),