Merge branch 'master' into new_tsi

This commit is contained in:
jiangtaoli2016 2017-04-24 09:02:11 -07:00
commit 65856a7cf4
24 changed files with 320 additions and 390 deletions

View File

@ -33,10 +33,10 @@
#include <string.h>
#include <node.h>
#include <nan.h>
#include "grpc/grpc.h"
#include <node.h>
#include "grpc/byte_buffer_reader.h"
#include "grpc/grpc.h"
#include "grpc/slice.h"
#include "byte_buffer.h"

View File

@ -36,8 +36,8 @@
#include <string.h>
#include <node.h>
#include <nan.h>
#include <node.h>
#include "grpc/grpc.h"
namespace grpc {

View File

@ -31,23 +31,23 @@
*
*/
#include <map>
#include <memory>
#include <vector>
#include <map>
#include <node.h>
#include "grpc/support/log.h"
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
#include "grpc/support/alloc.h"
#include "grpc/support/time.h"
#include "byte_buffer.h"
#include "call.h"
#include "call_credentials.h"
#include "channel.h"
#include "completion_queue.h"
#include "completion_queue_async_worker.h"
#include "call_credentials.h"
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
#include "grpc/support/alloc.h"
#include "grpc/support/log.h"
#include "grpc/support/time.h"
#include "slice.h"
#include "timeval.h"
@ -101,8 +101,8 @@ bool CreateMetadataArray(Local<Object> metadata, grpc_metadata_array *array) {
HandleScope scope;
Local<Array> keys = Nan::GetOwnPropertyNames(metadata).ToLocalChecked();
for (unsigned int i = 0; i < keys->Length(); i++) {
Local<String> current_key = Nan::To<String>(
Nan::Get(keys, i).ToLocalChecked()).ToLocalChecked();
Local<String> current_key =
Nan::To<String>(Nan::Get(keys, i).ToLocalChecked()).ToLocalChecked();
Local<Value> value_array = Nan::Get(metadata, current_key).ToLocalChecked();
if (!value_array->IsArray()) {
return false;
@ -113,8 +113,8 @@ bool CreateMetadataArray(Local<Object> metadata, grpc_metadata_array *array) {
gpr_zalloc(array->capacity * sizeof(grpc_metadata)));
for (unsigned int i = 0; i < keys->Length(); i++) {
Local<String> current_key(Nan::To<String>(keys->Get(i)).ToLocalChecked());
Local<Array> values = Local<Array>::Cast(
Nan::Get(metadata, current_key).ToLocalChecked());
Local<Array> values =
Local<Array>::Cast(Nan::Get(metadata, current_key).ToLocalChecked());
grpc_slice key_slice = CreateSliceFromString(current_key);
grpc_slice key_intern_slice = grpc_slice_intern(key_slice);
grpc_slice_unref(key_slice);
@ -183,17 +183,12 @@ Local<Value> Op::GetOpType() const {
return scope.Escape(Nan::New(GetTypeString()).ToLocalChecked());
}
Op::~Op() {
}
Op::~Op() {}
class SendMetadataOp : public Op {
public:
SendMetadataOp() {
grpc_metadata_array_init(&send_metadata);
}
~SendMetadataOp() {
DestroyMetadataArray(&send_metadata);
}
SendMetadataOp() { grpc_metadata_array_init(&send_metadata); }
~SendMetadataOp() { DestroyMetadataArray(&send_metadata); }
Local<Value> GetNodeValue() const {
EscapableHandleScope scope;
return scope.Escape(Nan::True());
@ -206,32 +201,26 @@ class SendMetadataOp : public Op {
if (maybe_metadata.IsEmpty()) {
return false;
}
if (!CreateMetadataArray(maybe_metadata.ToLocalChecked(),
&send_metadata)) {
if (!CreateMetadataArray(maybe_metadata.ToLocalChecked(), &send_metadata)) {
return false;
}
out->data.send_initial_metadata.count = send_metadata.count;
out->data.send_initial_metadata.metadata = send_metadata.metadata;
return true;
}
bool IsFinalOp() {
return false;
}
void OnComplete(bool success) {
}
bool IsFinalOp() { return false; }
void OnComplete(bool success) {}
protected:
std::string GetTypeString() const {
return "send_metadata";
}
std::string GetTypeString() const { return "send_metadata"; }
private:
grpc_metadata_array send_metadata;
};
class SendMessageOp : public Op {
public:
SendMessageOp() {
send_message = NULL;
}
SendMessageOp() { send_message = NULL; }
~SendMessageOp() {
if (send_message != NULL) {
grpc_byte_buffer_destroy(send_message);
@ -246,8 +235,8 @@ class SendMessageOp : public Op {
return false;
}
Local<Object> object_value = Nan::To<Object>(value).ToLocalChecked();
MaybeLocal<Value> maybe_flag_value = Nan::Get(
object_value, Nan::New("grpcWriteFlags").ToLocalChecked());
MaybeLocal<Value> maybe_flag_value =
Nan::Get(object_value, Nan::New("grpcWriteFlags").ToLocalChecked());
if (!maybe_flag_value.IsEmpty()) {
Local<Value> flag_value = maybe_flag_value.ToLocalChecked();
if (flag_value->IsUint32()) {
@ -259,15 +248,13 @@ class SendMessageOp : public Op {
out->data.send_message.send_message = send_message;
return true;
}
bool IsFinalOp() {
return false;
}
void OnComplete(bool success) {
}
bool IsFinalOp() { return false; }
void OnComplete(bool success) {}
protected:
std::string GetTypeString() const {
return "send_message";
}
std::string GetTypeString() const { return "send_message"; }
private:
grpc_byte_buffer *send_message;
};
@ -278,25 +265,18 @@ class SendClientCloseOp : public Op {
EscapableHandleScope scope;
return scope.Escape(Nan::True());
}
bool ParseOp(Local<Value> value, grpc_op *out) {
return true;
}
bool IsFinalOp() {
return false;
}
void OnComplete(bool success) {
}
bool ParseOp(Local<Value> value, grpc_op *out) { return true; }
bool IsFinalOp() { return false; }
void OnComplete(bool success) {}
protected:
std::string GetTypeString() const {
return "client_close";
}
std::string GetTypeString() const { return "client_close"; }
};
class SendServerStatusOp : public Op {
public:
SendServerStatusOp() {
grpc_metadata_array_init(&status_metadata);
}
SendServerStatusOp() { grpc_metadata_array_init(&status_metadata); }
~SendServerStatusOp() {
grpc_slice_unref(details);
DestroyMetadataArray(&status_metadata);
@ -310,18 +290,18 @@ class SendServerStatusOp : public Op {
return false;
}
Local<Object> server_status = Nan::To<Object>(value).ToLocalChecked();
MaybeLocal<Value> maybe_metadata = Nan::Get(
server_status, Nan::New("metadata").ToLocalChecked());
MaybeLocal<Value> maybe_metadata =
Nan::Get(server_status, Nan::New("metadata").ToLocalChecked());
if (maybe_metadata.IsEmpty()) {
return false;
}
if (!maybe_metadata.ToLocalChecked()->IsObject()) {
return false;
}
Local<Object> metadata = Nan::To<Object>(
maybe_metadata.ToLocalChecked()).ToLocalChecked();
MaybeLocal<Value> maybe_code = Nan::Get(server_status,
Nan::New("code").ToLocalChecked());
Local<Object> metadata =
Nan::To<Object>(maybe_metadata.ToLocalChecked()).ToLocalChecked();
MaybeLocal<Value> maybe_code =
Nan::Get(server_status, Nan::New("code").ToLocalChecked());
if (maybe_code.IsEmpty()) {
return false;
}
@ -329,16 +309,16 @@ class SendServerStatusOp : public Op {
return false;
}
uint32_t code = Nan::To<uint32_t>(maybe_code.ToLocalChecked()).FromJust();
MaybeLocal<Value> maybe_details = Nan::Get(
server_status, Nan::New("details").ToLocalChecked());
MaybeLocal<Value> maybe_details =
Nan::Get(server_status, Nan::New("details").ToLocalChecked());
if (maybe_details.IsEmpty()) {
return false;
}
if (!maybe_details.ToLocalChecked()->IsString()) {
return false;
}
Local<String> details = Nan::To<String>(
maybe_details.ToLocalChecked()).ToLocalChecked();
Local<String> details =
Nan::To<String>(maybe_details.ToLocalChecked()).ToLocalChecked();
if (!CreateMetadataArray(metadata, &status_metadata)) {
return false;
}
@ -352,15 +332,11 @@ class SendServerStatusOp : public Op {
out->data.send_status_from_server.status_details = &this->details;
return true;
}
bool IsFinalOp() {
return true;
}
void OnComplete(bool success) {
}
bool IsFinalOp() { return true; }
void OnComplete(bool success) {}
protected:
std::string GetTypeString() const {
return "send_status";
}
std::string GetTypeString() const { return "send_status"; }
private:
grpc_slice details;
@ -369,13 +345,9 @@ class SendServerStatusOp : public Op {
class GetMetadataOp : public Op {
public:
GetMetadataOp() {
grpc_metadata_array_init(&recv_metadata);
}
GetMetadataOp() { grpc_metadata_array_init(&recv_metadata); }
~GetMetadataOp() {
grpc_metadata_array_destroy(&recv_metadata);
}
~GetMetadataOp() { grpc_metadata_array_destroy(&recv_metadata); }
Local<Value> GetNodeValue() const {
EscapableHandleScope scope;
@ -386,16 +358,11 @@ class GetMetadataOp : public Op {
out->data.recv_initial_metadata.recv_initial_metadata = &recv_metadata;
return true;
}
bool IsFinalOp() {
return false;
}
void OnComplete(bool success) {
}
bool IsFinalOp() { return false; }
void OnComplete(bool success) {}
protected:
std::string GetTypeString() const {
return "metadata";
}
std::string GetTypeString() const { return "metadata"; }
private:
grpc_metadata_array recv_metadata;
@ -403,9 +370,7 @@ class GetMetadataOp : public Op {
class ReadMessageOp : public Op {
public:
ReadMessageOp() {
recv_message = NULL;
}
ReadMessageOp() { recv_message = NULL; }
~ReadMessageOp() {
if (recv_message != NULL) {
grpc_byte_buffer_destroy(recv_message);
@ -420,16 +385,11 @@ class ReadMessageOp : public Op {
out->data.recv_message.recv_message = &recv_message;
return true;
}
bool IsFinalOp() {
return false;
}
void OnComplete(bool success) {
}
bool IsFinalOp() { return false; }
void OnComplete(bool success) {}
protected:
std::string GetTypeString() const {
return "read";
}
std::string GetTypeString() const { return "read"; }
private:
grpc_byte_buffer *recv_message;
@ -437,13 +397,9 @@ class ReadMessageOp : public Op {
class ClientStatusOp : public Op {
public:
ClientStatusOp() {
grpc_metadata_array_init(&metadata_array);
}
ClientStatusOp() { grpc_metadata_array_init(&metadata_array); }
~ClientStatusOp() {
grpc_metadata_array_destroy(&metadata_array);
}
~ClientStatusOp() { grpc_metadata_array_destroy(&metadata_array); }
bool ParseOp(Local<Value> value, grpc_op *out) {
out->data.recv_status_on_client.trailing_metadata = &metadata_array;
@ -463,15 +419,12 @@ class ClientStatusOp : public Op {
ParseMetadata(&metadata_array));
return scope.Escape(status_obj);
}
bool IsFinalOp() {
return true;
}
void OnComplete(bool success) {
}
bool IsFinalOp() { return true; }
void OnComplete(bool success) {}
protected:
std::string GetTypeString() const {
return "status";
}
std::string GetTypeString() const { return "status"; }
private:
grpc_metadata_array metadata_array;
grpc_status_code status;
@ -489,23 +442,18 @@ class ServerCloseResponseOp : public Op {
out->data.recv_close_on_server.cancelled = &cancelled;
return true;
}
bool IsFinalOp() {
return false;
}
void OnComplete(bool success) {
}
bool IsFinalOp() { return false; }
void OnComplete(bool success) {}
protected:
std::string GetTypeString() const {
return "cancelled";
}
std::string GetTypeString() const { return "cancelled"; }
private:
int cancelled;
};
tag::tag(Callback *callback, OpVec *ops, Call *call, Local<Value> call_value) :
callback(callback), ops(ops), call(call){
tag::tag(Callback *callback, OpVec *ops, Call *call, Local<Value> call_value)
: callback(callback), ops(ops), call(call) {
HandleScope scope;
call_persist.Reset(call_value);
}
@ -555,19 +503,15 @@ void DestroyTag(void *tag) {
void Call::DestroyCall() {
if (this->wrapped_call != NULL) {
grpc_call_destroy(this->wrapped_call);
grpc_call_unref(this->wrapped_call);
this->wrapped_call = NULL;
}
}
Call::Call(grpc_call *call) : wrapped_call(call),
pending_batches(0),
has_final_op_completed(false) {
}
Call::Call(grpc_call *call)
: wrapped_call(call), pending_batches(0), has_final_op_completed(false) {}
Call::~Call() {
DestroyCall();
}
Call::~Call() { DestroyCall(); }
void Call::Init(Local<Object> exports) {
HandleScope scope;
@ -596,10 +540,10 @@ Local<Value> Call::WrapStruct(grpc_call *call) {
return scope.Escape(Nan::Null());
}
const int argc = 1;
Local<Value> argv[argc] = {Nan::New<External>(
reinterpret_cast<void *>(call))};
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
constructor->GetFunction(), argc, argv);
Local<Value> argv[argc] = {
Nan::New<External>(reinterpret_cast<void *>(call))};
MaybeLocal<Object> maybe_instance =
Nan::NewInstance(constructor->GetFunction(), argc, argv);
if (maybe_instance.IsEmpty()) {
return scope.Escape(Nan::Null());
} else {
@ -631,8 +575,7 @@ NAN_METHOD(Call::New) {
if (info[0]->IsExternal()) {
Local<External> ext = info[0].As<External>();
// This option is used for wrapping an existing call
grpc_call *call_value =
reinterpret_cast<grpc_call *>(ext->Value());
grpc_call *call_value = reinterpret_cast<grpc_call *>(ext->Value());
call = new Call(call_value);
} else {
if (!Channel::HasInstance(info[0])) {
@ -648,8 +591,8 @@ NAN_METHOD(Call::New) {
// These arguments are at the end because they are optional
grpc_call *parent_call = NULL;
if (Call::HasInstance(info[4])) {
Call *parent_obj = ObjectWrap::Unwrap<Call>(
Nan::To<Object>(info[4]).ToLocalChecked());
Call *parent_obj =
ObjectWrap::Unwrap<Call>(Nan::To<Object>(info[4]).ToLocalChecked());
parent_call = parent_obj->wrapped_call;
} else if (!(info[4]->IsUndefined() || info[4]->IsNull())) {
return Nan::ThrowTypeError(
@ -670,22 +613,20 @@ NAN_METHOD(Call::New) {
double deadline = Nan::To<double>(info[2]).FromJust();
grpc_channel *wrapped_channel = channel->GetWrappedChannel();
grpc_call *wrapped_call;
grpc_slice method = CreateSliceFromString(
Nan::To<String>(info[1]).ToLocalChecked());
grpc_slice method =
CreateSliceFromString(Nan::To<String>(info[1]).ToLocalChecked());
if (info[3]->IsString()) {
grpc_slice *host = new grpc_slice;
*host = CreateSliceFromString(
Nan::To<String>(info[3]).ToLocalChecked());
*host =
CreateSliceFromString(Nan::To<String>(info[3]).ToLocalChecked());
wrapped_call = grpc_channel_create_call(
wrapped_channel, parent_call, propagate_flags,
GetCompletionQueue(), method,
host, MillisecondsToTimespec(deadline), NULL);
wrapped_channel, parent_call, propagate_flags, GetCompletionQueue(),
method, host, MillisecondsToTimespec(deadline), NULL);
delete host;
} else if (info[3]->IsUndefined() || info[3]->IsNull()) {
wrapped_call = grpc_channel_create_call(
wrapped_channel, parent_call, propagate_flags,
GetCompletionQueue(), method,
NULL, MillisecondsToTimespec(deadline), NULL);
wrapped_channel, parent_call, propagate_flags, GetCompletionQueue(),
method, NULL, MillisecondsToTimespec(deadline), NULL);
} else {
return Nan::ThrowTypeError("Call's fourth argument must be a string");
}
@ -699,8 +640,8 @@ NAN_METHOD(Call::New) {
} else {
const int argc = 4;
Local<Value> argv[argc] = {info[0], info[1], info[2], info[3]};
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
constructor->GetFunction(), argc, argv);
MaybeLocal<Object> maybe_instance =
Nan::NewInstance(constructor->GetFunction(), argc, argv);
if (maybe_instance.IsEmpty()) {
// There's probably a pending exception
return;
@ -773,8 +714,8 @@ NAN_METHOD(Call::StartBatch) {
}
Callback *callback = new Callback(callback_func);
grpc_call_error error = grpc_call_start_batch(
call->wrapped_call, &ops[0], nops, new struct tag(
callback, op_vector.release(), call, info.This()), NULL);
call->wrapped_call, &ops[0], nops,
new struct tag(callback, op_vector.release(), call, info.This()), NULL);
if (error != GRPC_CALL_OK) {
return Nan::ThrowError(nanErrorWithCode("startBatch failed", error));
}
@ -807,8 +748,8 @@ NAN_METHOD(Call::CancelWithStatus) {
"cancelWithStatus's second argument must be a string");
}
Call *call = ObjectWrap::Unwrap<Call>(info.This());
grpc_status_code code = static_cast<grpc_status_code>(
Nan::To<uint32_t>(info[0]).FromJust());
grpc_status_code code =
static_cast<grpc_status_code>(Nan::To<uint32_t>(info[0]).FromJust());
if (code == GRPC_STATUS_OK) {
return Nan::ThrowRangeError(
"cancelWithStatus cannot be called with OK status");

View File

@ -37,14 +37,13 @@
#include <memory>
#include <vector>
#include <node.h>
#include <nan.h>
#include <node.h>
#include "grpc/grpc.h"
#include "grpc/support/log.h"
#include "channel.h"
namespace grpc {
namespace node {

View File

@ -31,17 +31,17 @@
*
*/
#include <node.h>
#include <nan.h>
#include <node.h>
#include <uv.h>
#include <queue>
#include "call.h"
#include "call_credentials.h"
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
#include "grpc/support/log.h"
#include "call_credentials.h"
#include "call.h"
namespace grpc {
namespace node {
@ -86,15 +86,15 @@ void CallCredentials::Init(Local<Object> exports) {
fun_tpl.Reset(tpl);
Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
Nan::Set(ctr, Nan::New("createFromPlugin").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(CreateFromPlugin)).ToLocalChecked());
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateFromPlugin))
.ToLocalChecked());
Nan::Set(exports, Nan::New("CallCredentials").ToLocalChecked(), ctr);
constructor = new Nan::Callback(ctr);
Local<FunctionTemplate> callback_tpl =
Nan::New<FunctionTemplate>(PluginCallback);
plugin_callback = new Callback(
Nan::GetFunction(callback_tpl).ToLocalChecked());
plugin_callback =
new Callback(Nan::GetFunction(callback_tpl).ToLocalChecked());
}
bool CallCredentials::HasInstance(Local<Value> val) {
@ -110,8 +110,8 @@ Local<Value> CallCredentials::WrapStruct(grpc_call_credentials *credentials) {
}
Local<Value> argv[argc] = {
Nan::New<External>(reinterpret_cast<void *>(credentials))};
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
constructor->GetFunction(), argc, argv);
MaybeLocal<Object> maybe_instance =
Nan::NewInstance(constructor->GetFunction(), argc, argv);
if (maybe_instance.IsEmpty()) {
return scope.Escape(Nan::Null());
} else {
@ -160,8 +160,6 @@ NAN_METHOD(CallCredentials::Compose) {
info.GetReturnValue().Set(WrapStruct(creds));
}
NAN_METHOD(CallCredentials::CreateFromPlugin) {
if (!info[0]->IsFunction()) {
return Nan::ThrowTypeError(
@ -172,9 +170,7 @@ NAN_METHOD(CallCredentials::CreateFromPlugin) {
state->callback = new Nan::Callback(info[0].As<Function>());
state->pending_callbacks = new std::queue<plugin_callback_data *>();
uv_mutex_init(&state->plugin_mutex);
uv_async_init(uv_default_loop(),
&state->plugin_async,
SendPluginCallback);
uv_async_init(uv_default_loop(), &state->plugin_async, SendPluginCallback);
uv_unref((uv_handle_t *)&state->plugin_async);
state->plugin_async.data = state;
@ -183,8 +179,8 @@ NAN_METHOD(CallCredentials::CreateFromPlugin) {
plugin.destroy = plugin_destroy_state;
plugin.state = reinterpret_cast<void *>(state);
plugin.type = "";
grpc_call_credentials *creds = grpc_metadata_credentials_create_from_plugin(
plugin, NULL);
grpc_call_credentials *creds =
grpc_metadata_credentials_create_from_plugin(plugin, NULL);
info.GetReturnValue().Set(WrapStruct(creds));
}
@ -206,26 +202,27 @@ NAN_METHOD(PluginCallback) {
return Nan::ThrowTypeError(
"The callback's fourth argument must be an object");
}
grpc_status_code code = static_cast<grpc_status_code>(
Nan::To<uint32_t>(info[0]).FromJust());
grpc_status_code code =
static_cast<grpc_status_code>(Nan::To<uint32_t>(info[0]).FromJust());
Utf8String details_utf8_str(info[1]);
char *details = *details_utf8_str;
grpc_metadata_array array;
grpc_metadata_array_init(&array);
Local<Object> callback_data = Nan::To<Object>(info[3]).ToLocalChecked();
if (!CreateMetadataArray(Nan::To<Object>(info[2]).ToLocalChecked(),
&array)){
if (!CreateMetadataArray(Nan::To<Object>(info[2]).ToLocalChecked(), &array)) {
return Nan::ThrowError("Failed to parse metadata");
}
grpc_credentials_plugin_metadata_cb cb =
reinterpret_cast<grpc_credentials_plugin_metadata_cb>(
Nan::Get(callback_data,
Nan::New("cb").ToLocalChecked()
).ToLocalChecked().As<External>()->Value());
Nan::Get(callback_data, Nan::New("cb").ToLocalChecked())
.ToLocalChecked()
.As<External>()
->Value());
void *user_data =
Nan::Get(callback_data,
Nan::New("user_data").ToLocalChecked()
).ToLocalChecked().As<External>()->Value();
Nan::Get(callback_data, Nan::New("user_data").ToLocalChecked())
.ToLocalChecked()
.As<External>()
->Value();
cb(user_data, array.metadata, array.count, code, details);
DestroyMetadataArray(&array);
}
@ -247,11 +244,9 @@ NAUV_WORK_CB(SendPluginCallback) {
Nan::New<v8::External>(data->user_data));
const int argc = 3;
v8::Local<v8::Value> argv[argc] = {
Nan::New(data->service_url).ToLocalChecked(),
callback_data,
Nan::New(data->service_url).ToLocalChecked(), callback_data,
// Get Local<Function> from Nan::Callback*
**plugin_callback
};
**plugin_callback};
Nan::Callback *callback = state->callback;
callback->Call(argc, argv);
delete data;

View File

@ -36,8 +36,8 @@
#include <queue>
#include <node.h>
#include <nan.h>
#include <node.h>
#include <uv.h>
#include "grpc/grpc_security.h"

View File

@ -35,15 +35,15 @@
#include "grpc/support/log.h"
#include <node.h>
#include <nan.h>
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
#include <node.h>
#include "call.h"
#include "channel.h"
#include "channel_credentials.h"
#include "completion_queue.h"
#include "completion_queue_async_worker.h"
#include "channel_credentials.h"
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
#include "timeval.h"
namespace grpc {
@ -82,8 +82,8 @@ bool ParseChannelArgs(Local<Value> args_val,
*channel_args_ptr = NULL;
return false;
}
grpc_channel_args *channel_args = reinterpret_cast<grpc_channel_args*>(
malloc(sizeof(grpc_channel_args)));
grpc_channel_args *channel_args =
reinterpret_cast<grpc_channel_args *>(malloc(sizeof(grpc_channel_args)));
*channel_args_ptr = channel_args;
Local<Object> args_hash = Nan::To<Object>(args_val).ToLocalChecked();
Local<Array> keys = Nan::GetOwnPropertyNames(args_hash).ToLocalChecked();
@ -104,16 +104,16 @@ bool ParseChannelArgs(Local<Value> args_val,
} else if (value->IsString()) {
Utf8String val_str(value);
channel_args->args[i].type = GRPC_ARG_STRING;
channel_args->args[i].value.string = reinterpret_cast<char*>(
calloc(val_str.length() + 1,sizeof(char)));
memcpy(channel_args->args[i].value.string,
*val_str, val_str.length() + 1);
channel_args->args[i].value.string =
reinterpret_cast<char *>(calloc(val_str.length() + 1, sizeof(char)));
memcpy(channel_args->args[i].value.string, *val_str,
val_str.length() + 1);
} else {
// The value does not match either of the accepted types
return false;
}
channel_args->args[i].key = reinterpret_cast<char*>(
calloc(key_str.length() + 1, sizeof(char)));
channel_args->args[i].key =
reinterpret_cast<char *>(calloc(key_str.length() + 1, sizeof(char)));
memcpy(channel_args->args[i].key, *key_str, key_str.length() + 1);
}
return true;
@ -190,12 +190,13 @@ NAN_METHOD(Channel::New) {
grpc_channel_args *channel_args_ptr = NULL;
if (!ParseChannelArgs(info[2], &channel_args_ptr)) {
DeallocateChannelArgs(channel_args_ptr);
return Nan::ThrowTypeError("Channel options must be an object with "
return Nan::ThrowTypeError(
"Channel options must be an object with "
"string keys and integer or string values");
}
if (creds == NULL) {
wrapped_channel = grpc_insecure_channel_create(*host, channel_args_ptr,
NULL);
wrapped_channel =
grpc_insecure_channel_create(*host, channel_args_ptr, NULL);
} else {
wrapped_channel =
grpc_secure_channel_create(creds, *host, channel_args_ptr, NULL);
@ -208,8 +209,8 @@ NAN_METHOD(Channel::New) {
} else {
const int argc = 3;
Local<Value> argv[argc] = {info[0], info[1], info[2]};
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
constructor->GetFunction(), argc, argv);
MaybeLocal<Object> maybe_instance =
Nan::NewInstance(constructor->GetFunction(), argc, argv);
if (maybe_instance.IsEmpty()) {
// There's probably a pending exception
return;
@ -232,11 +233,13 @@ NAN_METHOD(Channel::Close) {
NAN_METHOD(Channel::GetTarget) {
if (!HasInstance(info.This())) {
return Nan::ThrowTypeError("getTarget can only be called on Channel objects");
return Nan::ThrowTypeError(
"getTarget can only be called on Channel objects");
}
Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
info.GetReturnValue().Set(Nan::New(
grpc_channel_get_target(channel->wrapped_channel)).ToLocalChecked());
info.GetReturnValue().Set(
Nan::New(grpc_channel_get_target(channel->wrapped_channel))
.ToLocalChecked());
}
NAN_METHOD(Channel::GetConnectivityState) {
@ -246,9 +249,8 @@ NAN_METHOD(Channel::GetConnectivityState) {
}
Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
int try_to_connect = (int)info[0]->Equals(Nan::True());
info.GetReturnValue().Set(
grpc_channel_check_connectivity_state(channel->wrapped_channel,
try_to_connect));
info.GetReturnValue().Set(grpc_channel_check_connectivity_state(
channel->wrapped_channel, try_to_connect));
}
NAN_METHOD(Channel::WatchConnectivityState) {
@ -268,8 +270,7 @@ NAN_METHOD(Channel::WatchConnectivityState) {
return Nan::ThrowTypeError(
"watchConnectivityState's third argument must be a callback");
}
grpc_connectivity_state last_state =
static_cast<grpc_connectivity_state>(
grpc_connectivity_state last_state = static_cast<grpc_connectivity_state>(
Nan::To<uint32_t>(info[0]).FromJust());
double deadline = Nan::To<double>(info[1]).FromJust();
Local<Function> callback_func = info[2].As<Function>();
@ -279,8 +280,7 @@ NAN_METHOD(Channel::WatchConnectivityState) {
grpc_channel_watch_connectivity_state(
channel->wrapped_channel, last_state, MillisecondsToTimespec(deadline),
GetCompletionQueue(),
new struct tag(callback,
ops.release(), NULL, Nan::Null()));
new struct tag(callback, ops.release(), NULL, Nan::Null()));
CompletionQueueNext();
}

View File

@ -34,8 +34,8 @@
#ifndef NET_GRPC_NODE_CHANNEL_H_
#define NET_GRPC_NODE_CHANNEL_H_
#include <node.h>
#include <nan.h>
#include <node.h>
#include "grpc/grpc.h"
namespace grpc {

View File

@ -33,12 +33,12 @@
#include <node.h>
#include "call.h"
#include "call_credentials.h"
#include "channel_credentials.h"
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
#include "grpc/support/log.h"
#include "channel_credentials.h"
#include "call_credentials.h"
#include "call.h"
namespace grpc {
namespace node {
@ -80,12 +80,12 @@ void ChannelCredentials::Init(Local<Object> exports) {
Nan::SetPrototypeMethod(tpl, "compose", Compose);
fun_tpl.Reset(tpl);
Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
Nan::Set(ctr, Nan::New("createSsl").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
Nan::Set(
ctr, Nan::New("createSsl").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
Nan::Set(ctr, Nan::New("createInsecure").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(CreateInsecure)).ToLocalChecked());
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateInsecure))
.ToLocalChecked());
Nan::Set(exports, Nan::New("ChannelCredentials").ToLocalChecked(), ctr);
constructor = new Nan::Callback(ctr);
}
@ -101,8 +101,8 @@ Local<Value> ChannelCredentials::WrapStruct(
const int argc = 1;
Local<Value> argv[argc] = {
Nan::New<External>(reinterpret_cast<void *>(credentials))};
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
constructor->GetFunction(), argc, argv);
MaybeLocal<Object> maybe_instance =
Nan::NewInstance(constructor->GetFunction(), argc, argv);
if (maybe_instance.IsEmpty()) {
return scope.Escape(Nan::Null());
} else {
@ -179,11 +179,10 @@ NAN_METHOD(ChannelCredentials::Compose) {
return Nan::ThrowTypeError(
"compose's first argument must be a CallCredentials object");
}
ChannelCredentials *self = ObjectWrap::Unwrap<ChannelCredentials>(
info.This());
ChannelCredentials *self =
ObjectWrap::Unwrap<ChannelCredentials>(info.This());
if (self->wrapped_credentials == NULL) {
return Nan::ThrowTypeError(
"Cannot compose insecure credential");
return Nan::ThrowTypeError("Cannot compose insecure credential");
}
CallCredentials *other = ObjectWrap::Unwrap<CallCredentials>(
Nan::To<Object>(info[0]).ToLocalChecked());

View File

@ -34,8 +34,8 @@
#ifndef NET_GRPC_NODE_CHANNEL_CREDENTIALS_H_
#define NET_GRPC_NODE_CHANNEL_CREDENTIALS_H_
#include <node.h>
#include <nan.h>
#include <node.h>
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"

View File

@ -31,8 +31,8 @@
*
*/
#include <v8.h>
#include <grpc/grpc.h>
#include <v8.h>
namespace grpc {
namespace node {

View File

@ -33,8 +33,8 @@
#include <queue>
#include <node.h>
#include <nan.h>
#include <node.h>
#include <v8.h>
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
@ -53,12 +53,12 @@ extern "C" {
#include "call_credentials.h"
#include "channel.h"
#include "channel_credentials.h"
#include "server.h"
#include "completion_queue.h"
#include "completion_queue_async_worker.h"
#include "server.h"
#include "server_credentials.h"
#include "slice.h"
#include "timeval.h"
#include "completion_queue.h"
using grpc::node::CreateSliceFromString;
@ -188,8 +188,7 @@ void InitOpTypeConstants(Local<Object> exports) {
Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_INITIAL_METADATA));
Nan::Set(op_type, Nan::New("SEND_INITIAL_METADATA").ToLocalChecked(),
SEND_INITIAL_METADATA);
Local<Value> SEND_MESSAGE(
Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_MESSAGE));
Local<Value> SEND_MESSAGE(Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_MESSAGE));
Nan::Set(op_type, Nan::New("SEND_MESSAGE").ToLocalChecked(), SEND_MESSAGE);
Local<Value> SEND_CLOSE_FROM_CLIENT(
Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_CLOSE_FROM_CLIENT));
@ -203,8 +202,7 @@ void InitOpTypeConstants(Local<Object> exports) {
Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_INITIAL_METADATA));
Nan::Set(op_type, Nan::New("RECV_INITIAL_METADATA").ToLocalChecked(),
RECV_INITIAL_METADATA);
Local<Value> RECV_MESSAGE(
Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_MESSAGE));
Local<Value> RECV_MESSAGE(Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_MESSAGE));
Nan::Set(op_type, Nan::New("RECV_MESSAGE").ToLocalChecked(), RECV_MESSAGE);
Local<Value> RECV_STATUS_ON_CLIENT(
Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_STATUS_ON_CLIENT));
@ -252,8 +250,7 @@ void InitConnectivityStateConstants(Local<Object> exports) {
Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_TRANSIENT_FAILURE));
Nan::Set(channel_state, Nan::New("TRANSIENT_FAILURE").ToLocalChecked(),
TRANSIENT_FAILURE);
Local<Value> FATAL_FAILURE(
Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_SHUTDOWN));
Local<Value> FATAL_FAILURE(Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_SHUTDOWN));
Nan::Set(channel_state, Nan::New("FATAL_FAILURE").ToLocalChecked(),
FATAL_FAILURE);
}
@ -282,13 +279,11 @@ void InitLogConstants(Local<Object> exports) {
NAN_METHOD(MetadataKeyIsLegal) {
if (!info[0]->IsString()) {
return Nan::ThrowTypeError(
"headerKeyIsLegal's argument must be a string");
return Nan::ThrowTypeError("headerKeyIsLegal's argument must be a string");
}
Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
grpc_slice slice = CreateSliceFromString(key);
info.GetReturnValue().Set(static_cast<bool>(
grpc_header_key_is_legal(slice)));
info.GetReturnValue().Set(static_cast<bool>(grpc_header_key_is_legal(slice)));
grpc_slice_unref(slice);
}
@ -299,8 +294,8 @@ NAN_METHOD(MetadataNonbinValueIsLegal) {
}
Local<String> value = Nan::To<String>(info[0]).ToLocalChecked();
grpc_slice slice = CreateSliceFromString(value);
info.GetReturnValue().Set(static_cast<bool>(
grpc_header_nonbin_value_is_legal(slice)));
info.GetReturnValue().Set(
static_cast<bool>(grpc_header_nonbin_value_is_legal(slice)));
grpc_slice_unref(slice);
}
@ -311,8 +306,7 @@ NAN_METHOD(MetadataKeyIsBinary) {
}
Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
grpc_slice slice = CreateSliceFromString(key);
info.GetReturnValue().Set(static_cast<bool>(
grpc_is_binary_header(slice)));
info.GetReturnValue().Set(static_cast<bool>(grpc_is_binary_header(slice)));
grpc_slice_unref(slice);
}
@ -354,11 +348,13 @@ NAUV_WORK_CB(LogMessagesCallback) {
args.pop();
Local<Value> file = Nan::New(arg->core_args.file).ToLocalChecked();
Local<Value> line = Nan::New<Uint32, uint32_t>(arg->core_args.line);
Local<Value> severity = Nan::New(
gpr_log_severity_string(arg->core_args.severity)).ToLocalChecked();
Local<Value> severity =
Nan::New(gpr_log_severity_string(arg->core_args.severity))
.ToLocalChecked();
Local<Value> message = Nan::New(arg->core_args.message).ToLocalChecked();
Local<Value> timestamp = Nan::New<v8::Date>(
grpc::node::TimespecToMilliseconds(arg->timestamp)).ToLocalChecked();
Local<Value> timestamp =
Nan::New<v8::Date>(grpc::node::TimespecToMilliseconds(arg->timestamp))
.ToLocalChecked();
const int argc = 5;
Local<Value> argv[argc] = {file, line, severity, message, timestamp};
grpc_logger_state.callback->Call(argc, argv);
@ -388,8 +384,7 @@ void init_logger() {
memset(&grpc_logger_state, 0, sizeof(logger_state));
grpc_logger_state.pending_args = new std::queue<log_args *>();
uv_mutex_init(&grpc_logger_state.mutex);
uv_async_init(uv_default_loop(),
&grpc_logger_state.async,
uv_async_init(uv_default_loop(), &grpc_logger_state.async,
LogMessagesCallback);
uv_unref((uv_handle_t *)&grpc_logger_state.async);
grpc_logger_state.logger_set = false;
@ -416,11 +411,10 @@ NAN_METHOD(SetDefaultLoggerCallback) {
NAN_METHOD(SetLogVerbosity) {
if (!info[0]->IsUint32()) {
return Nan::ThrowTypeError(
"setLogVerbosity's argument must be a number");
return Nan::ThrowTypeError("setLogVerbosity's argument must be a number");
}
gpr_log_severity severity = static_cast<gpr_log_severity>(
Nan::To<uint32_t>(info[0]).FromJust());
gpr_log_severity severity =
static_cast<gpr_log_severity>(Nan::To<uint32_t>(info[0]).FromJust());
gpr_set_log_verbosity(severity);
}
@ -453,28 +447,25 @@ void init(Local<Object> exports) {
// Attach a few utility functions directly to the module
Nan::Set(exports, Nan::New("metadataKeyIsLegal").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(MetadataKeyIsLegal)).ToLocalChecked());
Nan::Set(exports, Nan::New("metadataNonbinValueIsLegal").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(MetadataNonbinValueIsLegal)
).ToLocalChecked());
Nan::GetFunction(Nan::New<FunctionTemplate>(MetadataKeyIsLegal))
.ToLocalChecked());
Nan::Set(
exports, Nan::New("metadataNonbinValueIsLegal").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(MetadataNonbinValueIsLegal))
.ToLocalChecked());
Nan::Set(exports, Nan::New("metadataKeyIsBinary").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(MetadataKeyIsBinary)
).ToLocalChecked());
Nan::GetFunction(Nan::New<FunctionTemplate>(MetadataKeyIsBinary))
.ToLocalChecked());
Nan::Set(exports, Nan::New("setDefaultRootsPem").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(SetDefaultRootsPem)
).ToLocalChecked());
Nan::Set(exports, Nan::New("setDefaultLoggerCallback").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(SetDefaultLoggerCallback)
).ToLocalChecked());
Nan::GetFunction(Nan::New<FunctionTemplate>(SetDefaultRootsPem))
.ToLocalChecked());
Nan::Set(
exports, Nan::New("setDefaultLoggerCallback").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(SetDefaultLoggerCallback))
.ToLocalChecked());
Nan::Set(exports, Nan::New("setLogVerbosity").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(SetLogVerbosity)
).ToLocalChecked());
Nan::GetFunction(Nan::New<FunctionTemplate>(SetLogVerbosity))
.ToLocalChecked());
}
NODE_MODULE(grpc_node, init)

View File

@ -111,14 +111,9 @@ class NewCallOp : public Op {
return scope.Escape(obj);
}
bool ParseOp(Local<Value> value, grpc_op *out) {
return true;
}
bool IsFinalOp() {
return false;
}
void OnComplete(bool success) {
}
bool ParseOp(Local<Value> value, grpc_op *out) { return true; }
bool IsFinalOp() { return false; }
void OnComplete(bool success) {}
grpc_call *call;
grpc_call_details details;
@ -137,19 +132,17 @@ class TryShutdownOp: public Op {
EscapableHandleScope scope;
return scope.Escape(Nan::New(server_persist));
}
bool ParseOp(Local<Value> value, grpc_op *out) {
return true;
}
bool IsFinalOp() {
return false;
}
bool ParseOp(Local<Value> value, grpc_op *out) { return true; }
bool IsFinalOp() { return false; }
void OnComplete(bool success) {
if (success) {
server->DestroyWrappedServer();
}
}
protected:
std::string GetTypeString() const { return "try_shutdown"; }
private:
Server *server;
Nan::Persistent<v8::Value, Nan::CopyablePersistentTraits<v8::Value>>
@ -227,10 +220,9 @@ NAN_METHOD(Server::RequestCall) {
ops->push_back(unique_ptr<Op>(op));
grpc_call_error error = grpc_server_request_call(
server->wrapped_server, &op->call, &op->details, &op->request_metadata,
GetCompletionQueue(),
GetCompletionQueue(),
new struct tag(new Callback(info[0].As<Function>()), ops.release(),
NULL, Nan::Null()));
GetCompletionQueue(), GetCompletionQueue(),
new struct tag(new Callback(info[0].As<Function>()), ops.release(), NULL,
Nan::Null()));
if (error != GRPC_CALL_OK) {
return Nan::ThrowError(nanErrorWithCode("requestCall failed", error));
}

View File

@ -34,8 +34,8 @@
#ifndef NET_GRPC_NODE_SERVER_H_
#define NET_GRPC_NODE_SERVER_H_
#include <node.h>
#include <nan.h>
#include <node.h>
#include "grpc/grpc.h"
namespace grpc {

View File

@ -78,12 +78,12 @@ void ServerCredentials::Init(Local<Object> exports) {
tpl->SetClassName(Nan::New("ServerCredentials").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> ctr = tpl->GetFunction();
Nan::Set(ctr, Nan::New("createSsl").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
Nan::Set(
ctr, Nan::New("createSsl").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
Nan::Set(ctr, Nan::New("createInsecure").ToLocalChecked(),
Nan::GetFunction(
Nan::New<FunctionTemplate>(CreateInsecure)).ToLocalChecked());
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateInsecure))
.ToLocalChecked());
fun_tpl.Reset(tpl);
constructor = new Nan::Callback(ctr);
Nan::Set(exports, Nan::New("ServerCredentials").ToLocalChecked(), ctr);
@ -100,8 +100,8 @@ Local<Value> ServerCredentials::WrapStruct(
const int argc = 1;
Local<Value> argv[argc] = {
Nan::New<External>(reinterpret_cast<void *>(credentials))};
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
constructor->GetFunction(), argc, argv);
MaybeLocal<Object> maybe_instance =
Nan::NewInstance(constructor->GetFunction(), argc, argv);
if (maybe_instance.IsEmpty()) {
return scope.Escape(Nan::Null());
} else {
@ -160,8 +160,8 @@ NAN_METHOD(ServerCredentials::CreateSsl) {
}
Local<Array> pair_list = Local<Array>::Cast(info[1]);
uint32_t key_cert_pair_count = pair_list->Length();
grpc_ssl_pem_key_cert_pair *key_cert_pairs = new grpc_ssl_pem_key_cert_pair[
key_cert_pair_count];
grpc_ssl_pem_key_cert_pair *key_cert_pairs =
new grpc_ssl_pem_key_cert_pair[key_cert_pair_count];
Local<String> key_key = Nan::New("private_key").ToLocalChecked();
Local<String> cert_key = Nan::New("cert_chain").ToLocalChecked();

View File

@ -34,8 +34,8 @@
#ifndef NET_GRPC_NODE_SERVER_CREDENTIALS_H_
#define NET_GRPC_NODE_SERVER_CREDENTIALS_H_
#include <node.h>
#include <nan.h>
#include <node.h>
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"

View File

@ -35,8 +35,8 @@
#include "server.h"
#include <node.h>
#include <nan.h>
#include <node.h>
#include "grpc/grpc.h"
#include "grpc/support/time.h"
@ -60,22 +60,14 @@ static Callback *shutdown_callback = NULL;
class ServerShutdownOp : public Op {
public:
ServerShutdownOp(grpc_server *server): server(server) {
}
ServerShutdownOp(grpc_server *server) : server(server) {}
~ServerShutdownOp() {
}
~ServerShutdownOp() {}
Local<Value> GetNodeValue() const {
return Nan::Null();
}
Local<Value> GetNodeValue() const { return Nan::Null(); }
bool ParseOp(Local<Value> value, grpc_op *out) {
return true;
}
bool IsFinalOp() {
return false;
}
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 */
@ -88,12 +80,9 @@ class ServerShutdownOp : public Op {
std::string GetTypeString() const { return "shutdown"; }
};
Server::Server(grpc_server *server) : wrapped_server(server) {
}
Server::Server(grpc_server *server) : wrapped_server(server) {}
Server::~Server() {
this->ShutdownServer();
}
Server::~Server() { this->ShutdownServer(); }
NAN_METHOD(ServerShutdownCallback) {
if (!info[0]->IsNull()) {
@ -107,8 +96,8 @@ void Server::ShutdownServer() {
if (shutdown_callback == NULL) {
Local<FunctionTemplate> callback_tpl =
Nan::New<FunctionTemplate>(ServerShutdownCallback);
shutdown_callback = new Callback(
Nan::GetFunction(callback_tpl).ToLocalChecked());
shutdown_callback =
new Callback(Nan::GetFunction(callback_tpl).ToLocalChecked());
}
ServerShutdownOp *op = new ServerShutdownOp(this->wrapped_server);

View File

@ -31,10 +31,10 @@
*
*/
#include <node.h>
#include <nan.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <nan.h>
#include <node.h>
#include "slice.h"
@ -73,28 +73,32 @@ grpc_slice CreateSliceFromString(const Local<String> source) {
grpc_slice CreateSliceFromBuffer(const Local<Value> source) {
// Prerequisite: ::node::Buffer::HasInstance(source)
Nan::HandleScope scope;
return grpc_slice_new_with_user_data(::node::Buffer::Data(source),
::node::Buffer::Length(source),
buffer_destroy_func,
new PersistentValue(source));
return grpc_slice_new_with_user_data(
::node::Buffer::Data(source), ::node::Buffer::Length(source),
buffer_destroy_func, new PersistentValue(source));
}
Local<String> CopyStringFromSlice(const grpc_slice slice) {
Nan::EscapableHandleScope scope;
if (GRPC_SLICE_LENGTH(slice) == 0) {
return scope.Escape(Nan::EmptyString());
}
return scope.Escape(Nan::New<String>(
const_cast<char *>(reinterpret_cast<const char *>(GRPC_SLICE_START_PTR(slice))),
GRPC_SLICE_LENGTH(slice)).ToLocalChecked());
return scope.Escape(
Nan::New<String>(const_cast<char *>(reinterpret_cast<const char *>(
GRPC_SLICE_START_PTR(slice))),
GRPC_SLICE_LENGTH(slice))
.ToLocalChecked());
}
Local<Value> CreateBufferFromSlice(const grpc_slice slice) {
Nan::EscapableHandleScope scope;
grpc_slice *slice_ptr = new grpc_slice;
*slice_ptr = grpc_slice_ref(slice);
return scope.Escape(Nan::NewBuffer(
const_cast<char *>(reinterpret_cast<const char *>(GRPC_SLICE_START_PTR(*slice_ptr))),
GRPC_SLICE_LENGTH(*slice_ptr), SliceFreeCallback, slice_ptr).ToLocalChecked());
return scope.Escape(
Nan::NewBuffer(
const_cast<char *>(
reinterpret_cast<const char *>(GRPC_SLICE_START_PTR(*slice_ptr))),
GRPC_SLICE_LENGTH(*slice_ptr), SliceFreeCallback, slice_ptr)
.ToLocalChecked());
}
} // namespace node

View File

@ -31,14 +31,15 @@
*
*/
#include <node.h>
#include <nan.h>
#include <grpc/slice.h>
#include <nan.h>
#include <node.h>
namespace grpc {
namespace node {
typedef Nan::Persistent<v8::Value, Nan::CopyablePersistentTraits<v8::Value>> PersistentValue;
typedef Nan::Persistent<v8::Value, Nan::CopyablePersistentTraits<v8::Value>>
PersistentValue;
grpc_slice CreateSliceFromString(const v8::Local<v8::String> source);

View File

@ -31,8 +31,8 @@
*
*/
#include <limits>
#include <cstdint>
#include <limits>
#include "grpc/grpc.h"
#include "grpc/support/time.h"

View File

@ -88,7 +88,10 @@ function timeDiffToNanos(time_diff) {
*/
function BenchmarkClient(server_targets, channels, histogram_params,
security_params) {
var options = {};
var options = {
"grpc.max_receive_message_length": -1,
"grpc.max_send_message_length": -1
};
var creds;
if (security_params) {
var ca_path;
@ -180,6 +183,8 @@ BenchmarkClient.prototype.startClosedLoop = function(
self.last_wall_time = process.hrtime();
self.last_usage = process.cpuUsage();
var makeCall;
var argument;
@ -270,6 +275,8 @@ BenchmarkClient.prototype.startPoisson = function(
self.last_wall_time = process.hrtime();
self.last_usage = process.cpuUsage();
var makeCall;
var argument;
@ -354,9 +361,11 @@ BenchmarkClient.prototype.startPoisson = function(
*/
BenchmarkClient.prototype.mark = function(reset) {
var wall_time_diff = process.hrtime(this.last_wall_time);
var usage_diff = process.cpuUsage(this.last_usage);
var histogram = this.histogram;
if (reset) {
this.last_wall_time = process.hrtime();
this.last_usage = process.cpuUsage();
this.histogram = new Histogram(histogram.resolution,
histogram.max_possible);
}
@ -371,9 +380,8 @@ BenchmarkClient.prototype.mark = function(reset) {
count: histogram.getCount()
},
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
// Not sure how to measure these values
time_user: 0,
time_system: 0
time_user: usage_diff.user / 1000000,
time_system: usage_diff.system / 1000000
};
};

View File

@ -95,7 +95,6 @@ function BenchmarkClient(server_targets, channels, histogram_params,
var host_port;
host_port = server_targets[i % server_targets.length].split(':');
var new_options = _.assign({hostname: host_port[0], port: +host_port[1]}, options);
new_options.agent = new protocol.Agent(new_options);
this.client_options[i] = new_options;
}
@ -137,6 +136,7 @@ BenchmarkClient.prototype.startClosedLoop = function(
}
self.last_wall_time = process.hrtime();
self.last_usage = process.cpuUsage();
var argument = {
response_size: resp_size,
@ -207,6 +207,7 @@ BenchmarkClient.prototype.startPoisson = function(
}
self.last_wall_time = process.hrtime();
self.last_usage = process.cpuUsage();
var argument = {
response_size: resp_size,
@ -264,9 +265,11 @@ BenchmarkClient.prototype.startPoisson = function(
*/
BenchmarkClient.prototype.mark = function(reset) {
var wall_time_diff = process.hrtime(this.last_wall_time);
var usage_diff = process.cpuUsage(this.last_usage);
var histogram = this.histogram;
if (reset) {
this.last_wall_time = process.hrtime();
this.last_usage = process.cpuUsage();
this.histogram = new Histogram(histogram.resolution,
histogram.max_possible);
}
@ -281,9 +284,8 @@ BenchmarkClient.prototype.mark = function(reset) {
count: histogram.getCount()
},
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
// Not sure how to measure these values
time_user: 0,
time_system: 0
time_user: usage_diff.user / 1000000,
time_system: usage_diff.system / 1000000
};
};

View File

@ -132,7 +132,12 @@ function BenchmarkServer(host, port, tls, generic, response_size) {
server_creds = grpc.ServerCredentials.createInsecure();
}
var server = new grpc.Server();
var options = {
"grpc.max_receive_message_length": -1,
"grpc.max_send_message_length": -1
};
var server = new grpc.Server(options);
this.port = server.bind(host + ':' + port, server_creds);
if (generic) {
server.addService(genericService, {
@ -156,6 +161,7 @@ util.inherits(BenchmarkServer, EventEmitter);
BenchmarkServer.prototype.start = function() {
this.server.start();
this.last_wall_time = process.hrtime();
this.last_usage = process.cpuUsage();
this.emit('started');
};
@ -175,14 +181,15 @@ BenchmarkServer.prototype.getPort = function() {
*/
BenchmarkServer.prototype.mark = function(reset) {
var wall_time_diff = process.hrtime(this.last_wall_time);
var usage_diff = process.cpuUsage(this.last_usage);
if (reset) {
this.last_wall_time = process.hrtime();
this.last_usage = process.cpuUsage();
}
return {
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
// Not sure how to measure these values
time_user: 0,
time_system: 0
time_user: usage_diff.user / 1000000,
time_system: usage_diff.system / 1000000
};
};

View File

@ -81,6 +81,7 @@ BenchmarkServer.prototype.start = function() {
var self = this;
this.server.listen(this.input_port, this.input_hostname, function() {
self.last_wall_time = process.hrtime();
self.last_usage = process.cpuUsage();
self.emit('started');
});
};
@ -91,14 +92,15 @@ BenchmarkServer.prototype.getPort = function() {
BenchmarkServer.prototype.mark = function(reset) {
var wall_time_diff = process.hrtime(this.last_wall_time);
var usage_diff = process.cpuUsage(this.last_usage);
if (reset) {
this.last_wall_time = process.hrtime();
this.last_usage = process.cpuUsage();
}
return {
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
// Not sure how to measure these values
time_user: 0,
time_system: 0
time_user: usage_diff.user / 1000000,
time_system: usage_diff.system / 1000000
};
};