mirror of https://github.com/grpc/grpc-node.git
Merge github.com:grpc/grpc into cpparena
This commit is contained in:
commit
db70eca069
|
@ -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"
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <node.h>
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include "grpc/grpc.h"
|
||||
|
||||
namespace grpc {
|
||||
|
|
|
@ -332,7 +332,6 @@ class SendServerStatusOp : public Op {
|
|||
out->data.send_status_from_server.status_details = &this->details;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsFinalOp() { return true; }
|
||||
void OnComplete(bool success) {}
|
||||
|
||||
|
@ -359,7 +358,6 @@ class GetMetadataOp : public Op {
|
|||
out->data.recv_initial_metadata.recv_initial_metadata = &recv_metadata;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsFinalOp() { return false; }
|
||||
void OnComplete(bool success) {}
|
||||
|
||||
|
@ -387,7 +385,6 @@ class ReadMessageOp : public Op {
|
|||
out->data.recv_message.recv_message = &recv_message;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsFinalOp() { return false; }
|
||||
void OnComplete(bool success) {}
|
||||
|
||||
|
@ -422,7 +419,6 @@ class ClientStatusOp : public Op {
|
|||
ParseMetadata(&metadata_array));
|
||||
return scope.Escape(status_obj);
|
||||
}
|
||||
|
||||
bool IsFinalOp() { return true; }
|
||||
void OnComplete(bool success) {}
|
||||
|
||||
|
@ -446,7 +442,6 @@ class ServerCloseResponseOp : public Op {
|
|||
out->data.recv_close_on_server.cancelled = &cancelled;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsFinalOp() { return false; }
|
||||
void OnComplete(bool success) {}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
@ -109,9 +109,9 @@ Local<Value> CallCredentials::WrapStruct(grpc_call_credentials *credentials) {
|
|||
return scope.Escape(Nan::Null());
|
||||
}
|
||||
Local<Value> argv[argc] = {
|
||||
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
||||
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
|
||||
constructor->GetFunction(), argc, argv);
|
||||
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
||||
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(
|
||||
|
@ -170,21 +168,19 @@ NAN_METHOD(CallCredentials::CreateFromPlugin) {
|
|||
grpc_metadata_credentials_plugin plugin;
|
||||
plugin_state *state = new plugin_state;
|
||||
state->callback = new Nan::Callback(info[0].As<Function>());
|
||||
state->pending_callbacks = new std::queue<plugin_callback_data*>();
|
||||
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_unref((uv_handle_t*)&state->plugin_async);
|
||||
uv_async_init(uv_default_loop(), &state->plugin_async, SendPluginCallback);
|
||||
uv_unref((uv_handle_t *)&state->plugin_async);
|
||||
|
||||
state->plugin_async.data = state;
|
||||
|
||||
plugin.get_metadata = plugin_get_metadata;
|
||||
plugin.destroy = plugin_destroy_state;
|
||||
plugin.state = reinterpret_cast<void*>(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,34 +202,35 @@ 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);
|
||||
}
|
||||
|
||||
NAUV_WORK_CB(SendPluginCallback) {
|
||||
Nan::HandleScope scope;
|
||||
plugin_state *state = reinterpret_cast<plugin_state*>(async->data);
|
||||
std::queue<plugin_callback_data*> callbacks;
|
||||
plugin_state *state = reinterpret_cast<plugin_state *>(async->data);
|
||||
std::queue<plugin_callback_data *> callbacks;
|
||||
uv_mutex_lock(&state->plugin_mutex);
|
||||
state->pending_callbacks->swap(callbacks);
|
||||
uv_mutex_unlock(&state->plugin_mutex);
|
||||
|
@ -242,16 +239,14 @@ NAUV_WORK_CB(SendPluginCallback) {
|
|||
callbacks.pop();
|
||||
Local<Object> callback_data = Nan::New<Object>();
|
||||
Nan::Set(callback_data, Nan::New("cb").ToLocalChecked(),
|
||||
Nan::New<v8::External>(reinterpret_cast<void*>(data->cb)));
|
||||
Nan::New<v8::External>(reinterpret_cast<void *>(data->cb)));
|
||||
Nan::Set(callback_data, Nan::New("user_data").ToLocalChecked(),
|
||||
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,
|
||||
// Get Local<Function> from Nan::Callback*
|
||||
**plugin_callback
|
||||
};
|
||||
Nan::New(data->service_url).ToLocalChecked(), callback_data,
|
||||
// Get Local<Function> from Nan::Callback*
|
||||
**plugin_callback};
|
||||
Nan::Callback *callback = state->callback;
|
||||
callback->Call(argc, argv);
|
||||
delete data;
|
||||
|
@ -261,7 +256,7 @@ NAUV_WORK_CB(SendPluginCallback) {
|
|||
void plugin_get_metadata(void *state, grpc_auth_metadata_context context,
|
||||
grpc_credentials_plugin_metadata_cb cb,
|
||||
void *user_data) {
|
||||
plugin_state *p_state = reinterpret_cast<plugin_state*>(state);
|
||||
plugin_state *p_state = reinterpret_cast<plugin_state *>(state);
|
||||
plugin_callback_data *data = new plugin_callback_data;
|
||||
data->service_url = context.service_url;
|
||||
data->cb = cb;
|
||||
|
@ -275,7 +270,7 @@ void plugin_get_metadata(void *state, grpc_auth_metadata_context context,
|
|||
}
|
||||
|
||||
void plugin_uv_close_cb(uv_handle_t *handle) {
|
||||
uv_async_t *async = reinterpret_cast<uv_async_t*>(handle);
|
||||
uv_async_t *async = reinterpret_cast<uv_async_t *>(handle);
|
||||
plugin_state *state = reinterpret_cast<plugin_state *>(async->data);
|
||||
uv_mutex_destroy(&state->plugin_mutex);
|
||||
delete state->pending_callbacks;
|
||||
|
@ -285,7 +280,7 @@ void plugin_uv_close_cb(uv_handle_t *handle) {
|
|||
|
||||
void plugin_destroy_state(void *ptr) {
|
||||
plugin_state *state = reinterpret_cast<plugin_state *>(ptr);
|
||||
uv_close((uv_handle_t*)&state->plugin_async, plugin_uv_close_cb);
|
||||
uv_close((uv_handle_t *)&state->plugin_async, plugin_uv_close_cb);
|
||||
}
|
||||
|
||||
} // namespace node
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
|
||||
#include <queue>
|
||||
|
||||
#include <node.h>
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include <uv.h>
|
||||
#include "grpc/grpc_security.h"
|
||||
|
||||
|
@ -84,7 +84,7 @@ typedef struct plugin_callback_data {
|
|||
|
||||
typedef struct plugin_state {
|
||||
Nan::Callback *callback;
|
||||
std::queue<plugin_callback_data*> *pending_callbacks;
|
||||
std::queue<plugin_callback_data *> *pending_callbacks;
|
||||
uv_mutex_t plugin_mutex;
|
||||
// async.data == this
|
||||
uv_async_t plugin_async;
|
||||
|
|
|
@ -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 "
|
||||
"string keys and integer or string values");
|
||||
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,9 +270,8 @@ 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>(
|
||||
Nan::To<uint32_t>(info[0]).FromJust());
|
||||
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>();
|
||||
Nan::Callback *callback = new Callback(callback_func);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -100,9 +100,9 @@ Local<Value> ChannelCredentials::WrapStruct(
|
|||
EscapableHandleScope scope;
|
||||
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);
|
||||
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
||||
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());
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <v8.h>
|
||||
#include <grpc/grpc.h>
|
||||
#include <v8.h>
|
||||
|
||||
namespace grpc {
|
||||
namespace node {
|
||||
|
|
|
@ -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,10 +384,9 @@ 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);
|
||||
uv_unref((uv_handle_t *)&grpc_logger_state.async);
|
||||
grpc_logger_state.logger_set = false;
|
||||
|
||||
gpr_log_verbosity_init();
|
||||
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
@ -128,7 +123,7 @@ class NewCallOp : public Op {
|
|||
std::string GetTypeString() const { return "new_call"; }
|
||||
};
|
||||
|
||||
class TryShutdownOp: public Op {
|
||||
class TryShutdownOp : public Op {
|
||||
public:
|
||||
TryShutdownOp(Server *server, Local<Value> server_value) : server(server) {
|
||||
server_persist.Reset(server_value);
|
||||
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
@ -99,9 +99,9 @@ Local<Value> ServerCredentials::WrapStruct(
|
|||
Nan::EscapableHandleScope scope;
|
||||
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);
|
||||
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
||||
MaybeLocal<Object> maybe_instance =
|
||||
Nan::NewInstance(constructor->GetFunction(), argc, argv);
|
||||
if (maybe_instance.IsEmpty()) {
|
||||
return scope.Escape(Nan::Null());
|
||||
} else {
|
||||
|
@ -160,13 +160,13 @@ 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();
|
||||
|
||||
for(uint32_t i = 0; i < key_cert_pair_count; i++) {
|
||||
for (uint32_t i = 0; i < key_cert_pair_count; i++) {
|
||||
Local<Value> pair_val = Nan::Get(pair_list, i).ToLocalChecked();
|
||||
if (!pair_val->IsObject()) {
|
||||
delete[] key_cert_pairs;
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
@ -105,10 +94,10 @@ void Server::ShutdownServer() {
|
|||
Nan::HandleScope scope;
|
||||
if (this->wrapped_server != NULL) {
|
||||
if (shutdown_callback == NULL) {
|
||||
Local<FunctionTemplate>callback_tpl =
|
||||
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);
|
||||
|
|
36
ext/slice.cc
36
ext/slice.cc
|
@ -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"
|
||||
|
||||
|
@ -49,19 +49,19 @@ using v8::Value;
|
|||
|
||||
namespace {
|
||||
void SliceFreeCallback(char *data, void *hint) {
|
||||
grpc_slice *slice = reinterpret_cast<grpc_slice*>(hint);
|
||||
grpc_slice *slice = reinterpret_cast<grpc_slice *>(hint);
|
||||
grpc_slice_unref(*slice);
|
||||
delete slice;
|
||||
}
|
||||
|
||||
void string_destroy_func(void *user_data) {
|
||||
delete reinterpret_cast<Nan::Utf8String*>(user_data);
|
||||
delete reinterpret_cast<Nan::Utf8String *>(user_data);
|
||||
}
|
||||
|
||||
void buffer_destroy_func(void *user_data) {
|
||||
delete reinterpret_cast<PersistentValue*>(user_data);
|
||||
delete reinterpret_cast<PersistentValue *>(user_data);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
grpc_slice CreateSliceFromString(const Local<String> source) {
|
||||
Nan::HandleScope scope;
|
||||
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <limits>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
#include "grpc/grpc.h"
|
||||
#include "grpc/support/time.h"
|
||||
|
|
Loading…
Reference in New Issue