mirror of https://github.com/grpc/grpc-node.git
Merge branch 'master' into new_tsi
This commit is contained in:
commit
65856a7cf4
|
@ -33,10 +33,10 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
#include "grpc/grpc.h"
|
#include <node.h>
|
||||||
#include "grpc/byte_buffer_reader.h"
|
#include "grpc/byte_buffer_reader.h"
|
||||||
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/slice.h"
|
#include "grpc/slice.h"
|
||||||
|
|
||||||
#include "byte_buffer.h"
|
#include "byte_buffer.h"
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
|
|
259
ext/call.cc
259
ext/call.cc
|
@ -31,23 +31,23 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
|
|
||||||
#include "grpc/support/log.h"
|
|
||||||
#include "grpc/grpc.h"
|
|
||||||
#include "grpc/grpc_security.h"
|
|
||||||
#include "grpc/support/alloc.h"
|
|
||||||
#include "grpc/support/time.h"
|
|
||||||
#include "byte_buffer.h"
|
#include "byte_buffer.h"
|
||||||
#include "call.h"
|
#include "call.h"
|
||||||
|
#include "call_credentials.h"
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
#include "completion_queue.h"
|
#include "completion_queue.h"
|
||||||
#include "completion_queue_async_worker.h"
|
#include "completion_queue_async_worker.h"
|
||||||
#include "call_credentials.h"
|
#include "grpc/grpc.h"
|
||||||
|
#include "grpc/grpc_security.h"
|
||||||
|
#include "grpc/support/alloc.h"
|
||||||
|
#include "grpc/support/log.h"
|
||||||
|
#include "grpc/support/time.h"
|
||||||
#include "slice.h"
|
#include "slice.h"
|
||||||
#include "timeval.h"
|
#include "timeval.h"
|
||||||
|
|
||||||
|
@ -101,20 +101,20 @@ bool CreateMetadataArray(Local<Object> metadata, grpc_metadata_array *array) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
Local<Array> keys = Nan::GetOwnPropertyNames(metadata).ToLocalChecked();
|
Local<Array> keys = Nan::GetOwnPropertyNames(metadata).ToLocalChecked();
|
||||||
for (unsigned int i = 0; i < keys->Length(); i++) {
|
for (unsigned int i = 0; i < keys->Length(); i++) {
|
||||||
Local<String> current_key = Nan::To<String>(
|
Local<String> current_key =
|
||||||
Nan::Get(keys, i).ToLocalChecked()).ToLocalChecked();
|
Nan::To<String>(Nan::Get(keys, i).ToLocalChecked()).ToLocalChecked();
|
||||||
Local<Value> value_array = Nan::Get(metadata, current_key).ToLocalChecked();
|
Local<Value> value_array = Nan::Get(metadata, current_key).ToLocalChecked();
|
||||||
if (!value_array->IsArray()) {
|
if (!value_array->IsArray()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
array->capacity += Local<Array>::Cast(value_array)->Length();
|
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)));
|
gpr_zalloc(array->capacity * sizeof(grpc_metadata)));
|
||||||
for (unsigned int i = 0; i < keys->Length(); i++) {
|
for (unsigned int i = 0; i < keys->Length(); i++) {
|
||||||
Local<String> current_key(Nan::To<String>(keys->Get(i)).ToLocalChecked());
|
Local<String> current_key(Nan::To<String>(keys->Get(i)).ToLocalChecked());
|
||||||
Local<Array> values = Local<Array>::Cast(
|
Local<Array> values =
|
||||||
Nan::Get(metadata, current_key).ToLocalChecked());
|
Local<Array>::Cast(Nan::Get(metadata, current_key).ToLocalChecked());
|
||||||
grpc_slice key_slice = CreateSliceFromString(current_key);
|
grpc_slice key_slice = CreateSliceFromString(current_key);
|
||||||
grpc_slice key_intern_slice = grpc_slice_intern(key_slice);
|
grpc_slice key_intern_slice = grpc_slice_intern(key_slice);
|
||||||
grpc_slice_unref(key_slice);
|
grpc_slice_unref(key_slice);
|
||||||
|
@ -157,7 +157,7 @@ Local<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
|
||||||
size_t length = metadata_array->count;
|
size_t length = metadata_array->count;
|
||||||
Local<Object> metadata_object = Nan::New<Object>();
|
Local<Object> metadata_object = Nan::New<Object>();
|
||||||
for (unsigned int i = 0; i < length; i++) {
|
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
|
// TODO(murgatroid99): Use zero-copy string construction instead
|
||||||
Local<String> key_string = CopyStringFromSlice(elem->key);
|
Local<String> key_string = CopyStringFromSlice(elem->key);
|
||||||
Local<Array> array;
|
Local<Array> array;
|
||||||
|
@ -183,17 +183,12 @@ Local<Value> Op::GetOpType() const {
|
||||||
return scope.Escape(Nan::New(GetTypeString()).ToLocalChecked());
|
return scope.Escape(Nan::New(GetTypeString()).ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
Op::~Op() {
|
Op::~Op() {}
|
||||||
}
|
|
||||||
|
|
||||||
class SendMetadataOp : public Op {
|
class SendMetadataOp : public Op {
|
||||||
public:
|
public:
|
||||||
SendMetadataOp() {
|
SendMetadataOp() { grpc_metadata_array_init(&send_metadata); }
|
||||||
grpc_metadata_array_init(&send_metadata);
|
~SendMetadataOp() { DestroyMetadataArray(&send_metadata); }
|
||||||
}
|
|
||||||
~SendMetadataOp() {
|
|
||||||
DestroyMetadataArray(&send_metadata);
|
|
||||||
}
|
|
||||||
Local<Value> GetNodeValue() const {
|
Local<Value> GetNodeValue() const {
|
||||||
EscapableHandleScope scope;
|
EscapableHandleScope scope;
|
||||||
return scope.Escape(Nan::True());
|
return scope.Escape(Nan::True());
|
||||||
|
@ -206,32 +201,26 @@ class SendMetadataOp : public Op {
|
||||||
if (maybe_metadata.IsEmpty()) {
|
if (maybe_metadata.IsEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!CreateMetadataArray(maybe_metadata.ToLocalChecked(),
|
if (!CreateMetadataArray(maybe_metadata.ToLocalChecked(), &send_metadata)) {
|
||||||
&send_metadata)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out->data.send_initial_metadata.count = send_metadata.count;
|
out->data.send_initial_metadata.count = send_metadata.count;
|
||||||
out->data.send_initial_metadata.metadata = send_metadata.metadata;
|
out->data.send_initial_metadata.metadata = send_metadata.metadata;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool IsFinalOp() {
|
bool IsFinalOp() { return false; }
|
||||||
return false;
|
void OnComplete(bool success) {}
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const {
|
std::string GetTypeString() const { return "send_metadata"; }
|
||||||
return "send_metadata";
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
grpc_metadata_array send_metadata;
|
grpc_metadata_array send_metadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SendMessageOp : public Op {
|
class SendMessageOp : public Op {
|
||||||
public:
|
public:
|
||||||
SendMessageOp() {
|
SendMessageOp() { send_message = NULL; }
|
||||||
send_message = NULL;
|
|
||||||
}
|
|
||||||
~SendMessageOp() {
|
~SendMessageOp() {
|
||||||
if (send_message != NULL) {
|
if (send_message != NULL) {
|
||||||
grpc_byte_buffer_destroy(send_message);
|
grpc_byte_buffer_destroy(send_message);
|
||||||
|
@ -246,8 +235,8 @@ class SendMessageOp : public Op {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Local<Object> object_value = Nan::To<Object>(value).ToLocalChecked();
|
Local<Object> object_value = Nan::To<Object>(value).ToLocalChecked();
|
||||||
MaybeLocal<Value> maybe_flag_value = Nan::Get(
|
MaybeLocal<Value> maybe_flag_value =
|
||||||
object_value, Nan::New("grpcWriteFlags").ToLocalChecked());
|
Nan::Get(object_value, Nan::New("grpcWriteFlags").ToLocalChecked());
|
||||||
if (!maybe_flag_value.IsEmpty()) {
|
if (!maybe_flag_value.IsEmpty()) {
|
||||||
Local<Value> flag_value = maybe_flag_value.ToLocalChecked();
|
Local<Value> flag_value = maybe_flag_value.ToLocalChecked();
|
||||||
if (flag_value->IsUint32()) {
|
if (flag_value->IsUint32()) {
|
||||||
|
@ -259,15 +248,13 @@ class SendMessageOp : public Op {
|
||||||
out->data.send_message.send_message = send_message;
|
out->data.send_message.send_message = send_message;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool IsFinalOp() {
|
|
||||||
return false;
|
bool IsFinalOp() { return false; }
|
||||||
}
|
void OnComplete(bool success) {}
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const {
|
std::string GetTypeString() const { return "send_message"; }
|
||||||
return "send_message";
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
grpc_byte_buffer *send_message;
|
grpc_byte_buffer *send_message;
|
||||||
};
|
};
|
||||||
|
@ -278,25 +265,18 @@ class SendClientCloseOp : public Op {
|
||||||
EscapableHandleScope scope;
|
EscapableHandleScope scope;
|
||||||
return scope.Escape(Nan::True());
|
return scope.Escape(Nan::True());
|
||||||
}
|
}
|
||||||
bool ParseOp(Local<Value> value, grpc_op *out) {
|
|
||||||
return true;
|
bool ParseOp(Local<Value> value, grpc_op *out) { return true; }
|
||||||
}
|
bool IsFinalOp() { return false; }
|
||||||
bool IsFinalOp() {
|
void OnComplete(bool success) {}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const {
|
std::string GetTypeString() const { return "client_close"; }
|
||||||
return "client_close";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SendServerStatusOp : public Op {
|
class SendServerStatusOp : public Op {
|
||||||
public:
|
public:
|
||||||
SendServerStatusOp() {
|
SendServerStatusOp() { grpc_metadata_array_init(&status_metadata); }
|
||||||
grpc_metadata_array_init(&status_metadata);
|
|
||||||
}
|
|
||||||
~SendServerStatusOp() {
|
~SendServerStatusOp() {
|
||||||
grpc_slice_unref(details);
|
grpc_slice_unref(details);
|
||||||
DestroyMetadataArray(&status_metadata);
|
DestroyMetadataArray(&status_metadata);
|
||||||
|
@ -310,18 +290,18 @@ class SendServerStatusOp : public Op {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Local<Object> server_status = Nan::To<Object>(value).ToLocalChecked();
|
Local<Object> server_status = Nan::To<Object>(value).ToLocalChecked();
|
||||||
MaybeLocal<Value> maybe_metadata = Nan::Get(
|
MaybeLocal<Value> maybe_metadata =
|
||||||
server_status, Nan::New("metadata").ToLocalChecked());
|
Nan::Get(server_status, Nan::New("metadata").ToLocalChecked());
|
||||||
if (maybe_metadata.IsEmpty()) {
|
if (maybe_metadata.IsEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!maybe_metadata.ToLocalChecked()->IsObject()) {
|
if (!maybe_metadata.ToLocalChecked()->IsObject()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Local<Object> metadata = Nan::To<Object>(
|
Local<Object> metadata =
|
||||||
maybe_metadata.ToLocalChecked()).ToLocalChecked();
|
Nan::To<Object>(maybe_metadata.ToLocalChecked()).ToLocalChecked();
|
||||||
MaybeLocal<Value> maybe_code = Nan::Get(server_status,
|
MaybeLocal<Value> maybe_code =
|
||||||
Nan::New("code").ToLocalChecked());
|
Nan::Get(server_status, Nan::New("code").ToLocalChecked());
|
||||||
if (maybe_code.IsEmpty()) {
|
if (maybe_code.IsEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -329,16 +309,16 @@ class SendServerStatusOp : public Op {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint32_t code = Nan::To<uint32_t>(maybe_code.ToLocalChecked()).FromJust();
|
uint32_t code = Nan::To<uint32_t>(maybe_code.ToLocalChecked()).FromJust();
|
||||||
MaybeLocal<Value> maybe_details = Nan::Get(
|
MaybeLocal<Value> maybe_details =
|
||||||
server_status, Nan::New("details").ToLocalChecked());
|
Nan::Get(server_status, Nan::New("details").ToLocalChecked());
|
||||||
if (maybe_details.IsEmpty()) {
|
if (maybe_details.IsEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!maybe_details.ToLocalChecked()->IsString()) {
|
if (!maybe_details.ToLocalChecked()->IsString()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Local<String> details = Nan::To<String>(
|
Local<String> details =
|
||||||
maybe_details.ToLocalChecked()).ToLocalChecked();
|
Nan::To<String>(maybe_details.ToLocalChecked()).ToLocalChecked();
|
||||||
if (!CreateMetadataArray(metadata, &status_metadata)) {
|
if (!CreateMetadataArray(metadata, &status_metadata)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -352,15 +332,11 @@ class SendServerStatusOp : public Op {
|
||||||
out->data.send_status_from_server.status_details = &this->details;
|
out->data.send_status_from_server.status_details = &this->details;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool IsFinalOp() {
|
bool IsFinalOp() { return true; }
|
||||||
return true;
|
void OnComplete(bool success) {}
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const {
|
std::string GetTypeString() const { return "send_status"; }
|
||||||
return "send_status";
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
grpc_slice details;
|
grpc_slice details;
|
||||||
|
@ -369,13 +345,9 @@ class SendServerStatusOp : public Op {
|
||||||
|
|
||||||
class GetMetadataOp : public Op {
|
class GetMetadataOp : public Op {
|
||||||
public:
|
public:
|
||||||
GetMetadataOp() {
|
GetMetadataOp() { grpc_metadata_array_init(&recv_metadata); }
|
||||||
grpc_metadata_array_init(&recv_metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
~GetMetadataOp() {
|
~GetMetadataOp() { grpc_metadata_array_destroy(&recv_metadata); }
|
||||||
grpc_metadata_array_destroy(&recv_metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
Local<Value> GetNodeValue() const {
|
Local<Value> GetNodeValue() const {
|
||||||
EscapableHandleScope scope;
|
EscapableHandleScope scope;
|
||||||
|
@ -386,16 +358,11 @@ class GetMetadataOp : public Op {
|
||||||
out->data.recv_initial_metadata.recv_initial_metadata = &recv_metadata;
|
out->data.recv_initial_metadata.recv_initial_metadata = &recv_metadata;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool IsFinalOp() {
|
bool IsFinalOp() { return false; }
|
||||||
return false;
|
void OnComplete(bool success) {}
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const {
|
std::string GetTypeString() const { return "metadata"; }
|
||||||
return "metadata";
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
grpc_metadata_array recv_metadata;
|
grpc_metadata_array recv_metadata;
|
||||||
|
@ -403,9 +370,7 @@ class GetMetadataOp : public Op {
|
||||||
|
|
||||||
class ReadMessageOp : public Op {
|
class ReadMessageOp : public Op {
|
||||||
public:
|
public:
|
||||||
ReadMessageOp() {
|
ReadMessageOp() { recv_message = NULL; }
|
||||||
recv_message = NULL;
|
|
||||||
}
|
|
||||||
~ReadMessageOp() {
|
~ReadMessageOp() {
|
||||||
if (recv_message != NULL) {
|
if (recv_message != NULL) {
|
||||||
grpc_byte_buffer_destroy(recv_message);
|
grpc_byte_buffer_destroy(recv_message);
|
||||||
|
@ -420,16 +385,11 @@ class ReadMessageOp : public Op {
|
||||||
out->data.recv_message.recv_message = &recv_message;
|
out->data.recv_message.recv_message = &recv_message;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool IsFinalOp() {
|
bool IsFinalOp() { return false; }
|
||||||
return false;
|
void OnComplete(bool success) {}
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const {
|
std::string GetTypeString() const { return "read"; }
|
||||||
return "read";
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
grpc_byte_buffer *recv_message;
|
grpc_byte_buffer *recv_message;
|
||||||
|
@ -437,13 +397,9 @@ class ReadMessageOp : public Op {
|
||||||
|
|
||||||
class ClientStatusOp : public Op {
|
class ClientStatusOp : public Op {
|
||||||
public:
|
public:
|
||||||
ClientStatusOp() {
|
ClientStatusOp() { grpc_metadata_array_init(&metadata_array); }
|
||||||
grpc_metadata_array_init(&metadata_array);
|
|
||||||
}
|
|
||||||
|
|
||||||
~ClientStatusOp() {
|
~ClientStatusOp() { grpc_metadata_array_destroy(&metadata_array); }
|
||||||
grpc_metadata_array_destroy(&metadata_array);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ParseOp(Local<Value> value, grpc_op *out) {
|
bool ParseOp(Local<Value> value, grpc_op *out) {
|
||||||
out->data.recv_status_on_client.trailing_metadata = &metadata_array;
|
out->data.recv_status_on_client.trailing_metadata = &metadata_array;
|
||||||
|
@ -456,22 +412,19 @@ class ClientStatusOp : public Op {
|
||||||
EscapableHandleScope scope;
|
EscapableHandleScope scope;
|
||||||
Local<Object> status_obj = Nan::New<Object>();
|
Local<Object> status_obj = Nan::New<Object>();
|
||||||
Nan::Set(status_obj, Nan::New("code").ToLocalChecked(),
|
Nan::Set(status_obj, Nan::New("code").ToLocalChecked(),
|
||||||
Nan::New<Number>(status));
|
Nan::New<Number>(status));
|
||||||
Nan::Set(status_obj, Nan::New("details").ToLocalChecked(),
|
Nan::Set(status_obj, Nan::New("details").ToLocalChecked(),
|
||||||
CopyStringFromSlice(status_details));
|
CopyStringFromSlice(status_details));
|
||||||
Nan::Set(status_obj, Nan::New("metadata").ToLocalChecked(),
|
Nan::Set(status_obj, Nan::New("metadata").ToLocalChecked(),
|
||||||
ParseMetadata(&metadata_array));
|
ParseMetadata(&metadata_array));
|
||||||
return scope.Escape(status_obj);
|
return scope.Escape(status_obj);
|
||||||
}
|
}
|
||||||
bool IsFinalOp() {
|
bool IsFinalOp() { return true; }
|
||||||
return true;
|
void OnComplete(bool success) {}
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const {
|
std::string GetTypeString() const { return "status"; }
|
||||||
return "status";
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
grpc_metadata_array metadata_array;
|
grpc_metadata_array metadata_array;
|
||||||
grpc_status_code status;
|
grpc_status_code status;
|
||||||
|
@ -489,23 +442,18 @@ class ServerCloseResponseOp : public Op {
|
||||||
out->data.recv_close_on_server.cancelled = &cancelled;
|
out->data.recv_close_on_server.cancelled = &cancelled;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool IsFinalOp() {
|
bool IsFinalOp() { return false; }
|
||||||
return false;
|
void OnComplete(bool success) {}
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const {
|
std::string GetTypeString() const { return "cancelled"; }
|
||||||
return "cancelled";
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int cancelled;
|
int cancelled;
|
||||||
};
|
};
|
||||||
|
|
||||||
tag::tag(Callback *callback, OpVec *ops, Call *call, Local<Value> call_value) :
|
tag::tag(Callback *callback, OpVec *ops, Call *call, Local<Value> call_value)
|
||||||
callback(callback), ops(ops), call(call){
|
: callback(callback), ops(ops), call(call) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
call_persist.Reset(call_value);
|
call_persist.Reset(call_value);
|
||||||
}
|
}
|
||||||
|
@ -555,19 +503,15 @@ void DestroyTag(void *tag) {
|
||||||
|
|
||||||
void Call::DestroyCall() {
|
void Call::DestroyCall() {
|
||||||
if (this->wrapped_call != NULL) {
|
if (this->wrapped_call != NULL) {
|
||||||
grpc_call_destroy(this->wrapped_call);
|
grpc_call_unref(this->wrapped_call);
|
||||||
this->wrapped_call = NULL;
|
this->wrapped_call = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Call::Call(grpc_call *call) : wrapped_call(call),
|
Call::Call(grpc_call *call)
|
||||||
pending_batches(0),
|
: wrapped_call(call), pending_batches(0), has_final_op_completed(false) {}
|
||||||
has_final_op_completed(false) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Call::~Call() {
|
Call::~Call() { DestroyCall(); }
|
||||||
DestroyCall();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Call::Init(Local<Object> exports) {
|
void Call::Init(Local<Object> exports) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
@ -596,10 +540,10 @@ Local<Value> Call::WrapStruct(grpc_call *call) {
|
||||||
return scope.Escape(Nan::Null());
|
return scope.Escape(Nan::Null());
|
||||||
}
|
}
|
||||||
const int argc = 1;
|
const int argc = 1;
|
||||||
Local<Value> argv[argc] = {Nan::New<External>(
|
Local<Value> argv[argc] = {
|
||||||
reinterpret_cast<void *>(call))};
|
Nan::New<External>(reinterpret_cast<void *>(call))};
|
||||||
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
|
MaybeLocal<Object> maybe_instance =
|
||||||
constructor->GetFunction(), argc, argv);
|
Nan::NewInstance(constructor->GetFunction(), argc, argv);
|
||||||
if (maybe_instance.IsEmpty()) {
|
if (maybe_instance.IsEmpty()) {
|
||||||
return scope.Escape(Nan::Null());
|
return scope.Escape(Nan::Null());
|
||||||
} else {
|
} else {
|
||||||
|
@ -631,8 +575,7 @@ NAN_METHOD(Call::New) {
|
||||||
if (info[0]->IsExternal()) {
|
if (info[0]->IsExternal()) {
|
||||||
Local<External> ext = info[0].As<External>();
|
Local<External> ext = info[0].As<External>();
|
||||||
// This option is used for wrapping an existing call
|
// This option is used for wrapping an existing call
|
||||||
grpc_call *call_value =
|
grpc_call *call_value = reinterpret_cast<grpc_call *>(ext->Value());
|
||||||
reinterpret_cast<grpc_call *>(ext->Value());
|
|
||||||
call = new Call(call_value);
|
call = new Call(call_value);
|
||||||
} else {
|
} else {
|
||||||
if (!Channel::HasInstance(info[0])) {
|
if (!Channel::HasInstance(info[0])) {
|
||||||
|
@ -648,8 +591,8 @@ NAN_METHOD(Call::New) {
|
||||||
// These arguments are at the end because they are optional
|
// These arguments are at the end because they are optional
|
||||||
grpc_call *parent_call = NULL;
|
grpc_call *parent_call = NULL;
|
||||||
if (Call::HasInstance(info[4])) {
|
if (Call::HasInstance(info[4])) {
|
||||||
Call *parent_obj = ObjectWrap::Unwrap<Call>(
|
Call *parent_obj =
|
||||||
Nan::To<Object>(info[4]).ToLocalChecked());
|
ObjectWrap::Unwrap<Call>(Nan::To<Object>(info[4]).ToLocalChecked());
|
||||||
parent_call = parent_obj->wrapped_call;
|
parent_call = parent_obj->wrapped_call;
|
||||||
} else if (!(info[4]->IsUndefined() || info[4]->IsNull())) {
|
} else if (!(info[4]->IsUndefined() || info[4]->IsNull())) {
|
||||||
return Nan::ThrowTypeError(
|
return Nan::ThrowTypeError(
|
||||||
|
@ -670,22 +613,20 @@ NAN_METHOD(Call::New) {
|
||||||
double deadline = Nan::To<double>(info[2]).FromJust();
|
double deadline = Nan::To<double>(info[2]).FromJust();
|
||||||
grpc_channel *wrapped_channel = channel->GetWrappedChannel();
|
grpc_channel *wrapped_channel = channel->GetWrappedChannel();
|
||||||
grpc_call *wrapped_call;
|
grpc_call *wrapped_call;
|
||||||
grpc_slice method = CreateSliceFromString(
|
grpc_slice method =
|
||||||
Nan::To<String>(info[1]).ToLocalChecked());
|
CreateSliceFromString(Nan::To<String>(info[1]).ToLocalChecked());
|
||||||
if (info[3]->IsString()) {
|
if (info[3]->IsString()) {
|
||||||
grpc_slice *host = new grpc_slice;
|
grpc_slice *host = new grpc_slice;
|
||||||
*host = CreateSliceFromString(
|
*host =
|
||||||
Nan::To<String>(info[3]).ToLocalChecked());
|
CreateSliceFromString(Nan::To<String>(info[3]).ToLocalChecked());
|
||||||
wrapped_call = grpc_channel_create_call(
|
wrapped_call = grpc_channel_create_call(
|
||||||
wrapped_channel, parent_call, propagate_flags,
|
wrapped_channel, parent_call, propagate_flags, GetCompletionQueue(),
|
||||||
GetCompletionQueue(), method,
|
method, host, MillisecondsToTimespec(deadline), NULL);
|
||||||
host, MillisecondsToTimespec(deadline), NULL);
|
|
||||||
delete host;
|
delete host;
|
||||||
} else if (info[3]->IsUndefined() || info[3]->IsNull()) {
|
} else if (info[3]->IsUndefined() || info[3]->IsNull()) {
|
||||||
wrapped_call = grpc_channel_create_call(
|
wrapped_call = grpc_channel_create_call(
|
||||||
wrapped_channel, parent_call, propagate_flags,
|
wrapped_channel, parent_call, propagate_flags, GetCompletionQueue(),
|
||||||
GetCompletionQueue(), method,
|
method, NULL, MillisecondsToTimespec(deadline), NULL);
|
||||||
NULL, MillisecondsToTimespec(deadline), NULL);
|
|
||||||
} else {
|
} else {
|
||||||
return Nan::ThrowTypeError("Call's fourth argument must be a string");
|
return Nan::ThrowTypeError("Call's fourth argument must be a string");
|
||||||
}
|
}
|
||||||
|
@ -699,8 +640,8 @@ NAN_METHOD(Call::New) {
|
||||||
} else {
|
} else {
|
||||||
const int argc = 4;
|
const int argc = 4;
|
||||||
Local<Value> argv[argc] = {info[0], info[1], info[2], info[3]};
|
Local<Value> argv[argc] = {info[0], info[1], info[2], info[3]};
|
||||||
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
|
MaybeLocal<Object> maybe_instance =
|
||||||
constructor->GetFunction(), argc, argv);
|
Nan::NewInstance(constructor->GetFunction(), argc, argv);
|
||||||
if (maybe_instance.IsEmpty()) {
|
if (maybe_instance.IsEmpty()) {
|
||||||
// There's probably a pending exception
|
// There's probably a pending exception
|
||||||
return;
|
return;
|
||||||
|
@ -773,8 +714,8 @@ NAN_METHOD(Call::StartBatch) {
|
||||||
}
|
}
|
||||||
Callback *callback = new Callback(callback_func);
|
Callback *callback = new Callback(callback_func);
|
||||||
grpc_call_error error = grpc_call_start_batch(
|
grpc_call_error error = grpc_call_start_batch(
|
||||||
call->wrapped_call, &ops[0], nops, new struct tag(
|
call->wrapped_call, &ops[0], nops,
|
||||||
callback, op_vector.release(), call, info.This()), NULL);
|
new struct tag(callback, op_vector.release(), call, info.This()), NULL);
|
||||||
if (error != GRPC_CALL_OK) {
|
if (error != GRPC_CALL_OK) {
|
||||||
return Nan::ThrowError(nanErrorWithCode("startBatch failed", error));
|
return Nan::ThrowError(nanErrorWithCode("startBatch failed", error));
|
||||||
}
|
}
|
||||||
|
@ -807,8 +748,8 @@ NAN_METHOD(Call::CancelWithStatus) {
|
||||||
"cancelWithStatus's second argument must be a string");
|
"cancelWithStatus's second argument must be a string");
|
||||||
}
|
}
|
||||||
Call *call = ObjectWrap::Unwrap<Call>(info.This());
|
Call *call = ObjectWrap::Unwrap<Call>(info.This());
|
||||||
grpc_status_code code = static_cast<grpc_status_code>(
|
grpc_status_code code =
|
||||||
Nan::To<uint32_t>(info[0]).FromJust());
|
static_cast<grpc_status_code>(Nan::To<uint32_t>(info[0]).FromJust());
|
||||||
if (code == GRPC_STATUS_OK) {
|
if (code == GRPC_STATUS_OK) {
|
||||||
return Nan::ThrowRangeError(
|
return Nan::ThrowRangeError(
|
||||||
"cancelWithStatus cannot be called with OK status");
|
"cancelWithStatus cannot be called with OK status");
|
||||||
|
|
|
@ -37,14 +37,13 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/support/log.h"
|
#include "grpc/support/log.h"
|
||||||
|
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
|
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
|
|
|
@ -31,17 +31,17 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
#include "call.h"
|
||||||
|
#include "call_credentials.h"
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/grpc_security.h"
|
#include "grpc/grpc_security.h"
|
||||||
#include "grpc/support/log.h"
|
#include "grpc/support/log.h"
|
||||||
#include "call_credentials.h"
|
|
||||||
#include "call.h"
|
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
namespace node {
|
namespace node {
|
||||||
|
@ -86,15 +86,15 @@ void CallCredentials::Init(Local<Object> exports) {
|
||||||
fun_tpl.Reset(tpl);
|
fun_tpl.Reset(tpl);
|
||||||
Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
|
Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
|
||||||
Nan::Set(ctr, Nan::New("createFromPlugin").ToLocalChecked(),
|
Nan::Set(ctr, Nan::New("createFromPlugin").ToLocalChecked(),
|
||||||
Nan::GetFunction(
|
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateFromPlugin))
|
||||||
Nan::New<FunctionTemplate>(CreateFromPlugin)).ToLocalChecked());
|
.ToLocalChecked());
|
||||||
Nan::Set(exports, Nan::New("CallCredentials").ToLocalChecked(), ctr);
|
Nan::Set(exports, Nan::New("CallCredentials").ToLocalChecked(), ctr);
|
||||||
constructor = new Nan::Callback(ctr);
|
constructor = new Nan::Callback(ctr);
|
||||||
|
|
||||||
Local<FunctionTemplate> callback_tpl =
|
Local<FunctionTemplate> callback_tpl =
|
||||||
Nan::New<FunctionTemplate>(PluginCallback);
|
Nan::New<FunctionTemplate>(PluginCallback);
|
||||||
plugin_callback = new Callback(
|
plugin_callback =
|
||||||
Nan::GetFunction(callback_tpl).ToLocalChecked());
|
new Callback(Nan::GetFunction(callback_tpl).ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CallCredentials::HasInstance(Local<Value> val) {
|
bool CallCredentials::HasInstance(Local<Value> val) {
|
||||||
|
@ -109,9 +109,9 @@ Local<Value> CallCredentials::WrapStruct(grpc_call_credentials *credentials) {
|
||||||
return scope.Escape(Nan::Null());
|
return scope.Escape(Nan::Null());
|
||||||
}
|
}
|
||||||
Local<Value> argv[argc] = {
|
Local<Value> argv[argc] = {
|
||||||
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
||||||
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
|
MaybeLocal<Object> maybe_instance =
|
||||||
constructor->GetFunction(), argc, argv);
|
Nan::NewInstance(constructor->GetFunction(), argc, argv);
|
||||||
if (maybe_instance.IsEmpty()) {
|
if (maybe_instance.IsEmpty()) {
|
||||||
return scope.Escape(Nan::Null());
|
return scope.Escape(Nan::Null());
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,8 +160,6 @@ NAN_METHOD(CallCredentials::Compose) {
|
||||||
info.GetReturnValue().Set(WrapStruct(creds));
|
info.GetReturnValue().Set(WrapStruct(creds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(CallCredentials::CreateFromPlugin) {
|
NAN_METHOD(CallCredentials::CreateFromPlugin) {
|
||||||
if (!info[0]->IsFunction()) {
|
if (!info[0]->IsFunction()) {
|
||||||
return Nan::ThrowTypeError(
|
return Nan::ThrowTypeError(
|
||||||
|
@ -170,21 +168,19 @@ NAN_METHOD(CallCredentials::CreateFromPlugin) {
|
||||||
grpc_metadata_credentials_plugin plugin;
|
grpc_metadata_credentials_plugin plugin;
|
||||||
plugin_state *state = new plugin_state;
|
plugin_state *state = new plugin_state;
|
||||||
state->callback = new Nan::Callback(info[0].As<Function>());
|
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_mutex_init(&state->plugin_mutex);
|
||||||
uv_async_init(uv_default_loop(),
|
uv_async_init(uv_default_loop(), &state->plugin_async, SendPluginCallback);
|
||||||
&state->plugin_async,
|
uv_unref((uv_handle_t *)&state->plugin_async);
|
||||||
SendPluginCallback);
|
|
||||||
uv_unref((uv_handle_t*)&state->plugin_async);
|
|
||||||
|
|
||||||
state->plugin_async.data = state;
|
state->plugin_async.data = state;
|
||||||
|
|
||||||
plugin.get_metadata = plugin_get_metadata;
|
plugin.get_metadata = plugin_get_metadata;
|
||||||
plugin.destroy = plugin_destroy_state;
|
plugin.destroy = plugin_destroy_state;
|
||||||
plugin.state = reinterpret_cast<void*>(state);
|
plugin.state = reinterpret_cast<void *>(state);
|
||||||
plugin.type = "";
|
plugin.type = "";
|
||||||
grpc_call_credentials *creds = grpc_metadata_credentials_create_from_plugin(
|
grpc_call_credentials *creds =
|
||||||
plugin, NULL);
|
grpc_metadata_credentials_create_from_plugin(plugin, NULL);
|
||||||
info.GetReturnValue().Set(WrapStruct(creds));
|
info.GetReturnValue().Set(WrapStruct(creds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,34 +202,35 @@ NAN_METHOD(PluginCallback) {
|
||||||
return Nan::ThrowTypeError(
|
return Nan::ThrowTypeError(
|
||||||
"The callback's fourth argument must be an object");
|
"The callback's fourth argument must be an object");
|
||||||
}
|
}
|
||||||
grpc_status_code code = static_cast<grpc_status_code>(
|
grpc_status_code code =
|
||||||
Nan::To<uint32_t>(info[0]).FromJust());
|
static_cast<grpc_status_code>(Nan::To<uint32_t>(info[0]).FromJust());
|
||||||
Utf8String details_utf8_str(info[1]);
|
Utf8String details_utf8_str(info[1]);
|
||||||
char *details = *details_utf8_str;
|
char *details = *details_utf8_str;
|
||||||
grpc_metadata_array array;
|
grpc_metadata_array array;
|
||||||
grpc_metadata_array_init(&array);
|
grpc_metadata_array_init(&array);
|
||||||
Local<Object> callback_data = Nan::To<Object>(info[3]).ToLocalChecked();
|
Local<Object> callback_data = Nan::To<Object>(info[3]).ToLocalChecked();
|
||||||
if (!CreateMetadataArray(Nan::To<Object>(info[2]).ToLocalChecked(),
|
if (!CreateMetadataArray(Nan::To<Object>(info[2]).ToLocalChecked(), &array)) {
|
||||||
&array)){
|
|
||||||
return Nan::ThrowError("Failed to parse metadata");
|
return Nan::ThrowError("Failed to parse metadata");
|
||||||
}
|
}
|
||||||
grpc_credentials_plugin_metadata_cb cb =
|
grpc_credentials_plugin_metadata_cb cb =
|
||||||
reinterpret_cast<grpc_credentials_plugin_metadata_cb>(
|
reinterpret_cast<grpc_credentials_plugin_metadata_cb>(
|
||||||
Nan::Get(callback_data,
|
Nan::Get(callback_data, Nan::New("cb").ToLocalChecked())
|
||||||
Nan::New("cb").ToLocalChecked()
|
.ToLocalChecked()
|
||||||
).ToLocalChecked().As<External>()->Value());
|
.As<External>()
|
||||||
|
->Value());
|
||||||
void *user_data =
|
void *user_data =
|
||||||
Nan::Get(callback_data,
|
Nan::Get(callback_data, Nan::New("user_data").ToLocalChecked())
|
||||||
Nan::New("user_data").ToLocalChecked()
|
.ToLocalChecked()
|
||||||
).ToLocalChecked().As<External>()->Value();
|
.As<External>()
|
||||||
|
->Value();
|
||||||
cb(user_data, array.metadata, array.count, code, details);
|
cb(user_data, array.metadata, array.count, code, details);
|
||||||
DestroyMetadataArray(&array);
|
DestroyMetadataArray(&array);
|
||||||
}
|
}
|
||||||
|
|
||||||
NAUV_WORK_CB(SendPluginCallback) {
|
NAUV_WORK_CB(SendPluginCallback) {
|
||||||
Nan::HandleScope scope;
|
Nan::HandleScope scope;
|
||||||
plugin_state *state = reinterpret_cast<plugin_state*>(async->data);
|
plugin_state *state = reinterpret_cast<plugin_state *>(async->data);
|
||||||
std::queue<plugin_callback_data*> callbacks;
|
std::queue<plugin_callback_data *> callbacks;
|
||||||
uv_mutex_lock(&state->plugin_mutex);
|
uv_mutex_lock(&state->plugin_mutex);
|
||||||
state->pending_callbacks->swap(callbacks);
|
state->pending_callbacks->swap(callbacks);
|
||||||
uv_mutex_unlock(&state->plugin_mutex);
|
uv_mutex_unlock(&state->plugin_mutex);
|
||||||
|
@ -242,16 +239,14 @@ NAUV_WORK_CB(SendPluginCallback) {
|
||||||
callbacks.pop();
|
callbacks.pop();
|
||||||
Local<Object> callback_data = Nan::New<Object>();
|
Local<Object> callback_data = Nan::New<Object>();
|
||||||
Nan::Set(callback_data, Nan::New("cb").ToLocalChecked(),
|
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::Set(callback_data, Nan::New("user_data").ToLocalChecked(),
|
||||||
Nan::New<v8::External>(data->user_data));
|
Nan::New<v8::External>(data->user_data));
|
||||||
const int argc = 3;
|
const int argc = 3;
|
||||||
v8::Local<v8::Value> argv[argc] = {
|
v8::Local<v8::Value> argv[argc] = {
|
||||||
Nan::New(data->service_url).ToLocalChecked(),
|
Nan::New(data->service_url).ToLocalChecked(), callback_data,
|
||||||
callback_data,
|
// Get Local<Function> from Nan::Callback*
|
||||||
// Get Local<Function> from Nan::Callback*
|
**plugin_callback};
|
||||||
**plugin_callback
|
|
||||||
};
|
|
||||||
Nan::Callback *callback = state->callback;
|
Nan::Callback *callback = state->callback;
|
||||||
callback->Call(argc, argv);
|
callback->Call(argc, argv);
|
||||||
delete data;
|
delete data;
|
||||||
|
@ -261,7 +256,7 @@ NAUV_WORK_CB(SendPluginCallback) {
|
||||||
void plugin_get_metadata(void *state, grpc_auth_metadata_context context,
|
void plugin_get_metadata(void *state, grpc_auth_metadata_context context,
|
||||||
grpc_credentials_plugin_metadata_cb cb,
|
grpc_credentials_plugin_metadata_cb cb,
|
||||||
void *user_data) {
|
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;
|
plugin_callback_data *data = new plugin_callback_data;
|
||||||
data->service_url = context.service_url;
|
data->service_url = context.service_url;
|
||||||
data->cb = cb;
|
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) {
|
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);
|
plugin_state *state = reinterpret_cast<plugin_state *>(async->data);
|
||||||
uv_mutex_destroy(&state->plugin_mutex);
|
uv_mutex_destroy(&state->plugin_mutex);
|
||||||
delete state->pending_callbacks;
|
delete state->pending_callbacks;
|
||||||
|
@ -285,7 +280,7 @@ void plugin_uv_close_cb(uv_handle_t *handle) {
|
||||||
|
|
||||||
void plugin_destroy_state(void *ptr) {
|
void plugin_destroy_state(void *ptr) {
|
||||||
plugin_state *state = reinterpret_cast<plugin_state *>(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
|
} // namespace node
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
#include "grpc/grpc_security.h"
|
#include "grpc/grpc_security.h"
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ typedef struct plugin_callback_data {
|
||||||
|
|
||||||
typedef struct plugin_state {
|
typedef struct plugin_state {
|
||||||
Nan::Callback *callback;
|
Nan::Callback *callback;
|
||||||
std::queue<plugin_callback_data*> *pending_callbacks;
|
std::queue<plugin_callback_data *> *pending_callbacks;
|
||||||
uv_mutex_t plugin_mutex;
|
uv_mutex_t plugin_mutex;
|
||||||
// async.data == this
|
// async.data == this
|
||||||
uv_async_t plugin_async;
|
uv_async_t plugin_async;
|
||||||
|
|
|
@ -35,15 +35,15 @@
|
||||||
|
|
||||||
#include "grpc/support/log.h"
|
#include "grpc/support/log.h"
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
#include "grpc/grpc.h"
|
#include <node.h>
|
||||||
#include "grpc/grpc_security.h"
|
|
||||||
#include "call.h"
|
#include "call.h"
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
|
#include "channel_credentials.h"
|
||||||
#include "completion_queue.h"
|
#include "completion_queue.h"
|
||||||
#include "completion_queue_async_worker.h"
|
#include "completion_queue_async_worker.h"
|
||||||
#include "channel_credentials.h"
|
#include "grpc/grpc.h"
|
||||||
|
#include "grpc/grpc_security.h"
|
||||||
#include "timeval.h"
|
#include "timeval.h"
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
|
@ -82,8 +82,8 @@ bool ParseChannelArgs(Local<Value> args_val,
|
||||||
*channel_args_ptr = NULL;
|
*channel_args_ptr = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
grpc_channel_args *channel_args = reinterpret_cast<grpc_channel_args*>(
|
grpc_channel_args *channel_args =
|
||||||
malloc(sizeof(grpc_channel_args)));
|
reinterpret_cast<grpc_channel_args *>(malloc(sizeof(grpc_channel_args)));
|
||||||
*channel_args_ptr = channel_args;
|
*channel_args_ptr = channel_args;
|
||||||
Local<Object> args_hash = Nan::To<Object>(args_val).ToLocalChecked();
|
Local<Object> args_hash = Nan::To<Object>(args_val).ToLocalChecked();
|
||||||
Local<Array> keys = Nan::GetOwnPropertyNames(args_hash).ToLocalChecked();
|
Local<Array> keys = Nan::GetOwnPropertyNames(args_hash).ToLocalChecked();
|
||||||
|
@ -104,16 +104,16 @@ bool ParseChannelArgs(Local<Value> args_val,
|
||||||
} else if (value->IsString()) {
|
} else if (value->IsString()) {
|
||||||
Utf8String val_str(value);
|
Utf8String val_str(value);
|
||||||
channel_args->args[i].type = GRPC_ARG_STRING;
|
channel_args->args[i].type = GRPC_ARG_STRING;
|
||||||
channel_args->args[i].value.string = reinterpret_cast<char*>(
|
channel_args->args[i].value.string =
|
||||||
calloc(val_str.length() + 1,sizeof(char)));
|
reinterpret_cast<char *>(calloc(val_str.length() + 1, sizeof(char)));
|
||||||
memcpy(channel_args->args[i].value.string,
|
memcpy(channel_args->args[i].value.string, *val_str,
|
||||||
*val_str, val_str.length() + 1);
|
val_str.length() + 1);
|
||||||
} else {
|
} else {
|
||||||
// The value does not match either of the accepted types
|
// The value does not match either of the accepted types
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
channel_args->args[i].key = reinterpret_cast<char*>(
|
channel_args->args[i].key =
|
||||||
calloc(key_str.length() + 1, sizeof(char)));
|
reinterpret_cast<char *>(calloc(key_str.length() + 1, sizeof(char)));
|
||||||
memcpy(channel_args->args[i].key, *key_str, key_str.length() + 1);
|
memcpy(channel_args->args[i].key, *key_str, key_str.length() + 1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -190,12 +190,13 @@ NAN_METHOD(Channel::New) {
|
||||||
grpc_channel_args *channel_args_ptr = NULL;
|
grpc_channel_args *channel_args_ptr = NULL;
|
||||||
if (!ParseChannelArgs(info[2], &channel_args_ptr)) {
|
if (!ParseChannelArgs(info[2], &channel_args_ptr)) {
|
||||||
DeallocateChannelArgs(channel_args_ptr);
|
DeallocateChannelArgs(channel_args_ptr);
|
||||||
return Nan::ThrowTypeError("Channel options must be an object with "
|
return Nan::ThrowTypeError(
|
||||||
"string keys and integer or string values");
|
"Channel options must be an object with "
|
||||||
|
"string keys and integer or string values");
|
||||||
}
|
}
|
||||||
if (creds == NULL) {
|
if (creds == NULL) {
|
||||||
wrapped_channel = grpc_insecure_channel_create(*host, channel_args_ptr,
|
wrapped_channel =
|
||||||
NULL);
|
grpc_insecure_channel_create(*host, channel_args_ptr, NULL);
|
||||||
} else {
|
} else {
|
||||||
wrapped_channel =
|
wrapped_channel =
|
||||||
grpc_secure_channel_create(creds, *host, channel_args_ptr, NULL);
|
grpc_secure_channel_create(creds, *host, channel_args_ptr, NULL);
|
||||||
|
@ -208,8 +209,8 @@ NAN_METHOD(Channel::New) {
|
||||||
} else {
|
} else {
|
||||||
const int argc = 3;
|
const int argc = 3;
|
||||||
Local<Value> argv[argc] = {info[0], info[1], info[2]};
|
Local<Value> argv[argc] = {info[0], info[1], info[2]};
|
||||||
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
|
MaybeLocal<Object> maybe_instance =
|
||||||
constructor->GetFunction(), argc, argv);
|
Nan::NewInstance(constructor->GetFunction(), argc, argv);
|
||||||
if (maybe_instance.IsEmpty()) {
|
if (maybe_instance.IsEmpty()) {
|
||||||
// There's probably a pending exception
|
// There's probably a pending exception
|
||||||
return;
|
return;
|
||||||
|
@ -232,11 +233,13 @@ NAN_METHOD(Channel::Close) {
|
||||||
|
|
||||||
NAN_METHOD(Channel::GetTarget) {
|
NAN_METHOD(Channel::GetTarget) {
|
||||||
if (!HasInstance(info.This())) {
|
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());
|
Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
|
||||||
info.GetReturnValue().Set(Nan::New(
|
info.GetReturnValue().Set(
|
||||||
grpc_channel_get_target(channel->wrapped_channel)).ToLocalChecked());
|
Nan::New(grpc_channel_get_target(channel->wrapped_channel))
|
||||||
|
.ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
NAN_METHOD(Channel::GetConnectivityState) {
|
NAN_METHOD(Channel::GetConnectivityState) {
|
||||||
|
@ -246,9 +249,8 @@ NAN_METHOD(Channel::GetConnectivityState) {
|
||||||
}
|
}
|
||||||
Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
|
Channel *channel = ObjectWrap::Unwrap<Channel>(info.This());
|
||||||
int try_to_connect = (int)info[0]->Equals(Nan::True());
|
int try_to_connect = (int)info[0]->Equals(Nan::True());
|
||||||
info.GetReturnValue().Set(
|
info.GetReturnValue().Set(grpc_channel_check_connectivity_state(
|
||||||
grpc_channel_check_connectivity_state(channel->wrapped_channel,
|
channel->wrapped_channel, try_to_connect));
|
||||||
try_to_connect));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NAN_METHOD(Channel::WatchConnectivityState) {
|
NAN_METHOD(Channel::WatchConnectivityState) {
|
||||||
|
@ -268,9 +270,8 @@ NAN_METHOD(Channel::WatchConnectivityState) {
|
||||||
return Nan::ThrowTypeError(
|
return Nan::ThrowTypeError(
|
||||||
"watchConnectivityState's third argument must be a callback");
|
"watchConnectivityState's third argument must be a callback");
|
||||||
}
|
}
|
||||||
grpc_connectivity_state last_state =
|
grpc_connectivity_state last_state = static_cast<grpc_connectivity_state>(
|
||||||
static_cast<grpc_connectivity_state>(
|
Nan::To<uint32_t>(info[0]).FromJust());
|
||||||
Nan::To<uint32_t>(info[0]).FromJust());
|
|
||||||
double deadline = Nan::To<double>(info[1]).FromJust();
|
double deadline = Nan::To<double>(info[1]).FromJust();
|
||||||
Local<Function> callback_func = info[2].As<Function>();
|
Local<Function> callback_func = info[2].As<Function>();
|
||||||
Nan::Callback *callback = new Callback(callback_func);
|
Nan::Callback *callback = new Callback(callback_func);
|
||||||
|
@ -279,8 +280,7 @@ NAN_METHOD(Channel::WatchConnectivityState) {
|
||||||
grpc_channel_watch_connectivity_state(
|
grpc_channel_watch_connectivity_state(
|
||||||
channel->wrapped_channel, last_state, MillisecondsToTimespec(deadline),
|
channel->wrapped_channel, last_state, MillisecondsToTimespec(deadline),
|
||||||
GetCompletionQueue(),
|
GetCompletionQueue(),
|
||||||
new struct tag(callback,
|
new struct tag(callback, ops.release(), NULL, Nan::Null()));
|
||||||
ops.release(), NULL, Nan::Null()));
|
|
||||||
CompletionQueueNext();
|
CompletionQueueNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
#ifndef NET_GRPC_NODE_CHANNEL_H_
|
#ifndef NET_GRPC_NODE_CHANNEL_H_
|
||||||
#define NET_GRPC_NODE_CHANNEL_H_
|
#define NET_GRPC_NODE_CHANNEL_H_
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
|
|
|
@ -33,12 +33,12 @@
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
|
|
||||||
|
#include "call.h"
|
||||||
|
#include "call_credentials.h"
|
||||||
|
#include "channel_credentials.h"
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/grpc_security.h"
|
#include "grpc/grpc_security.h"
|
||||||
#include "grpc/support/log.h"
|
#include "grpc/support/log.h"
|
||||||
#include "channel_credentials.h"
|
|
||||||
#include "call_credentials.h"
|
|
||||||
#include "call.h"
|
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
namespace node {
|
namespace node {
|
||||||
|
@ -80,12 +80,12 @@ void ChannelCredentials::Init(Local<Object> exports) {
|
||||||
Nan::SetPrototypeMethod(tpl, "compose", Compose);
|
Nan::SetPrototypeMethod(tpl, "compose", Compose);
|
||||||
fun_tpl.Reset(tpl);
|
fun_tpl.Reset(tpl);
|
||||||
Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
|
Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
|
||||||
Nan::Set(ctr, Nan::New("createSsl").ToLocalChecked(),
|
Nan::Set(
|
||||||
Nan::GetFunction(
|
ctr, Nan::New("createSsl").ToLocalChecked(),
|
||||||
Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
|
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
|
||||||
Nan::Set(ctr, Nan::New("createInsecure").ToLocalChecked(),
|
Nan::Set(ctr, Nan::New("createInsecure").ToLocalChecked(),
|
||||||
Nan::GetFunction(
|
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateInsecure))
|
||||||
Nan::New<FunctionTemplate>(CreateInsecure)).ToLocalChecked());
|
.ToLocalChecked());
|
||||||
Nan::Set(exports, Nan::New("ChannelCredentials").ToLocalChecked(), ctr);
|
Nan::Set(exports, Nan::New("ChannelCredentials").ToLocalChecked(), ctr);
|
||||||
constructor = new Nan::Callback(ctr);
|
constructor = new Nan::Callback(ctr);
|
||||||
}
|
}
|
||||||
|
@ -100,9 +100,9 @@ Local<Value> ChannelCredentials::WrapStruct(
|
||||||
EscapableHandleScope scope;
|
EscapableHandleScope scope;
|
||||||
const int argc = 1;
|
const int argc = 1;
|
||||||
Local<Value> argv[argc] = {
|
Local<Value> argv[argc] = {
|
||||||
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
||||||
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
|
MaybeLocal<Object> maybe_instance =
|
||||||
constructor->GetFunction(), argc, argv);
|
Nan::NewInstance(constructor->GetFunction(), argc, argv);
|
||||||
if (maybe_instance.IsEmpty()) {
|
if (maybe_instance.IsEmpty()) {
|
||||||
return scope.Escape(Nan::Null());
|
return scope.Escape(Nan::Null());
|
||||||
} else {
|
} else {
|
||||||
|
@ -179,11 +179,10 @@ NAN_METHOD(ChannelCredentials::Compose) {
|
||||||
return Nan::ThrowTypeError(
|
return Nan::ThrowTypeError(
|
||||||
"compose's first argument must be a CallCredentials object");
|
"compose's first argument must be a CallCredentials object");
|
||||||
}
|
}
|
||||||
ChannelCredentials *self = ObjectWrap::Unwrap<ChannelCredentials>(
|
ChannelCredentials *self =
|
||||||
info.This());
|
ObjectWrap::Unwrap<ChannelCredentials>(info.This());
|
||||||
if (self->wrapped_credentials == NULL) {
|
if (self->wrapped_credentials == NULL) {
|
||||||
return Nan::ThrowTypeError(
|
return Nan::ThrowTypeError("Cannot compose insecure credential");
|
||||||
"Cannot compose insecure credential");
|
|
||||||
}
|
}
|
||||||
CallCredentials *other = ObjectWrap::Unwrap<CallCredentials>(
|
CallCredentials *other = ObjectWrap::Unwrap<CallCredentials>(
|
||||||
Nan::To<Object>(info[0]).ToLocalChecked());
|
Nan::To<Object>(info[0]).ToLocalChecked());
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
#ifndef NET_GRPC_NODE_CHANNEL_CREDENTIALS_H_
|
#ifndef NET_GRPC_NODE_CHANNEL_CREDENTIALS_H_
|
||||||
#define NET_GRPC_NODE_CHANNEL_CREDENTIALS_H_
|
#define NET_GRPC_NODE_CHANNEL_CREDENTIALS_H_
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/grpc_security.h"
|
#include "grpc/grpc_security.h"
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <v8.h>
|
|
||||||
#include <grpc/grpc.h>
|
#include <grpc/grpc.h>
|
||||||
|
#include <v8.h>
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include <v8.h>
|
#include <v8.h>
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/grpc_security.h"
|
#include "grpc/grpc_security.h"
|
||||||
|
@ -53,12 +53,12 @@ extern "C" {
|
||||||
#include "call_credentials.h"
|
#include "call_credentials.h"
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
#include "channel_credentials.h"
|
#include "channel_credentials.h"
|
||||||
#include "server.h"
|
#include "completion_queue.h"
|
||||||
#include "completion_queue_async_worker.h"
|
#include "completion_queue_async_worker.h"
|
||||||
|
#include "server.h"
|
||||||
#include "server_credentials.h"
|
#include "server_credentials.h"
|
||||||
#include "slice.h"
|
#include "slice.h"
|
||||||
#include "timeval.h"
|
#include "timeval.h"
|
||||||
#include "completion_queue.h"
|
|
||||||
|
|
||||||
using grpc::node::CreateSliceFromString;
|
using grpc::node::CreateSliceFromString;
|
||||||
|
|
||||||
|
@ -188,8 +188,7 @@ void InitOpTypeConstants(Local<Object> exports) {
|
||||||
Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_INITIAL_METADATA));
|
Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_INITIAL_METADATA));
|
||||||
Nan::Set(op_type, Nan::New("SEND_INITIAL_METADATA").ToLocalChecked(),
|
Nan::Set(op_type, Nan::New("SEND_INITIAL_METADATA").ToLocalChecked(),
|
||||||
SEND_INITIAL_METADATA);
|
SEND_INITIAL_METADATA);
|
||||||
Local<Value> SEND_MESSAGE(
|
Local<Value> SEND_MESSAGE(Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_MESSAGE));
|
||||||
Nan::New<Uint32, uint32_t>(GRPC_OP_SEND_MESSAGE));
|
|
||||||
Nan::Set(op_type, Nan::New("SEND_MESSAGE").ToLocalChecked(), SEND_MESSAGE);
|
Nan::Set(op_type, Nan::New("SEND_MESSAGE").ToLocalChecked(), SEND_MESSAGE);
|
||||||
Local<Value> SEND_CLOSE_FROM_CLIENT(
|
Local<Value> SEND_CLOSE_FROM_CLIENT(
|
||||||
Nan::New<Uint32, uint32_t>(GRPC_OP_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::New<Uint32, uint32_t>(GRPC_OP_RECV_INITIAL_METADATA));
|
||||||
Nan::Set(op_type, Nan::New("RECV_INITIAL_METADATA").ToLocalChecked(),
|
Nan::Set(op_type, Nan::New("RECV_INITIAL_METADATA").ToLocalChecked(),
|
||||||
RECV_INITIAL_METADATA);
|
RECV_INITIAL_METADATA);
|
||||||
Local<Value> RECV_MESSAGE(
|
Local<Value> RECV_MESSAGE(Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_MESSAGE));
|
||||||
Nan::New<Uint32, uint32_t>(GRPC_OP_RECV_MESSAGE));
|
|
||||||
Nan::Set(op_type, Nan::New("RECV_MESSAGE").ToLocalChecked(), RECV_MESSAGE);
|
Nan::Set(op_type, Nan::New("RECV_MESSAGE").ToLocalChecked(), RECV_MESSAGE);
|
||||||
Local<Value> RECV_STATUS_ON_CLIENT(
|
Local<Value> RECV_STATUS_ON_CLIENT(
|
||||||
Nan::New<Uint32, uint32_t>(GRPC_OP_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::New<Uint32, uint32_t>(GRPC_CHANNEL_TRANSIENT_FAILURE));
|
||||||
Nan::Set(channel_state, Nan::New("TRANSIENT_FAILURE").ToLocalChecked(),
|
Nan::Set(channel_state, Nan::New("TRANSIENT_FAILURE").ToLocalChecked(),
|
||||||
TRANSIENT_FAILURE);
|
TRANSIENT_FAILURE);
|
||||||
Local<Value> FATAL_FAILURE(
|
Local<Value> FATAL_FAILURE(Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_SHUTDOWN));
|
||||||
Nan::New<Uint32, uint32_t>(GRPC_CHANNEL_SHUTDOWN));
|
|
||||||
Nan::Set(channel_state, Nan::New("FATAL_FAILURE").ToLocalChecked(),
|
Nan::Set(channel_state, Nan::New("FATAL_FAILURE").ToLocalChecked(),
|
||||||
FATAL_FAILURE);
|
FATAL_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -282,13 +279,11 @@ void InitLogConstants(Local<Object> exports) {
|
||||||
|
|
||||||
NAN_METHOD(MetadataKeyIsLegal) {
|
NAN_METHOD(MetadataKeyIsLegal) {
|
||||||
if (!info[0]->IsString()) {
|
if (!info[0]->IsString()) {
|
||||||
return Nan::ThrowTypeError(
|
return Nan::ThrowTypeError("headerKeyIsLegal's argument must be a string");
|
||||||
"headerKeyIsLegal's argument must be a string");
|
|
||||||
}
|
}
|
||||||
Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
|
Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
|
||||||
grpc_slice slice = CreateSliceFromString(key);
|
grpc_slice slice = CreateSliceFromString(key);
|
||||||
info.GetReturnValue().Set(static_cast<bool>(
|
info.GetReturnValue().Set(static_cast<bool>(grpc_header_key_is_legal(slice)));
|
||||||
grpc_header_key_is_legal(slice)));
|
|
||||||
grpc_slice_unref(slice);
|
grpc_slice_unref(slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,8 +294,8 @@ NAN_METHOD(MetadataNonbinValueIsLegal) {
|
||||||
}
|
}
|
||||||
Local<String> value = Nan::To<String>(info[0]).ToLocalChecked();
|
Local<String> value = Nan::To<String>(info[0]).ToLocalChecked();
|
||||||
grpc_slice slice = CreateSliceFromString(value);
|
grpc_slice slice = CreateSliceFromString(value);
|
||||||
info.GetReturnValue().Set(static_cast<bool>(
|
info.GetReturnValue().Set(
|
||||||
grpc_header_nonbin_value_is_legal(slice)));
|
static_cast<bool>(grpc_header_nonbin_value_is_legal(slice)));
|
||||||
grpc_slice_unref(slice);
|
grpc_slice_unref(slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,8 +306,7 @@ NAN_METHOD(MetadataKeyIsBinary) {
|
||||||
}
|
}
|
||||||
Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
|
Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
|
||||||
grpc_slice slice = CreateSliceFromString(key);
|
grpc_slice slice = CreateSliceFromString(key);
|
||||||
info.GetReturnValue().Set(static_cast<bool>(
|
info.GetReturnValue().Set(static_cast<bool>(grpc_is_binary_header(slice)));
|
||||||
grpc_is_binary_header(slice)));
|
|
||||||
grpc_slice_unref(slice);
|
grpc_slice_unref(slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,11 +348,13 @@ NAUV_WORK_CB(LogMessagesCallback) {
|
||||||
args.pop();
|
args.pop();
|
||||||
Local<Value> file = Nan::New(arg->core_args.file).ToLocalChecked();
|
Local<Value> file = Nan::New(arg->core_args.file).ToLocalChecked();
|
||||||
Local<Value> line = Nan::New<Uint32, uint32_t>(arg->core_args.line);
|
Local<Value> line = Nan::New<Uint32, uint32_t>(arg->core_args.line);
|
||||||
Local<Value> severity = Nan::New(
|
Local<Value> severity =
|
||||||
gpr_log_severity_string(arg->core_args.severity)).ToLocalChecked();
|
Nan::New(gpr_log_severity_string(arg->core_args.severity))
|
||||||
|
.ToLocalChecked();
|
||||||
Local<Value> message = Nan::New(arg->core_args.message).ToLocalChecked();
|
Local<Value> message = Nan::New(arg->core_args.message).ToLocalChecked();
|
||||||
Local<Value> timestamp = Nan::New<v8::Date>(
|
Local<Value> timestamp =
|
||||||
grpc::node::TimespecToMilliseconds(arg->timestamp)).ToLocalChecked();
|
Nan::New<v8::Date>(grpc::node::TimespecToMilliseconds(arg->timestamp))
|
||||||
|
.ToLocalChecked();
|
||||||
const int argc = 5;
|
const int argc = 5;
|
||||||
Local<Value> argv[argc] = {file, line, severity, message, timestamp};
|
Local<Value> argv[argc] = {file, line, severity, message, timestamp};
|
||||||
grpc_logger_state.callback->Call(argc, argv);
|
grpc_logger_state.callback->Call(argc, argv);
|
||||||
|
@ -388,10 +384,9 @@ void init_logger() {
|
||||||
memset(&grpc_logger_state, 0, sizeof(logger_state));
|
memset(&grpc_logger_state, 0, sizeof(logger_state));
|
||||||
grpc_logger_state.pending_args = new std::queue<log_args *>();
|
grpc_logger_state.pending_args = new std::queue<log_args *>();
|
||||||
uv_mutex_init(&grpc_logger_state.mutex);
|
uv_mutex_init(&grpc_logger_state.mutex);
|
||||||
uv_async_init(uv_default_loop(),
|
uv_async_init(uv_default_loop(), &grpc_logger_state.async,
|
||||||
&grpc_logger_state.async,
|
|
||||||
LogMessagesCallback);
|
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;
|
grpc_logger_state.logger_set = false;
|
||||||
|
|
||||||
gpr_log_verbosity_init();
|
gpr_log_verbosity_init();
|
||||||
|
@ -416,11 +411,10 @@ NAN_METHOD(SetDefaultLoggerCallback) {
|
||||||
|
|
||||||
NAN_METHOD(SetLogVerbosity) {
|
NAN_METHOD(SetLogVerbosity) {
|
||||||
if (!info[0]->IsUint32()) {
|
if (!info[0]->IsUint32()) {
|
||||||
return Nan::ThrowTypeError(
|
return Nan::ThrowTypeError("setLogVerbosity's argument must be a number");
|
||||||
"setLogVerbosity's argument must be a number");
|
|
||||||
}
|
}
|
||||||
gpr_log_severity severity = static_cast<gpr_log_severity>(
|
gpr_log_severity severity =
|
||||||
Nan::To<uint32_t>(info[0]).FromJust());
|
static_cast<gpr_log_severity>(Nan::To<uint32_t>(info[0]).FromJust());
|
||||||
gpr_set_log_verbosity(severity);
|
gpr_set_log_verbosity(severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,28 +447,25 @@ void init(Local<Object> exports) {
|
||||||
|
|
||||||
// Attach a few utility functions directly to the module
|
// Attach a few utility functions directly to the module
|
||||||
Nan::Set(exports, Nan::New("metadataKeyIsLegal").ToLocalChecked(),
|
Nan::Set(exports, Nan::New("metadataKeyIsLegal").ToLocalChecked(),
|
||||||
Nan::GetFunction(
|
Nan::GetFunction(Nan::New<FunctionTemplate>(MetadataKeyIsLegal))
|
||||||
Nan::New<FunctionTemplate>(MetadataKeyIsLegal)).ToLocalChecked());
|
.ToLocalChecked());
|
||||||
Nan::Set(exports, Nan::New("metadataNonbinValueIsLegal").ToLocalChecked(),
|
Nan::Set(
|
||||||
Nan::GetFunction(
|
exports, Nan::New("metadataNonbinValueIsLegal").ToLocalChecked(),
|
||||||
Nan::New<FunctionTemplate>(MetadataNonbinValueIsLegal)
|
Nan::GetFunction(Nan::New<FunctionTemplate>(MetadataNonbinValueIsLegal))
|
||||||
).ToLocalChecked());
|
.ToLocalChecked());
|
||||||
Nan::Set(exports, Nan::New("metadataKeyIsBinary").ToLocalChecked(),
|
Nan::Set(exports, Nan::New("metadataKeyIsBinary").ToLocalChecked(),
|
||||||
Nan::GetFunction(
|
Nan::GetFunction(Nan::New<FunctionTemplate>(MetadataKeyIsBinary))
|
||||||
Nan::New<FunctionTemplate>(MetadataKeyIsBinary)
|
.ToLocalChecked());
|
||||||
).ToLocalChecked());
|
|
||||||
Nan::Set(exports, Nan::New("setDefaultRootsPem").ToLocalChecked(),
|
Nan::Set(exports, Nan::New("setDefaultRootsPem").ToLocalChecked(),
|
||||||
Nan::GetFunction(
|
Nan::GetFunction(Nan::New<FunctionTemplate>(SetDefaultRootsPem))
|
||||||
Nan::New<FunctionTemplate>(SetDefaultRootsPem)
|
.ToLocalChecked());
|
||||||
).ToLocalChecked());
|
Nan::Set(
|
||||||
Nan::Set(exports, Nan::New("setDefaultLoggerCallback").ToLocalChecked(),
|
exports, Nan::New("setDefaultLoggerCallback").ToLocalChecked(),
|
||||||
Nan::GetFunction(
|
Nan::GetFunction(Nan::New<FunctionTemplate>(SetDefaultLoggerCallback))
|
||||||
Nan::New<FunctionTemplate>(SetDefaultLoggerCallback)
|
.ToLocalChecked());
|
||||||
).ToLocalChecked());
|
|
||||||
Nan::Set(exports, Nan::New("setLogVerbosity").ToLocalChecked(),
|
Nan::Set(exports, Nan::New("setLogVerbosity").ToLocalChecked(),
|
||||||
Nan::GetFunction(
|
Nan::GetFunction(Nan::New<FunctionTemplate>(SetLogVerbosity))
|
||||||
Nan::New<FunctionTemplate>(SetLogVerbosity)
|
.ToLocalChecked());
|
||||||
).ToLocalChecked());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(grpc_node, init)
|
NODE_MODULE(grpc_node, init)
|
||||||
|
|
|
@ -111,14 +111,9 @@ class NewCallOp : public Op {
|
||||||
return scope.Escape(obj);
|
return scope.Escape(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParseOp(Local<Value> value, grpc_op *out) {
|
bool ParseOp(Local<Value> value, grpc_op *out) { return true; }
|
||||||
return true;
|
bool IsFinalOp() { return false; }
|
||||||
}
|
void OnComplete(bool success) {}
|
||||||
bool IsFinalOp() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
|
||||||
}
|
|
||||||
|
|
||||||
grpc_call *call;
|
grpc_call *call;
|
||||||
grpc_call_details details;
|
grpc_call_details details;
|
||||||
|
@ -128,7 +123,7 @@ class NewCallOp : public Op {
|
||||||
std::string GetTypeString() const { return "new_call"; }
|
std::string GetTypeString() const { return "new_call"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class TryShutdownOp: public Op {
|
class TryShutdownOp : public Op {
|
||||||
public:
|
public:
|
||||||
TryShutdownOp(Server *server, Local<Value> server_value) : server(server) {
|
TryShutdownOp(Server *server, Local<Value> server_value) : server(server) {
|
||||||
server_persist.Reset(server_value);
|
server_persist.Reset(server_value);
|
||||||
|
@ -137,19 +132,17 @@ class TryShutdownOp: public Op {
|
||||||
EscapableHandleScope scope;
|
EscapableHandleScope scope;
|
||||||
return scope.Escape(Nan::New(server_persist));
|
return scope.Escape(Nan::New(server_persist));
|
||||||
}
|
}
|
||||||
bool ParseOp(Local<Value> value, grpc_op *out) {
|
bool ParseOp(Local<Value> value, grpc_op *out) { return true; }
|
||||||
return true;
|
bool IsFinalOp() { return false; }
|
||||||
}
|
|
||||||
bool IsFinalOp() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
void OnComplete(bool success) {
|
||||||
if (success) {
|
if (success) {
|
||||||
server->DestroyWrappedServer();
|
server->DestroyWrappedServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string GetTypeString() const { return "try_shutdown"; }
|
std::string GetTypeString() const { return "try_shutdown"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Server *server;
|
Server *server;
|
||||||
Nan::Persistent<v8::Value, Nan::CopyablePersistentTraits<v8::Value>>
|
Nan::Persistent<v8::Value, Nan::CopyablePersistentTraits<v8::Value>>
|
||||||
|
@ -227,10 +220,9 @@ NAN_METHOD(Server::RequestCall) {
|
||||||
ops->push_back(unique_ptr<Op>(op));
|
ops->push_back(unique_ptr<Op>(op));
|
||||||
grpc_call_error error = grpc_server_request_call(
|
grpc_call_error error = grpc_server_request_call(
|
||||||
server->wrapped_server, &op->call, &op->details, &op->request_metadata,
|
server->wrapped_server, &op->call, &op->details, &op->request_metadata,
|
||||||
GetCompletionQueue(),
|
GetCompletionQueue(), GetCompletionQueue(),
|
||||||
GetCompletionQueue(),
|
new struct tag(new Callback(info[0].As<Function>()), ops.release(), NULL,
|
||||||
new struct tag(new Callback(info[0].As<Function>()), ops.release(),
|
Nan::Null()));
|
||||||
NULL, Nan::Null()));
|
|
||||||
if (error != GRPC_CALL_OK) {
|
if (error != GRPC_CALL_OK) {
|
||||||
return Nan::ThrowError(nanErrorWithCode("requestCall failed", error));
|
return Nan::ThrowError(nanErrorWithCode("requestCall failed", error));
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
#ifndef NET_GRPC_NODE_SERVER_H_
|
#ifndef NET_GRPC_NODE_SERVER_H_
|
||||||
#define NET_GRPC_NODE_SERVER_H_
|
#define NET_GRPC_NODE_SERVER_H_
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
|
|
|
@ -78,12 +78,12 @@ void ServerCredentials::Init(Local<Object> exports) {
|
||||||
tpl->SetClassName(Nan::New("ServerCredentials").ToLocalChecked());
|
tpl->SetClassName(Nan::New("ServerCredentials").ToLocalChecked());
|
||||||
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
Local<Function> ctr = tpl->GetFunction();
|
Local<Function> ctr = tpl->GetFunction();
|
||||||
Nan::Set(ctr, Nan::New("createSsl").ToLocalChecked(),
|
Nan::Set(
|
||||||
Nan::GetFunction(
|
ctr, Nan::New("createSsl").ToLocalChecked(),
|
||||||
Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
|
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateSsl)).ToLocalChecked());
|
||||||
Nan::Set(ctr, Nan::New("createInsecure").ToLocalChecked(),
|
Nan::Set(ctr, Nan::New("createInsecure").ToLocalChecked(),
|
||||||
Nan::GetFunction(
|
Nan::GetFunction(Nan::New<FunctionTemplate>(CreateInsecure))
|
||||||
Nan::New<FunctionTemplate>(CreateInsecure)).ToLocalChecked());
|
.ToLocalChecked());
|
||||||
fun_tpl.Reset(tpl);
|
fun_tpl.Reset(tpl);
|
||||||
constructor = new Nan::Callback(ctr);
|
constructor = new Nan::Callback(ctr);
|
||||||
Nan::Set(exports, Nan::New("ServerCredentials").ToLocalChecked(), ctr);
|
Nan::Set(exports, Nan::New("ServerCredentials").ToLocalChecked(), ctr);
|
||||||
|
@ -99,9 +99,9 @@ Local<Value> ServerCredentials::WrapStruct(
|
||||||
Nan::EscapableHandleScope scope;
|
Nan::EscapableHandleScope scope;
|
||||||
const int argc = 1;
|
const int argc = 1;
|
||||||
Local<Value> argv[argc] = {
|
Local<Value> argv[argc] = {
|
||||||
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
Nan::New<External>(reinterpret_cast<void *>(credentials))};
|
||||||
MaybeLocal<Object> maybe_instance = Nan::NewInstance(
|
MaybeLocal<Object> maybe_instance =
|
||||||
constructor->GetFunction(), argc, argv);
|
Nan::NewInstance(constructor->GetFunction(), argc, argv);
|
||||||
if (maybe_instance.IsEmpty()) {
|
if (maybe_instance.IsEmpty()) {
|
||||||
return scope.Escape(Nan::Null());
|
return scope.Escape(Nan::Null());
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,13 +160,13 @@ NAN_METHOD(ServerCredentials::CreateSsl) {
|
||||||
}
|
}
|
||||||
Local<Array> pair_list = Local<Array>::Cast(info[1]);
|
Local<Array> pair_list = Local<Array>::Cast(info[1]);
|
||||||
uint32_t key_cert_pair_count = pair_list->Length();
|
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[
|
grpc_ssl_pem_key_cert_pair *key_cert_pairs =
|
||||||
key_cert_pair_count];
|
new grpc_ssl_pem_key_cert_pair[key_cert_pair_count];
|
||||||
|
|
||||||
Local<String> key_key = Nan::New("private_key").ToLocalChecked();
|
Local<String> key_key = Nan::New("private_key").ToLocalChecked();
|
||||||
Local<String> cert_key = Nan::New("cert_chain").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();
|
Local<Value> pair_val = Nan::Get(pair_list, i).ToLocalChecked();
|
||||||
if (!pair_val->IsObject()) {
|
if (!pair_val->IsObject()) {
|
||||||
delete[] key_cert_pairs;
|
delete[] key_cert_pairs;
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
#ifndef NET_GRPC_NODE_SERVER_CREDENTIALS_H_
|
#ifndef NET_GRPC_NODE_SERVER_CREDENTIALS_H_
|
||||||
#define NET_GRPC_NODE_SERVER_CREDENTIALS_H_
|
#define NET_GRPC_NODE_SERVER_CREDENTIALS_H_
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/grpc_security.h"
|
#include "grpc/grpc_security.h"
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
|
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/support/time.h"
|
#include "grpc/support/time.h"
|
||||||
|
|
||||||
|
@ -60,22 +60,14 @@ static Callback *shutdown_callback = NULL;
|
||||||
|
|
||||||
class ServerShutdownOp : public Op {
|
class ServerShutdownOp : public Op {
|
||||||
public:
|
public:
|
||||||
ServerShutdownOp(grpc_server *server): server(server) {
|
ServerShutdownOp(grpc_server *server) : server(server) {}
|
||||||
}
|
|
||||||
|
|
||||||
~ServerShutdownOp() {
|
~ServerShutdownOp() {}
|
||||||
}
|
|
||||||
|
|
||||||
Local<Value> GetNodeValue() const {
|
Local<Value> GetNodeValue() const { return Nan::Null(); }
|
||||||
return Nan::Null();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ParseOp(Local<Value> value, grpc_op *out) {
|
bool ParseOp(Local<Value> value, grpc_op *out) { return true; }
|
||||||
return true;
|
bool IsFinalOp() { return false; }
|
||||||
}
|
|
||||||
bool IsFinalOp() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void OnComplete(bool success) {
|
void OnComplete(bool success) {
|
||||||
/* Because cancel_all_calls was called, we assume that shutdown_and_notify
|
/* Because cancel_all_calls was called, we assume that shutdown_and_notify
|
||||||
completes successfully */
|
completes successfully */
|
||||||
|
@ -88,12 +80,9 @@ class ServerShutdownOp : public Op {
|
||||||
std::string GetTypeString() const { return "shutdown"; }
|
std::string GetTypeString() const { return "shutdown"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
Server::Server(grpc_server *server) : wrapped_server(server) {
|
Server::Server(grpc_server *server) : wrapped_server(server) {}
|
||||||
}
|
|
||||||
|
|
||||||
Server::~Server() {
|
Server::~Server() { this->ShutdownServer(); }
|
||||||
this->ShutdownServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
NAN_METHOD(ServerShutdownCallback) {
|
NAN_METHOD(ServerShutdownCallback) {
|
||||||
if (!info[0]->IsNull()) {
|
if (!info[0]->IsNull()) {
|
||||||
|
@ -105,10 +94,10 @@ void Server::ShutdownServer() {
|
||||||
Nan::HandleScope scope;
|
Nan::HandleScope scope;
|
||||||
if (this->wrapped_server != NULL) {
|
if (this->wrapped_server != NULL) {
|
||||||
if (shutdown_callback == NULL) {
|
if (shutdown_callback == NULL) {
|
||||||
Local<FunctionTemplate>callback_tpl =
|
Local<FunctionTemplate> callback_tpl =
|
||||||
Nan::New<FunctionTemplate>(ServerShutdownCallback);
|
Nan::New<FunctionTemplate>(ServerShutdownCallback);
|
||||||
shutdown_callback = new Callback(
|
shutdown_callback =
|
||||||
Nan::GetFunction(callback_tpl).ToLocalChecked());
|
new Callback(Nan::GetFunction(callback_tpl).ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerShutdownOp *op = new ServerShutdownOp(this->wrapped_server);
|
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/slice.h>
|
||||||
#include <grpc/support/alloc.h>
|
#include <grpc/support/alloc.h>
|
||||||
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
|
|
||||||
#include "slice.h"
|
#include "slice.h"
|
||||||
|
|
||||||
|
@ -49,19 +49,19 @@ using v8::Value;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void SliceFreeCallback(char *data, void *hint) {
|
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);
|
grpc_slice_unref(*slice);
|
||||||
delete slice;
|
delete slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
void string_destroy_func(void *user_data) {
|
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) {
|
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) {
|
grpc_slice CreateSliceFromString(const Local<String> source) {
|
||||||
Nan::HandleScope scope;
|
Nan::HandleScope scope;
|
||||||
|
@ -73,28 +73,32 @@ grpc_slice CreateSliceFromString(const Local<String> source) {
|
||||||
grpc_slice CreateSliceFromBuffer(const Local<Value> source) {
|
grpc_slice CreateSliceFromBuffer(const Local<Value> source) {
|
||||||
// Prerequisite: ::node::Buffer::HasInstance(source)
|
// Prerequisite: ::node::Buffer::HasInstance(source)
|
||||||
Nan::HandleScope scope;
|
Nan::HandleScope scope;
|
||||||
return grpc_slice_new_with_user_data(::node::Buffer::Data(source),
|
return grpc_slice_new_with_user_data(
|
||||||
::node::Buffer::Length(source),
|
::node::Buffer::Data(source), ::node::Buffer::Length(source),
|
||||||
buffer_destroy_func,
|
buffer_destroy_func, new PersistentValue(source));
|
||||||
new PersistentValue(source));
|
|
||||||
}
|
}
|
||||||
Local<String> CopyStringFromSlice(const grpc_slice slice) {
|
Local<String> CopyStringFromSlice(const grpc_slice slice) {
|
||||||
Nan::EscapableHandleScope scope;
|
Nan::EscapableHandleScope scope;
|
||||||
if (GRPC_SLICE_LENGTH(slice) == 0) {
|
if (GRPC_SLICE_LENGTH(slice) == 0) {
|
||||||
return scope.Escape(Nan::EmptyString());
|
return scope.Escape(Nan::EmptyString());
|
||||||
}
|
}
|
||||||
return scope.Escape(Nan::New<String>(
|
return scope.Escape(
|
||||||
const_cast<char *>(reinterpret_cast<const char *>(GRPC_SLICE_START_PTR(slice))),
|
Nan::New<String>(const_cast<char *>(reinterpret_cast<const char *>(
|
||||||
GRPC_SLICE_LENGTH(slice)).ToLocalChecked());
|
GRPC_SLICE_START_PTR(slice))),
|
||||||
|
GRPC_SLICE_LENGTH(slice))
|
||||||
|
.ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
Local<Value> CreateBufferFromSlice(const grpc_slice slice) {
|
Local<Value> CreateBufferFromSlice(const grpc_slice slice) {
|
||||||
Nan::EscapableHandleScope scope;
|
Nan::EscapableHandleScope scope;
|
||||||
grpc_slice *slice_ptr = new grpc_slice;
|
grpc_slice *slice_ptr = new grpc_slice;
|
||||||
*slice_ptr = grpc_slice_ref(slice);
|
*slice_ptr = grpc_slice_ref(slice);
|
||||||
return scope.Escape(Nan::NewBuffer(
|
return scope.Escape(
|
||||||
const_cast<char *>(reinterpret_cast<const char *>(GRPC_SLICE_START_PTR(*slice_ptr))),
|
Nan::NewBuffer(
|
||||||
GRPC_SLICE_LENGTH(*slice_ptr), SliceFreeCallback, slice_ptr).ToLocalChecked());
|
const_cast<char *>(
|
||||||
|
reinterpret_cast<const char *>(GRPC_SLICE_START_PTR(*slice_ptr))),
|
||||||
|
GRPC_SLICE_LENGTH(*slice_ptr), SliceFreeCallback, slice_ptr)
|
||||||
|
.ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
|
@ -31,14 +31,15 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include <nan.h>
|
|
||||||
#include <grpc/slice.h>
|
#include <grpc/slice.h>
|
||||||
|
#include <nan.h>
|
||||||
|
#include <node.h>
|
||||||
|
|
||||||
namespace grpc {
|
namespace grpc {
|
||||||
namespace node {
|
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);
|
grpc_slice CreateSliceFromString(const v8::Local<v8::String> source);
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
#include "grpc/grpc.h"
|
#include "grpc/grpc.h"
|
||||||
#include "grpc/support/time.h"
|
#include "grpc/support/time.h"
|
||||||
|
|
|
@ -88,7 +88,10 @@ function timeDiffToNanos(time_diff) {
|
||||||
*/
|
*/
|
||||||
function BenchmarkClient(server_targets, channels, histogram_params,
|
function BenchmarkClient(server_targets, channels, histogram_params,
|
||||||
security_params) {
|
security_params) {
|
||||||
var options = {};
|
var options = {
|
||||||
|
"grpc.max_receive_message_length": -1,
|
||||||
|
"grpc.max_send_message_length": -1
|
||||||
|
};
|
||||||
var creds;
|
var creds;
|
||||||
if (security_params) {
|
if (security_params) {
|
||||||
var ca_path;
|
var ca_path;
|
||||||
|
@ -180,6 +183,8 @@ BenchmarkClient.prototype.startClosedLoop = function(
|
||||||
|
|
||||||
self.last_wall_time = process.hrtime();
|
self.last_wall_time = process.hrtime();
|
||||||
|
|
||||||
|
self.last_usage = process.cpuUsage();
|
||||||
|
|
||||||
var makeCall;
|
var makeCall;
|
||||||
|
|
||||||
var argument;
|
var argument;
|
||||||
|
@ -270,6 +275,8 @@ BenchmarkClient.prototype.startPoisson = function(
|
||||||
|
|
||||||
self.last_wall_time = process.hrtime();
|
self.last_wall_time = process.hrtime();
|
||||||
|
|
||||||
|
self.last_usage = process.cpuUsage();
|
||||||
|
|
||||||
var makeCall;
|
var makeCall;
|
||||||
|
|
||||||
var argument;
|
var argument;
|
||||||
|
@ -354,9 +361,11 @@ BenchmarkClient.prototype.startPoisson = function(
|
||||||
*/
|
*/
|
||||||
BenchmarkClient.prototype.mark = function(reset) {
|
BenchmarkClient.prototype.mark = function(reset) {
|
||||||
var wall_time_diff = process.hrtime(this.last_wall_time);
|
var wall_time_diff = process.hrtime(this.last_wall_time);
|
||||||
|
var usage_diff = process.cpuUsage(this.last_usage);
|
||||||
var histogram = this.histogram;
|
var histogram = this.histogram;
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this.last_wall_time = process.hrtime();
|
this.last_wall_time = process.hrtime();
|
||||||
|
this.last_usage = process.cpuUsage();
|
||||||
this.histogram = new Histogram(histogram.resolution,
|
this.histogram = new Histogram(histogram.resolution,
|
||||||
histogram.max_possible);
|
histogram.max_possible);
|
||||||
}
|
}
|
||||||
|
@ -371,9 +380,8 @@ BenchmarkClient.prototype.mark = function(reset) {
|
||||||
count: histogram.getCount()
|
count: histogram.getCount()
|
||||||
},
|
},
|
||||||
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
|
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
|
||||||
// Not sure how to measure these values
|
time_user: usage_diff.user / 1000000,
|
||||||
time_user: 0,
|
time_system: usage_diff.system / 1000000
|
||||||
time_system: 0
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,6 @@ function BenchmarkClient(server_targets, channels, histogram_params,
|
||||||
var host_port;
|
var host_port;
|
||||||
host_port = server_targets[i % server_targets.length].split(':');
|
host_port = server_targets[i % server_targets.length].split(':');
|
||||||
var new_options = _.assign({hostname: host_port[0], port: +host_port[1]}, options);
|
var new_options = _.assign({hostname: host_port[0], port: +host_port[1]}, options);
|
||||||
new_options.agent = new protocol.Agent(new_options);
|
|
||||||
this.client_options[i] = new_options;
|
this.client_options[i] = new_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +136,7 @@ BenchmarkClient.prototype.startClosedLoop = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
self.last_wall_time = process.hrtime();
|
self.last_wall_time = process.hrtime();
|
||||||
|
self.last_usage = process.cpuUsage();
|
||||||
|
|
||||||
var argument = {
|
var argument = {
|
||||||
response_size: resp_size,
|
response_size: resp_size,
|
||||||
|
@ -207,6 +207,7 @@ BenchmarkClient.prototype.startPoisson = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
self.last_wall_time = process.hrtime();
|
self.last_wall_time = process.hrtime();
|
||||||
|
self.last_usage = process.cpuUsage();
|
||||||
|
|
||||||
var argument = {
|
var argument = {
|
||||||
response_size: resp_size,
|
response_size: resp_size,
|
||||||
|
@ -264,9 +265,11 @@ BenchmarkClient.prototype.startPoisson = function(
|
||||||
*/
|
*/
|
||||||
BenchmarkClient.prototype.mark = function(reset) {
|
BenchmarkClient.prototype.mark = function(reset) {
|
||||||
var wall_time_diff = process.hrtime(this.last_wall_time);
|
var wall_time_diff = process.hrtime(this.last_wall_time);
|
||||||
|
var usage_diff = process.cpuUsage(this.last_usage);
|
||||||
var histogram = this.histogram;
|
var histogram = this.histogram;
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this.last_wall_time = process.hrtime();
|
this.last_wall_time = process.hrtime();
|
||||||
|
this.last_usage = process.cpuUsage();
|
||||||
this.histogram = new Histogram(histogram.resolution,
|
this.histogram = new Histogram(histogram.resolution,
|
||||||
histogram.max_possible);
|
histogram.max_possible);
|
||||||
}
|
}
|
||||||
|
@ -281,9 +284,8 @@ BenchmarkClient.prototype.mark = function(reset) {
|
||||||
count: histogram.getCount()
|
count: histogram.getCount()
|
||||||
},
|
},
|
||||||
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
|
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
|
||||||
// Not sure how to measure these values
|
time_user: usage_diff.user / 1000000,
|
||||||
time_user: 0,
|
time_system: usage_diff.system / 1000000
|
||||||
time_system: 0
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,12 @@ function BenchmarkServer(host, port, tls, generic, response_size) {
|
||||||
server_creds = grpc.ServerCredentials.createInsecure();
|
server_creds = grpc.ServerCredentials.createInsecure();
|
||||||
}
|
}
|
||||||
|
|
||||||
var server = new grpc.Server();
|
var options = {
|
||||||
|
"grpc.max_receive_message_length": -1,
|
||||||
|
"grpc.max_send_message_length": -1
|
||||||
|
};
|
||||||
|
|
||||||
|
var server = new grpc.Server(options);
|
||||||
this.port = server.bind(host + ':' + port, server_creds);
|
this.port = server.bind(host + ':' + port, server_creds);
|
||||||
if (generic) {
|
if (generic) {
|
||||||
server.addService(genericService, {
|
server.addService(genericService, {
|
||||||
|
@ -156,6 +161,7 @@ util.inherits(BenchmarkServer, EventEmitter);
|
||||||
BenchmarkServer.prototype.start = function() {
|
BenchmarkServer.prototype.start = function() {
|
||||||
this.server.start();
|
this.server.start();
|
||||||
this.last_wall_time = process.hrtime();
|
this.last_wall_time = process.hrtime();
|
||||||
|
this.last_usage = process.cpuUsage();
|
||||||
this.emit('started');
|
this.emit('started');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -175,14 +181,15 @@ BenchmarkServer.prototype.getPort = function() {
|
||||||
*/
|
*/
|
||||||
BenchmarkServer.prototype.mark = function(reset) {
|
BenchmarkServer.prototype.mark = function(reset) {
|
||||||
var wall_time_diff = process.hrtime(this.last_wall_time);
|
var wall_time_diff = process.hrtime(this.last_wall_time);
|
||||||
|
var usage_diff = process.cpuUsage(this.last_usage);
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this.last_wall_time = process.hrtime();
|
this.last_wall_time = process.hrtime();
|
||||||
|
this.last_usage = process.cpuUsage();
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
|
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
|
||||||
// Not sure how to measure these values
|
time_user: usage_diff.user / 1000000,
|
||||||
time_user: 0,
|
time_system: usage_diff.system / 1000000
|
||||||
time_system: 0
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ BenchmarkServer.prototype.start = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.server.listen(this.input_port, this.input_hostname, function() {
|
this.server.listen(this.input_port, this.input_hostname, function() {
|
||||||
self.last_wall_time = process.hrtime();
|
self.last_wall_time = process.hrtime();
|
||||||
|
self.last_usage = process.cpuUsage();
|
||||||
self.emit('started');
|
self.emit('started');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -91,14 +92,15 @@ BenchmarkServer.prototype.getPort = function() {
|
||||||
|
|
||||||
BenchmarkServer.prototype.mark = function(reset) {
|
BenchmarkServer.prototype.mark = function(reset) {
|
||||||
var wall_time_diff = process.hrtime(this.last_wall_time);
|
var wall_time_diff = process.hrtime(this.last_wall_time);
|
||||||
|
var usage_diff = process.cpuUsage(this.last_usage);
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this.last_wall_time = process.hrtime();
|
this.last_wall_time = process.hrtime();
|
||||||
|
this.last_usage = process.cpuUsage();
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
|
time_elapsed: wall_time_diff[0] + wall_time_diff[1] / 1e9,
|
||||||
// Not sure how to measure these values
|
time_user: usage_diff.user / 1000000,
|
||||||
time_user: 0,
|
time_system: usage_diff.system / 1000000
|
||||||
time_system: 0
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue