mirror of https://github.com/grpc/grpc-node.git
Merge remote-tracking branch 'upstream/v1.3.x' into node_only_uv
This commit is contained in:
commit
6f3bea8fa7
|
|
@ -33,10 +33,10 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include "grpc/byte_buffer_reader.h"
|
||||
#include <nan.h>
|
||||
#include "grpc/grpc.h"
|
||||
#include "grpc/byte_buffer_reader.h"
|
||||
#include "grpc/slice.h"
|
||||
|
||||
#include "byte_buffer.h"
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.h>
|
||||
#include "grpc/grpc.h"
|
||||
|
||||
namespace grpc {
|
||||
|
|
|
|||
259
ext/call.cc
259
ext/call.cc
|
|
@ -31,22 +31,22 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <node.h>
|
||||
|
||||
#include "byte_buffer.h"
|
||||
#include "call.h"
|
||||
#include "call_credentials.h"
|
||||
#include "channel.h"
|
||||
#include "completion_queue.h"
|
||||
#include "grpc/support/log.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 "byte_buffer.h"
|
||||
#include "call.h"
|
||||
#include "channel.h"
|
||||
#include "completion_queue.h"
|
||||
#include "call_credentials.h"
|
||||
#include "slice.h"
|
||||
#include "timeval.h"
|
||||
|
||||
|
|
@ -100,20 +100,20 @@ 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;
|
||||
}
|
||||
array->capacity += Local<Array>::Cast(value_array)->Length();
|
||||
}
|
||||
array->metadata = reinterpret_cast<grpc_metadata *>(
|
||||
array->metadata = reinterpret_cast<grpc_metadata*>(
|
||||
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);
|
||||
|
|
@ -156,7 +156,7 @@ Local<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
|
|||
size_t length = metadata_array->count;
|
||||
Local<Object> metadata_object = Nan::New<Object>();
|
||||
for (unsigned int i = 0; i < length; i++) {
|
||||
grpc_metadata *elem = &metadata_elements[i];
|
||||
grpc_metadata* elem = &metadata_elements[i];
|
||||
// TODO(murgatroid99): Use zero-copy string construction instead
|
||||
Local<String> key_string = CopyStringFromSlice(elem->key);
|
||||
Local<Array> array;
|
||||
|
|
@ -182,12 +182,17 @@ 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());
|
||||
|
|
@ -200,26 +205,32 @@ 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);
|
||||
|
|
@ -234,8 +245,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()) {
|
||||
|
|
@ -247,13 +258,15 @@ 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;
|
||||
};
|
||||
|
|
@ -264,18 +277,25 @@ 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);
|
||||
|
|
@ -289,18 +309,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;
|
||||
}
|
||||
|
|
@ -308,16 +328,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;
|
||||
}
|
||||
|
|
@ -331,11 +351,15 @@ 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;
|
||||
|
|
@ -344,9 +368,13 @@ 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;
|
||||
|
|
@ -357,11 +385,16 @@ 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;
|
||||
|
|
@ -369,7 +402,9 @@ 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);
|
||||
|
|
@ -384,11 +419,16 @@ 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;
|
||||
|
|
@ -396,9 +436,13 @@ 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;
|
||||
|
|
@ -411,19 +455,22 @@ class ClientStatusOp : public Op {
|
|||
EscapableHandleScope scope;
|
||||
Local<Object> status_obj = Nan::New<Object>();
|
||||
Nan::Set(status_obj, Nan::New("code").ToLocalChecked(),
|
||||
Nan::New<Number>(status));
|
||||
Nan::New<Number>(status));
|
||||
Nan::Set(status_obj, Nan::New("details").ToLocalChecked(),
|
||||
CopyStringFromSlice(status_details));
|
||||
CopyStringFromSlice(status_details));
|
||||
Nan::Set(status_obj, Nan::New("metadata").ToLocalChecked(),
|
||||
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;
|
||||
|
|
@ -441,18 +488,23 @@ 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);
|
||||
}
|
||||
|
|
@ -502,15 +554,19 @@ void DestroyTag(void *tag) {
|
|||
|
||||
void Call::DestroyCall() {
|
||||
if (this->wrapped_call != NULL) {
|
||||
grpc_call_unref(this->wrapped_call);
|
||||
grpc_call_destroy(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;
|
||||
|
|
@ -539,10 +595,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 {
|
||||
|
|
@ -574,7 +630,8 @@ 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])) {
|
||||
|
|
@ -590,8 +647,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(
|
||||
|
|
@ -612,20 +669,22 @@ 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");
|
||||
}
|
||||
|
|
@ -639,8 +698,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;
|
||||
|
|
@ -713,8 +772,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));
|
||||
}
|
||||
|
|
@ -747,8 +806,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");
|
||||
|
|
|
|||
|
|
@ -37,13 +37,14 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.h>
|
||||
#include "grpc/grpc.h"
|
||||
#include "grpc/support/log.h"
|
||||
|
||||
#include "channel.h"
|
||||
|
||||
|
||||
namespace grpc {
|
||||
namespace node {
|
||||
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.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,6 +160,8 @@ NAN_METHOD(CallCredentials::Compose) {
|
|||
info.GetReturnValue().Set(WrapStruct(creds));
|
||||
}
|
||||
|
||||
|
||||
|
||||
NAN_METHOD(CallCredentials::CreateFromPlugin) {
|
||||
if (!info[0]->IsFunction()) {
|
||||
return Nan::ThrowTypeError(
|
||||
|
|
@ -168,19 +170,21 @@ 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));
|
||||
}
|
||||
|
||||
|
|
@ -202,35 +206,34 @@ 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);
|
||||
|
|
@ -239,14 +242,16 @@ 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;
|
||||
|
|
@ -256,7 +261,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;
|
||||
|
|
@ -270,7 +275,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;
|
||||
|
|
@ -280,7 +285,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 <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.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,14 +35,14 @@
|
|||
|
||||
#include "grpc/support/log.h"
|
||||
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include "call.h"
|
||||
#include "channel.h"
|
||||
#include "channel_credentials.h"
|
||||
#include "completion_queue.h"
|
||||
#include <nan.h>
|
||||
#include "grpc/grpc.h"
|
||||
#include "grpc/grpc_security.h"
|
||||
#include "call.h"
|
||||
#include "channel.h"
|
||||
#include "completion_queue.h"
|
||||
#include "channel_credentials.h"
|
||||
#include "timeval.h"
|
||||
|
||||
namespace grpc {
|
||||
|
|
@ -81,8 +81,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();
|
||||
|
|
@ -103,16 +103,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;
|
||||
|
|
@ -189,13 +189,12 @@ 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 +207,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,13 +231,11 @@ 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) {
|
||||
|
|
@ -248,8 +245,9 @@ 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) {
|
||||
|
|
@ -269,8 +267,9 @@ 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,7 +278,8 @@ 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 <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.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,10 +179,11 @@ 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 <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.h>
|
||||
#include "grpc/grpc.h"
|
||||
#include "grpc/grpc_security.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <grpc/grpc.h>
|
||||
#include <node.h>
|
||||
#include <uv.h>
|
||||
#include <node.h>
|
||||
#include <v8.h>
|
||||
#include <grpc/grpc.h>
|
||||
|
||||
#include "call.h"
|
||||
#include "completion_queue.h"
|
||||
|
|
@ -55,8 +55,8 @@ void drain_completion_queue(uv_prepare_t *handle) {
|
|||
grpc_event event;
|
||||
(void)handle;
|
||||
do {
|
||||
event = grpc_completion_queue_next(queue, gpr_inf_past(GPR_CLOCK_MONOTONIC),
|
||||
NULL);
|
||||
event = grpc_completion_queue_next(
|
||||
queue, gpr_inf_past(GPR_CLOCK_MONOTONIC), NULL);
|
||||
|
||||
if (event.type == GRPC_OP_COMPLETE) {
|
||||
const char *error_message;
|
||||
|
|
@ -75,7 +75,9 @@ void drain_completion_queue(uv_prepare_t *handle) {
|
|||
} while (event.type != GRPC_QUEUE_TIMEOUT);
|
||||
}
|
||||
|
||||
grpc_completion_queue *GetCompletionQueue() { return queue; }
|
||||
grpc_completion_queue *GetCompletionQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
void CompletionQueueNext() {
|
||||
if (pending_batches == 0) {
|
||||
|
|
@ -86,7 +88,7 @@ void CompletionQueueNext() {
|
|||
}
|
||||
|
||||
void CompletionQueueInit(Local<Object> exports) {
|
||||
queue = grpc_completion_queue_create_for_next(NULL);
|
||||
queue = grpc_completion_queue_create(NULL);
|
||||
uv_prepare_init(uv_default_loop(), &prepare);
|
||||
pending_batches = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <grpc/grpc.h>
|
||||
#include <v8.h>
|
||||
#include <grpc/grpc.h>
|
||||
|
||||
namespace grpc {
|
||||
namespace node {
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@
|
|||
|
||||
#include <queue>
|
||||
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.h>
|
||||
#include <v8.h>
|
||||
#include "grpc/grpc.h"
|
||||
#include "grpc/grpc_security.h"
|
||||
|
|
@ -51,11 +51,12 @@ extern "C" {
|
|||
#include "call_credentials.h"
|
||||
#include "channel.h"
|
||||
#include "channel_credentials.h"
|
||||
#include "completion_queue.h"
|
||||
#include "server.h"
|
||||
#include "completion_queue_async_worker.h"
|
||||
#include "server_credentials.h"
|
||||
#include "slice.h"
|
||||
#include "timeval.h"
|
||||
#include "completion_queue.h"
|
||||
|
||||
using grpc::node::CreateSliceFromString;
|
||||
|
||||
|
|
@ -185,7 +186,8 @@ 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));
|
||||
|
|
@ -199,7 +201,8 @@ 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));
|
||||
|
|
@ -247,7 +250,8 @@ 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);
|
||||
}
|
||||
|
|
@ -276,11 +280,13 @@ 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);
|
||||
}
|
||||
|
||||
|
|
@ -291,8 +297,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);
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +309,8 @@ 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);
|
||||
}
|
||||
|
||||
|
|
@ -345,13 +352,11 @@ 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);
|
||||
|
|
@ -381,9 +386,10 @@ 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();
|
||||
|
|
@ -408,10 +414,11 @@ 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);
|
||||
}
|
||||
|
||||
|
|
@ -442,25 +449,28 @@ 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)
|
||||
|
|
|
|||
|
|
@ -134,9 +134,14 @@ 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;
|
||||
|
|
@ -146,7 +151,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);
|
||||
|
|
@ -155,17 +160,19 @@ 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>>
|
||||
|
|
@ -277,9 +284,10 @@ 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 <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.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 <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.h>
|
||||
#include "grpc/grpc.h"
|
||||
#include "grpc/grpc_security.h"
|
||||
|
||||
|
|
|
|||
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,32 +73,28 @@ 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,15 +31,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <grpc/slice.h>
|
||||
#include <nan.h>
|
||||
#include <node.h>
|
||||
#include <nan.h>
|
||||
#include <grpc/slice.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 <cstdint>
|
||||
#include <limits>
|
||||
#include <cstdint>
|
||||
|
||||
#include "grpc/grpc.h"
|
||||
#include "grpc/support/time.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "grpc-health-check",
|
||||
"version": "1.4.0-dev",
|
||||
"version": "1.3.0-pre1",
|
||||
"author": "Google Inc.",
|
||||
"description": "Health check service for use with gRPC",
|
||||
"repository": {
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"grpc": "^1.4.0-dev",
|
||||
"grpc": "^1.3.0-pre1",
|
||||
"lodash": "^3.9.3",
|
||||
"google-protobuf": "^3.0.0"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "grpc-tools",
|
||||
"version": "1.4.0-dev",
|
||||
"version": "1.3.0-pre1",
|
||||
"author": "Google Inc.",
|
||||
"description": "Tools for developing with gRPC on Node.js",
|
||||
"homepage": "http://www.grpc.io/",
|
||||
|
|
|
|||
Loading…
Reference in New Issue