|
|
|
@ -120,7 +120,7 @@ Server::Server(grpc_server *server) : wrapped_server(server) { |
|
|
|
|
Server::~Server() { |
|
|
|
|
this->ShutdownServer(); |
|
|
|
|
grpc_completion_queue_shutdown(this->shutdown_queue); |
|
|
|
|
grpc_server_destroy(wrapped_server); |
|
|
|
|
grpc_server_destroy(this->wrapped_server); |
|
|
|
|
grpc_completion_queue_destroy(this->shutdown_queue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -139,8 +139,11 @@ void Server::Init(Handle<Object> exports) { |
|
|
|
|
NanSetPrototypeTemplate(tpl, "start", |
|
|
|
|
NanNew<FunctionTemplate>(Start)->GetFunction()); |
|
|
|
|
|
|
|
|
|
NanSetPrototypeTemplate(tpl, "shutdown", |
|
|
|
|
NanNew<FunctionTemplate>(Shutdown)->GetFunction()); |
|
|
|
|
NanSetPrototypeTemplate(tpl, "tryShutdown", |
|
|
|
|
NanNew<FunctionTemplate>(TryShutdown)->GetFunction()); |
|
|
|
|
NanSetPrototypeTemplate( |
|
|
|
|
tpl, "forceShutdown", |
|
|
|
|
NanNew<FunctionTemplate>(ForceShutdown)->GetFunction()); |
|
|
|
|
|
|
|
|
|
NanAssignPersistent(fun_tpl, tpl); |
|
|
|
|
Handle<Function> ctr = tpl->GetFunction(); |
|
|
|
@ -153,14 +156,12 @@ bool Server::HasInstance(Handle<Value> val) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Server::ShutdownServer() { |
|
|
|
|
if (this->wrapped_server != NULL) { |
|
|
|
|
grpc_server_shutdown_and_notify(this->wrapped_server, |
|
|
|
|
this->shutdown_queue, |
|
|
|
|
NULL); |
|
|
|
|
grpc_completion_queue_pluck(this->shutdown_queue, NULL, |
|
|
|
|
gpr_inf_future(GPR_CLOCK_REALTIME), NULL); |
|
|
|
|
this->wrapped_server = NULL; |
|
|
|
|
} |
|
|
|
|
grpc_server_shutdown_and_notify(this->wrapped_server, |
|
|
|
|
this->shutdown_queue, |
|
|
|
|
NULL); |
|
|
|
|
grpc_server_cancel_all_calls(this->wrapped_server); |
|
|
|
|
grpc_completion_queue_pluck(this->shutdown_queue, NULL, |
|
|
|
|
gpr_inf_future(GPR_CLOCK_REALTIME), NULL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NAN_METHOD(Server::New) { |
|
|
|
@ -222,9 +223,6 @@ NAN_METHOD(Server::RequestCall) { |
|
|
|
|
return NanThrowTypeError("requestCall can only be called on a Server"); |
|
|
|
|
} |
|
|
|
|
Server *server = ObjectWrap::Unwrap<Server>(args.This()); |
|
|
|
|
if (server->wrapped_server == NULL) { |
|
|
|
|
return NanThrowError("requestCall cannot be called on a shut down Server"); |
|
|
|
|
} |
|
|
|
|
NewCallOp *op = new NewCallOp(); |
|
|
|
|
unique_ptr<OpVec> ops(new OpVec()); |
|
|
|
|
ops->push_back(unique_ptr<Op>(op)); |
|
|
|
@ -256,10 +254,6 @@ NAN_METHOD(Server::AddHttp2Port) { |
|
|
|
|
"addHttp2Port's second argument must be ServerCredentials"); |
|
|
|
|
} |
|
|
|
|
Server *server = ObjectWrap::Unwrap<Server>(args.This()); |
|
|
|
|
if (server->wrapped_server == NULL) { |
|
|
|
|
return NanThrowError( |
|
|
|
|
"addHttp2Port cannot be called on a shut down Server"); |
|
|
|
|
} |
|
|
|
|
ServerCredentials *creds_object = ObjectWrap::Unwrap<ServerCredentials>( |
|
|
|
|
args[1]->ToObject()); |
|
|
|
|
grpc_server_credentials *creds = creds_object->GetWrappedServerCredentials(); |
|
|
|
@ -281,21 +275,30 @@ NAN_METHOD(Server::Start) { |
|
|
|
|
return NanThrowTypeError("start can only be called on a Server"); |
|
|
|
|
} |
|
|
|
|
Server *server = ObjectWrap::Unwrap<Server>(args.This()); |
|
|
|
|
if (server->wrapped_server == NULL) { |
|
|
|
|
return NanThrowError("start cannot be called on a shut down Server"); |
|
|
|
|
} |
|
|
|
|
grpc_server_start(server->wrapped_server); |
|
|
|
|
NanReturnUndefined(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NAN_METHOD(ShutdownCallback) { |
|
|
|
|
NAN_METHOD(Server::TryShutdown) { |
|
|
|
|
NanScope(); |
|
|
|
|
if (!HasInstance(args.This())) { |
|
|
|
|
return NanThrowTypeError("tryShutdown can only be called on a Server"); |
|
|
|
|
} |
|
|
|
|
Server *server = ObjectWrap::Unwrap<Server>(args.This()); |
|
|
|
|
unique_ptr<OpVec> ops(new OpVec()); |
|
|
|
|
grpc_server_shutdown_and_notify( |
|
|
|
|
server->wrapped_server, |
|
|
|
|
CompletionQueueAsyncWorker::GetQueue(), |
|
|
|
|
new struct tag(new NanCallback(args[0].As<Function>()), ops.release(), |
|
|
|
|
shared_ptr<Resources>(nullptr))); |
|
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
|
NanReturnUndefined(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NAN_METHOD(Server::Shutdown) { |
|
|
|
|
NAN_METHOD(Server::ForceShutdown) { |
|
|
|
|
NanScope(); |
|
|
|
|
if (!HasInstance(args.This())) { |
|
|
|
|
return NanThrowTypeError("shutdown can only be called on a Server"); |
|
|
|
|
return NanThrowTypeError("forceShutdown can only be called on a Server"); |
|
|
|
|
} |
|
|
|
|
Server *server = ObjectWrap::Unwrap<Server>(args.This()); |
|
|
|
|
server->ShutdownServer(); |
|
|
|
|