aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node
diff options
context:
space:
mode:
Diffstat (limited to 'src/node')
-rw-r--r--src/node/ext/call.cc1
-rw-r--r--src/node/ext/channel.cc1
-rw-r--r--src/node/ext/completion_queue.cc (renamed from src/node/ext/completion_queue_uv.cc)4
-rw-r--r--src/node/ext/completion_queue_async_worker.h86
-rw-r--r--src/node/ext/completion_queue_threadpool.cc182
-rw-r--r--src/node/ext/node_grpc.cc5
-rw-r--r--src/node/ext/server.cc59
-rw-r--r--src/node/ext/server_generic.cc73
-rw-r--r--src/node/ext/server_uv.cc131
-rw-r--r--src/node/health_check/package.json4
-rw-r--r--src/node/index.js55
-rw-r--r--src/node/src/protobuf_js_5_common.js10
-rw-r--r--src/node/src/server.js8
-rw-r--r--src/node/test/common_test.js21
-rw-r--r--src/node/test/surface_test.js42
-rw-r--r--src/node/tools/package.json2
16 files changed, 125 insertions, 559 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index bd60775aad..8877995f8f 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -46,7 +46,6 @@
#include "call.h"
#include "channel.h"
#include "completion_queue.h"
-#include "completion_queue_async_worker.h"
#include "call_credentials.h"
#include "slice.h"
#include "timeval.h"
diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc
index 1263cc0d28..2c533f056a 100644
--- a/src/node/ext/channel.cc
+++ b/src/node/ext/channel.cc
@@ -42,7 +42,6 @@
#include "call.h"
#include "channel.h"
#include "completion_queue.h"
-#include "completion_queue_async_worker.h"
#include "channel_credentials.h"
#include "timeval.h"
diff --git a/src/node/ext/completion_queue_uv.cc b/src/node/ext/completion_queue.cc
index 0f6f7da460..a743784c37 100644
--- a/src/node/ext/completion_queue_uv.cc
+++ b/src/node/ext/completion_queue.cc
@@ -31,8 +31,6 @@
*
*/
-#ifdef GRPC_UV
-
#include <uv.h>
#include <node.h>
#include <v8.h>
@@ -97,5 +95,3 @@ void CompletionQueueInit(Local<Object> exports) {
} // namespace node
} // namespace grpc
-
-#endif /* GRPC_UV */
diff --git a/src/node/ext/completion_queue_async_worker.h b/src/node/ext/completion_queue_async_worker.h
deleted file mode 100644
index 6e54116765..0000000000
--- a/src/node/ext/completion_queue_async_worker.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef NET_GRPC_NODE_COMPLETION_QUEUE_ASYNC_WORKER_H_
-#define NET_GRPC_NODE_COMPLETION_QUEUE_ASYNC_WORKER_H_
-#include <nan.h>
-
-#include "grpc/grpc.h"
-
-namespace grpc {
-namespace node {
-
-/* A worker that asynchronously calls completion_queue_next, and queues onto the
- node event loop a call to the function stored in the event's tag. */
-class CompletionQueueAsyncWorker : public Nan::AsyncWorker {
- public:
- CompletionQueueAsyncWorker();
-
- ~CompletionQueueAsyncWorker();
- /* Calls completion_queue_next with the provided deadline, and stores the
- event if there was one or sets an error message if there was not */
- void Execute();
-
- /* Returns the completion queue attached to this class */
- static grpc_completion_queue *GetQueue();
-
- /* Convenience function to create a worker with the given arguments and queue
- it to run asynchronously */
- static void Next();
-
- /* Initialize the CompletionQueueAsyncWorker class */
- static void Init(v8::Local<v8::Object> exports);
-
- protected:
- /* Called when Execute has succeeded (completed without setting an error
- message). Calls the saved callback with the event that came from
- completion_queue_next */
- void HandleOKCallback();
-
- void HandleErrorCallback();
-
- private:
- grpc_event result;
-
- static grpc_completion_queue *queue;
-
- // Number of grpc_completion_queue_next calls in the thread pool
- static int current_threads;
- // Number of grpc_completion_queue_next calls waiting to enter the thread pool
- static int waiting_next_calls;
-};
-
-} // namespace node
-} // namespace grpc
-
-#endif // NET_GRPC_NODE_COMPLETION_QUEUE_ASYNC_WORKER_H_
diff --git a/src/node/ext/completion_queue_threadpool.cc b/src/node/ext/completion_queue_threadpool.cc
deleted file mode 100644
index 7b1bdda033..0000000000
--- a/src/node/ext/completion_queue_threadpool.cc
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/* I don't like using #ifndef, but I don't see a better way to do this */
-#ifndef GRPC_UV
-
-#include <node.h>
-#include <nan.h>
-
-#include "grpc/grpc.h"
-#include "grpc/support/log.h"
-#include "grpc/support/time.h"
-#include "completion_queue.h"
-#include "call.h"
-
-namespace grpc {
-namespace node {
-
-namespace {
-
-/* A worker that asynchronously calls completion_queue_next, and queues onto the
- node event loop a call to the function stored in the event's tag. */
-class CompletionQueueAsyncWorker : public Nan::AsyncWorker {
- public:
- CompletionQueueAsyncWorker();
-
- ~CompletionQueueAsyncWorker();
- /* Calls completion_queue_next with the provided deadline, and stores the
- event if there was one or sets an error message if there was not */
- void Execute();
-
- /* Returns the completion queue attached to this class */
- static grpc_completion_queue *GetQueue();
-
- /* Convenience function to create a worker with the given arguments and queue
- it to run asynchronously */
- static void Next();
-
- /* Initialize the CompletionQueueAsyncWorker class */
- static void Init(v8::Local<v8::Object> exports);
-
- protected:
- /* Called when Execute has succeeded (completed without setting an error
- message). Calls the saved callback with the event that came from
- completion_queue_next */
- void HandleOKCallback();
-
- void HandleErrorCallback();
-
- private:
- static void TryAddWorker();
-
- grpc_event result;
-
- static grpc_completion_queue *queue;
-
- // Number of grpc_completion_queue_next calls in the thread pool
- static int current_threads;
- // Number of grpc_completion_queue_next calls waiting to enter the thread pool
- static int waiting_next_calls;
-};
-
-const int max_queue_threads = 2;
-
-using v8::Function;
-using v8::Local;
-using v8::Object;
-using v8::Value;
-
-grpc_completion_queue *CompletionQueueAsyncWorker::queue;
-
-// Invariants: current_threads <= max_queue_threads
-// (current_threads == max_queue_threads) || (waiting_next_calls == 0)
-
-int CompletionQueueAsyncWorker::current_threads;
-int CompletionQueueAsyncWorker::waiting_next_calls;
-
-CompletionQueueAsyncWorker::CompletionQueueAsyncWorker()
- : Nan::AsyncWorker(NULL) {}
-
-CompletionQueueAsyncWorker::~CompletionQueueAsyncWorker() {}
-
-void CompletionQueueAsyncWorker::Execute() {
- result =
- grpc_completion_queue_next(queue, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
- if (!result.success) {
- SetErrorMessage("The async function encountered an error");
- }
-}
-
-grpc_completion_queue *CompletionQueueAsyncWorker::GetQueue() { return queue; }
-
-void CompletionQueueAsyncWorker::TryAddWorker() {
- if (current_threads < max_queue_threads && waiting_next_calls > 0) {
- current_threads += 1;
- waiting_next_calls -= 1;
- CompletionQueueAsyncWorker *worker = new CompletionQueueAsyncWorker();
- Nan::AsyncQueueWorker(worker);
- }
- GPR_ASSERT(current_threads <= max_queue_threads);
- GPR_ASSERT((current_threads == max_queue_threads) ||
- (waiting_next_calls == 0));
-}
-
-void CompletionQueueAsyncWorker::Next() {
- waiting_next_calls += 1;
- TryAddWorker();
-}
-
-void CompletionQueueAsyncWorker::Init(Local<Object> exports) {
- Nan::HandleScope scope;
- current_threads = 0;
- waiting_next_calls = 0;
- queue = grpc_completion_queue_create(NULL);
-}
-
-void CompletionQueueAsyncWorker::HandleOKCallback() {
- Nan::HandleScope scope;
- current_threads -= 1;
- TryAddWorker();
- CompleteTag(result.tag, NULL);
-
- DestroyTag(result.tag);
-}
-
-void CompletionQueueAsyncWorker::HandleErrorCallback() {
- Nan::HandleScope scope;
- current_threads -= 1;
- TryAddWorker();
- CompleteTag(result.tag, ErrorMessage());
-
- DestroyTag(result.tag);
-}
-
-} // namespace
-
-grpc_completion_queue *GetCompletionQueue() {
- return CompletionQueueAsyncWorker::GetQueue();
-}
-
-void CompletionQueueNext() {
- CompletionQueueAsyncWorker::Next();
-}
-
-void CompletionQueueInit(Local<Object> exports) {
- CompletionQueueAsyncWorker::Init(exports);
-}
-
-} // namespace node
-} // namespace grpc
-
-#endif /* GRPC_UV */
diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc
index 122e5e63ee..f600cb9def 100644
--- a/src/node/ext/node_grpc.cc
+++ b/src/node/ext/node_grpc.cc
@@ -43,18 +43,15 @@
#include "grpc/support/time.h"
// TODO(murgatroid99): Remove this when the endpoint API becomes public
-#ifdef GRPC_UV
extern "C" {
#include "src/core/lib/iomgr/pollset_uv.h"
}
-#endif
#include "call.h"
#include "call_credentials.h"
#include "channel.h"
#include "channel_credentials.h"
#include "server.h"
-#include "completion_queue_async_worker.h"
#include "server_credentials.h"
#include "slice.h"
#include "timeval.h"
@@ -438,9 +435,7 @@ void init(Local<Object> exports) {
InitWriteFlags(exports);
InitLogConstants(exports);
-#ifdef GRPC_UV
grpc_pollset_work_run_loop = 0;
-#endif
grpc::node::Call::Init(exports);
grpc::node::CallCredentials::Init(exports);
diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc
index 5384305631..f7c62a311d 100644
--- a/src/node/ext/server.cc
+++ b/src/node/ext/server.cc
@@ -41,7 +41,6 @@
#include <vector>
#include "call.h"
#include "completion_queue.h"
-#include "completion_queue_async_worker.h"
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
#include "grpc/support/log.h"
@@ -78,6 +77,30 @@ using v8::Value;
Nan::Callback *Server::constructor;
Persistent<FunctionTemplate> Server::fun_tpl;
+static Callback *shutdown_callback = NULL;
+
+class ServerShutdownOp : public Op {
+ public:
+ ServerShutdownOp(grpc_server *server) : server(server) {}
+
+ ~ServerShutdownOp() {}
+
+ Local<Value> GetNodeValue() const { return Nan::Null(); }
+
+ bool ParseOp(Local<Value> value, grpc_op *out) { return true; }
+ bool IsFinalOp() { return false; }
+ void OnComplete(bool success) {
+ /* Because cancel_all_calls was called, we assume that shutdown_and_notify
+ completes successfully */
+ grpc_server_destroy(server);
+ }
+
+ grpc_server *server;
+
+ protected:
+ std::string GetTypeString() const { return "shutdown"; }
+};
+
class NewCallOp : public Op {
public:
NewCallOp() {
@@ -156,6 +179,10 @@ class TryShutdownOp: public Op {
server_persist;
};
+Server::Server(grpc_server *server) : wrapped_server(server) {}
+
+Server::~Server() { this->ShutdownServer(); }
+
void Server::Init(Local<Object> exports) {
HandleScope scope;
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
@@ -184,6 +211,36 @@ void Server::DestroyWrappedServer() {
}
}
+NAN_METHOD(ServerShutdownCallback) {
+ if (!info[0]->IsNull()) {
+ return Nan::ThrowError("forceShutdown failed somehow");
+ }
+}
+
+void Server::ShutdownServer() {
+ Nan::HandleScope scope;
+ if (this->wrapped_server != NULL) {
+ if (shutdown_callback == NULL) {
+ Local<FunctionTemplate> callback_tpl =
+ Nan::New<FunctionTemplate>(ServerShutdownCallback);
+ shutdown_callback =
+ new Callback(Nan::GetFunction(callback_tpl).ToLocalChecked());
+ }
+
+ ServerShutdownOp *op = new ServerShutdownOp(this->wrapped_server);
+ unique_ptr<OpVec> ops(new OpVec());
+ ops->push_back(unique_ptr<Op>(op));
+
+ grpc_server_shutdown_and_notify(
+ this->wrapped_server, GetCompletionQueue(),
+ new struct tag(new Callback(**shutdown_callback), ops.release(), NULL,
+ Nan::Null()));
+ grpc_server_cancel_all_calls(this->wrapped_server);
+ CompletionQueueNext();
+ this->wrapped_server = NULL;
+ }
+}
+
NAN_METHOD(Server::New) {
/* If this is not a constructor call, make a constructor call and return
the result */
diff --git a/src/node/ext/server_generic.cc b/src/node/ext/server_generic.cc
deleted file mode 100644
index 0cf20f754a..0000000000
--- a/src/node/ext/server_generic.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- *
- * Copyright 2017, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef GRPC_UV
-
-#include "server.h"
-
-#include <node.h>
-#include <nan.h>
-#include "grpc/grpc.h"
-#include "grpc/support/time.h"
-
-namespace grpc {
-namespace node {
-
-Server::Server(grpc_server *server) : wrapped_server(server) {
- shutdown_queue = grpc_completion_queue_create(NULL);
- grpc_server_register_non_listening_completion_queue(server, shutdown_queue,
- NULL);
-}
-
-Server::~Server() {
- this->ShutdownServer();
- grpc_completion_queue_shutdown(this->shutdown_queue);
- grpc_completion_queue_destroy(this->shutdown_queue);
-}
-
-void Server::ShutdownServer() {
- if (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);
- grpc_server_destroy(this->wrapped_server);
- this->wrapped_server = NULL;
- }
-}
-
-} // namespace grpc
-} // namespace node
-
-#endif /* GRPC_UV */
diff --git a/src/node/ext/server_uv.cc b/src/node/ext/server_uv.cc
deleted file mode 100644
index 789938318e..0000000000
--- a/src/node/ext/server_uv.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- *
- * Copyright 2017, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifdef GRPC_UV
-
-#include "server.h"
-
-#include <node.h>
-#include <nan.h>
-#include "grpc/grpc.h"
-#include "grpc/support/time.h"
-
-#include "call.h"
-#include "completion_queue.h"
-
-namespace grpc {
-namespace node {
-
-using Nan::Callback;
-using Nan::MaybeLocal;
-
-using v8::External;
-using v8::Function;
-using v8::FunctionTemplate;
-using v8::Local;
-using v8::Object;
-using v8::Value;
-
-static Callback *shutdown_callback = NULL;
-
-class ServerShutdownOp : public Op {
- public:
- ServerShutdownOp(grpc_server *server): server(server) {
- }
-
- ~ServerShutdownOp() {
- }
-
- Local<Value> GetNodeValue() const {
- return Nan::Null();
- }
-
- bool ParseOp(Local<Value> value, grpc_op *out) {
- return true;
- }
- bool IsFinalOp() {
- return false;
- }
- void OnComplete(bool success) {
- /* Because cancel_all_calls was called, we assume that shutdown_and_notify
- completes successfully */
- grpc_server_destroy(server);
- }
-
- grpc_server *server;
-
- protected:
- std::string GetTypeString() const { return "shutdown"; }
-};
-
-Server::Server(grpc_server *server) : wrapped_server(server) {
-}
-
-Server::~Server() {
- this->ShutdownServer();
-}
-
-NAN_METHOD(ServerShutdownCallback) {
- if (!info[0]->IsNull()) {
- return Nan::ThrowError("forceShutdown failed somehow");
- }
-}
-
-void Server::ShutdownServer() {
- Nan::HandleScope scope;
- if (this->wrapped_server != NULL) {
- if (shutdown_callback == NULL) {
- Local<FunctionTemplate>callback_tpl =
- Nan::New<FunctionTemplate>(ServerShutdownCallback);
- shutdown_callback = new Callback(
- Nan::GetFunction(callback_tpl).ToLocalChecked());
- }
-
- ServerShutdownOp *op = new ServerShutdownOp(this->wrapped_server);
- unique_ptr<OpVec> ops(new OpVec());
- ops->push_back(unique_ptr<Op>(op));
-
- grpc_server_shutdown_and_notify(
- this->wrapped_server, GetCompletionQueue(),
- new struct tag(new Callback(**shutdown_callback), ops.release(), NULL,
- Nan::Null()));
- grpc_server_cancel_all_calls(this->wrapped_server);
- CompletionQueueNext();
- this->wrapped_server = NULL;
- }
-}
-
-} // namespace grpc
-} // namespace node
-
-#endif /* GRPC_UV */
diff --git a/src/node/health_check/package.json b/src/node/health_check/package.json
index 3d33118298..fe36fb2693 100644
--- a/src/node/health_check/package.json
+++ b/src/node/health_check/package.json
@@ -1,6 +1,6 @@
{
"name": "grpc-health-check",
- "version": "1.3.0-pre1",
+ "version": "1.3.3",
"author": "Google Inc.",
"description": "Health check service for use with gRPC",
"repository": {
@@ -15,7 +15,7 @@
}
],
"dependencies": {
- "grpc": "^1.3.0-pre1",
+ "grpc": "^1.3.3",
"lodash": "^3.9.3",
"google-protobuf": "^3.0.0"
},
diff --git a/src/node/index.js b/src/node/index.js
index 071bfd7927..fb313ac88b 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -64,8 +64,6 @@ grpc.setDefaultRootsPem(fs.readFileSync(SSL_ROOTS_PATH, 'ascii'));
* Buffers. Defaults to false
* - longsAsStrings: deserialize long values as strings instead of objects.
* Defaults to true
- * - enumsAsStrings: deserialize enum values as strings instead of numbers.
- * Defaults to true
* - deprecatedArgumentOrder: Use the beta method argument order for client
* methods, with optional arguments after the callback. Defaults to false.
* This option is only a temporary stopgap measure to smooth an API breakage.
@@ -99,10 +97,6 @@ exports.loadObject = function loadObject(value, options) {
switch (protobufjsVersion) {
case 6: return protobuf_js_6_common.loadObject(value, options);
case 5:
- var deprecation_message = 'Calling grpc.loadObject with an object ' +
- 'generated by ProtoBuf.js 5 is deprecated. Please upgrade to ' +
- 'ProtoBuf.js 6.';
- common.log(grpc.logVerbosity.INFO, deprecation_message);
return protobuf_js_5_common.loadObject(value, options);
default:
throw new Error('Unrecognized protobufjsVersion', protobufjsVersion);
@@ -111,19 +105,6 @@ exports.loadObject = function loadObject(value, options) {
var loadObject = exports.loadObject;
-function applyProtoRoot(filename, root) {
- if (_.isString(filename)) {
- return filename;
- }
- filename.root = path.resolve(filename.root) + '/';
- root.resolvePath = function(originPath, importPath, alreadyNormalized) {
- return ProtoBuf.util.path.resolve(filename.root,
- importPath,
- alreadyNormalized);
- };
- return filename.file;
-}
-
/**
* Load a gRPC object from a .proto file. The options object can provide the
* following options:
@@ -133,8 +114,6 @@ function applyProtoRoot(filename, root) {
* Buffers. Defaults to false
* - longsAsStrings: deserialize long values as strings instead of objects.
* Defaults to true
- * - enumsAsStrings: deserialize enum values as strings instead of numbers.
- * Defaults to true
* - deprecatedArgumentOrder: Use the beta method argument order for client
* methods, with optional arguments after the callback. Defaults to false.
* This option is only a temporary stopgap measure to smooth an API breakage.
@@ -146,17 +125,31 @@ function applyProtoRoot(filename, root) {
* @return {Object<string, *>} The resulting gRPC object
*/
exports.load = function load(filename, format, options) {
- /* Note: format is currently unused, because the API for loading a proto
- file or a JSON file is identical in Protobuf.js 6. In the future, there is
- still the possibility of adding other formats that would be loaded
- differently */
options = _.defaults(options, common.defaultGrpcOptions);
- options.protobufjs_version = 6;
- var root = new ProtoBuf.Root();
- var parse_options = {keepCase: !options.convertFieldsToCamelCase};
- return loadObject(root.loadSync(applyProtoRoot(filename, root),
- parse_options),
- options);
+ options.protobufjsVersion = 5;
+ if (!format) {
+ format = 'proto';
+ }
+ var convertFieldsToCamelCaseOriginal = ProtoBuf.convertFieldsToCamelCase;
+ if(options && options.hasOwnProperty('convertFieldsToCamelCase')) {
+ ProtoBuf.convertFieldsToCamelCase = options.convertFieldsToCamelCase;
+ }
+ var builder;
+ try {
+ switch(format) {
+ case 'proto':
+ builder = ProtoBuf.loadProtoFile(filename);
+ break;
+ case 'json':
+ builder = ProtoBuf.loadJsonFile(filename);
+ break;
+ default:
+ throw new Error('Unrecognized format "' + format + '"');
+ }
+ } finally {
+ ProtoBuf.convertFieldsToCamelCase = convertFieldsToCamelCaseOriginal;
+ }
+ return loadObject(builder.ns, options);
};
var log_template = _.template(
diff --git a/src/node/src/protobuf_js_5_common.js b/src/node/src/protobuf_js_5_common.js
index 62cf2f4aca..4041e05390 100644
--- a/src/node/src/protobuf_js_5_common.js
+++ b/src/node/src/protobuf_js_5_common.js
@@ -45,8 +45,7 @@ var client = require('./client');
* objects. Defaults to true
* @return {function(Buffer):cls} The deserialization function
*/
-exports.deserializeCls = function deserializeCls(cls, binaryAsBase64,
- longsAsStrings) {
+exports.deserializeCls = function deserializeCls(cls, options) {
/**
* Deserialize a buffer to a message object
* @param {Buffer} arg_buf The buffer to deserialize
@@ -55,7 +54,8 @@ exports.deserializeCls = function deserializeCls(cls, binaryAsBase64,
return function deserialize(arg_buf) {
// Convert to a native object with binary fields as Buffers (first argument)
// and longs as strings (second argument)
- return cls.decode(arg_buf).toRaw(binaryAsBase64, longsAsStrings);
+ return cls.decode(arg_buf).toRaw(options.binaryAsBase64,
+ options.longsAsStrings);
};
};
@@ -128,10 +128,10 @@ exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service,
responseType: method.resolvedResponseType,
requestSerialize: serializeCls(method.resolvedRequestType.build()),
requestDeserialize: deserializeCls(method.resolvedRequestType.build(),
- binaryAsBase64, longsAsStrings),
+ options),
responseSerialize: serializeCls(method.resolvedResponseType.build()),
responseDeserialize: deserializeCls(method.resolvedResponseType.build(),
- binaryAsBase64, longsAsStrings)
+ options)
};
}));
};
diff --git a/src/node/src/server.js b/src/node/src/server.js
index 3450abed08..25640a0374 100644
--- a/src/node/src/server.js
+++ b/src/node/src/server.js
@@ -779,6 +779,11 @@ Server.prototype.addService = function(service, implementation) {
});
};
+var logAddProtoServiceDeprecationOnce = _.once(function() {
+ common.log(grpc.logVerbosity.INFO,
+ 'Server#addProtoService is deprecated. Use addService instead');
+});
+
/**
* Add a proto service to the server, with a corresponding implementation
* @deprecated Use grpc.load and Server#addService instead
@@ -790,8 +795,7 @@ Server.prototype.addProtoService = function(service, implementation) {
var options;
var protobuf_js_5_common = require('./protobuf_js_5_common');
var protobuf_js_6_common = require('./protobuf_js_6_common');
- common.log(grpc.logVerbosity.INFO,
- 'Server#addProtoService is deprecated. Use addService instead');
+ logAddProtoServiceDeprecationOnce();
if (protobuf_js_5_common.isProbablyProtobufJs5(service)) {
options = _.defaults(service.grpc_options, common.defaultGrpcOptions);
this.addService(
diff --git a/src/node/test/common_test.js b/src/node/test/common_test.js
index e1ce864f97..b7c2c6a8d6 100644
--- a/src/node/test/common_test.js
+++ b/src/node/test/common_test.js
@@ -37,16 +37,15 @@ var assert = require('assert');
var _ = require('lodash');
var common = require('../src/common');
-var protobuf_js_6_common = require('../src/protobuf_js_6_common');
+var protobuf_js_5_common = require('../src/protobuf_js_5_common');
-var serializeCls = protobuf_js_6_common.serializeCls;
-var deserializeCls = protobuf_js_6_common.deserializeCls;
+var serializeCls = protobuf_js_5_common.serializeCls;
+var deserializeCls = protobuf_js_5_common.deserializeCls;
var ProtoBuf = require('protobufjs');
-var messages_proto = new ProtoBuf.Root();
-messages_proto = messages_proto.loadSync(
- __dirname + '/test_messages.proto', {keepCase: true}).resolveAll();
+var messages_proto = ProtoBuf.loadProtoFile(
+ __dirname + '/test_messages.proto').build();
var default_options = common.defaultGrpcOptions;
@@ -101,6 +100,7 @@ describe('Proto message long int serialize and deserialize', function() {
var longNumDeserialize = deserializeCls(messages_proto.LongValues,
num_options);
var serialized = longSerialize({int_64: pos_value});
+ console.log(longDeserialize(serialized));
assert.strictEqual(typeof longDeserialize(serialized).int_64, 'string');
/* With the longsAsStrings option disabled, long values are represented as
* objects with 3 keys: low, high, and unsigned */
@@ -136,7 +136,8 @@ describe('Proto message bytes serialize and deserialize', function() {
var serialized = sequenceSerialize({repeated_field: [10]});
assert.strictEqual(expected_serialize.compare(serialized), 0);
});
- it('should deserialize packed or unpacked repeated', function() {
+ // This tests a bug that was fixed in Protobuf.js 6
+ it.skip('should deserialize packed or unpacked repeated', function() {
var expectedDeserialize = {
bytes_field: new Buffer(''),
repeated_field: [10]
@@ -155,7 +156,8 @@ describe('Proto message bytes serialize and deserialize', function() {
assert.deepEqual(unpackedDeserialized, expectedDeserialize);
});
});
-describe('Proto message oneof serialize and deserialize', function() {
+// This tests a bug that was fixed in Protobuf.js 6
+describe.skip('Proto message oneof serialize and deserialize', function() {
var oneofSerialize = serializeCls(messages_proto.OneOfValues);
var oneofDeserialize = deserializeCls(
messages_proto.OneOfValues, default_options);
@@ -193,7 +195,8 @@ describe('Proto message enum serialize and deserialize', function() {
assert.deepEqual(enumDeserialize(nameSerialized),
enumDeserialize(numberSerialized));
});
- it('Should deserialize as a string the enumsAsStrings option', function() {
+ // This tests a bug that was fixed in Protobuf.js 6
+ it.skip('Should correctly handle the enumsAsStrings option', function() {
var serialized = enumSerialize({enum_value: 'TWO'});
var nameDeserialized = enumDeserialize(serialized);
var numberDeserialized = enumIntDeserialize(serialized);
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index 783028fa99..d2f0511af2 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -43,9 +43,8 @@ var ProtoBuf = require('protobufjs');
var grpc = require('..');
-var math_proto = new ProtoBuf.Root();
-math_proto = math_proto.loadSync(__dirname +
- '/../../proto/math/math.proto', {keepCase: true});
+var math_proto = ProtoBuf.loadProtoFile(__dirname +
+ '/../../proto/math/math.proto');
var mathService = math_proto.lookup('math.Math');
var mathServiceAttrs = grpc.loadObject(
@@ -332,9 +331,7 @@ describe('Echo service', function() {
var server;
var client;
before(function() {
- var test_proto = new ProtoBuf.Root();
- test_proto = test_proto.loadSync(__dirname + '/echo_service.proto',
- {keepCase: true});
+ var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto');
var echo_service = test_proto.lookup('EchoService');
var Client = grpc.loadObject(echo_service);
server = new grpc.Server();
@@ -357,6 +354,13 @@ describe('Echo service', function() {
done();
});
});
+ it('Should convert an undefined argument to default values', function(done) {
+ client.echo(undefined, function(error, response) {
+ assert.ifError(error);
+ assert.deepEqual(response, {value: '', value2: 0});
+ done();
+ });
+ });
});
describe('Generic client and server', function() {
function toString(val) {
@@ -457,9 +461,7 @@ describe('Echo metadata', function() {
var server;
var metadata;
before(function() {
- var test_proto = new ProtoBuf.Root();
- test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
- {keepCase: true});
+ var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
var test_service = test_proto.lookup('TestService');
var Client = grpc.loadObject(test_service);
server = new grpc.Server();
@@ -560,9 +562,7 @@ describe('Client malformed response handling', function() {
var client;
var badArg = new Buffer([0xFF]);
before(function() {
- var test_proto = new ProtoBuf.Root();
- test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
- {keepCase: true});
+ var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
var test_service = test_proto.lookup('TestService');
var malformed_test_service = {
unary: {
@@ -669,9 +669,7 @@ describe('Server serialization failure handling', function() {
var client;
var server;
before(function() {
- var test_proto = new ProtoBuf.Root();
- test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
- {keepCase: true});
+ var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
var test_service = test_proto.lookup('TestService');
var malformed_test_service = {
unary: {
@@ -772,16 +770,13 @@ describe('Server serialization failure handling', function() {
});
});
describe('Other conditions', function() {
- var test_service;
var Client;
var client;
var server;
var port;
before(function() {
- var test_proto = new ProtoBuf.Root();
- test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
- {keepCase: true});
- test_service = test_proto.lookup('TestService');
+ var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
+ var test_service = test_proto.lookup('TestService');
Client = grpc.loadObject(test_service);
server = new grpc.Server();
var trailer_metadata = new grpc.Metadata();
@@ -1121,15 +1116,12 @@ describe('Call propagation', function() {
var proxy;
var proxy_impl;
- var test_service;
var Client;
var client;
var server;
before(function() {
- var test_proto = new ProtoBuf.Root();
- test_proto = test_proto.loadSync(__dirname + '/test_service.proto',
- {keepCase: true});
- test_service = test_proto.lookup('TestService');
+ var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
+ var test_service = test_proto.lookup('TestService');
server = new grpc.Server();
Client = grpc.loadObject(test_service);
server.addService(Client.service, {
diff --git a/src/node/tools/package.json b/src/node/tools/package.json
index 056f28ab3c..caf2b5a5cb 100644
--- a/src/node/tools/package.json
+++ b/src/node/tools/package.json
@@ -1,6 +1,6 @@
{
"name": "grpc-tools",
- "version": "1.3.0-pre1",
+ "version": "1.3.3",
"author": "Google Inc.",
"description": "Tools for developing with gRPC on Node.js",
"homepage": "http://www.grpc.io/",