aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler/python_plugin.cc1
-rw-r--r--src/core/iomgr/resolve_address_posix.c15
-rw-r--r--src/core/support/histogram.c35
-rw-r--r--src/core/surface/call.c2
-rw-r--r--src/node/binding.gyp30
-rw-r--r--src/node/ext/byte_buffer.cc17
-rw-r--r--src/node/ext/call.cc55
-rw-r--r--src/node/ext/call.h10
-rw-r--r--src/node/ext/channel.cc14
-rw-r--r--src/node/ext/channel.h2
-rw-r--r--src/node/ext/credentials.cc56
-rw-r--r--src/node/ext/credentials.h2
-rw-r--r--src/node/ext/node_grpc.cc6
-rw-r--r--src/node/ext/server.cc27
-rw-r--r--src/node/ext/server.h2
-rw-r--r--src/node/ext/server_credentials.cc40
-rw-r--r--src/node/ext/server_credentials.h2
-rw-r--r--src/node/package.json13
-rw-r--r--src/ruby/ext/grpc/extconf.rb1
-rw-r--r--src/ruby/ext/grpc/rb_grpc.c6
20 files changed, 175 insertions, 161 deletions
diff --git a/src/compiler/python_plugin.cc b/src/compiler/python_plugin.cc
index 0dd2c5b834..825f15a5c7 100644
--- a/src/compiler/python_plugin.cc
+++ b/src/compiler/python_plugin.cc
@@ -36,6 +36,7 @@
#include <cstring>
#include <memory>
#include <string>
+#include <tuple>
#include "src/compiler/python_generator.h"
#include <google/protobuf/compiler/code_generator.h>
diff --git a/src/core/iomgr/resolve_address_posix.c b/src/core/iomgr/resolve_address_posix.c
index 989b968ae2..85085dc37d 100644
--- a/src/core/iomgr/resolve_address_posix.c
+++ b/src/core/iomgr/resolve_address_posix.c
@@ -102,6 +102,21 @@ grpc_resolved_addresses *grpc_blocking_resolve_address(
s = getaddrinfo(host, port, &hints, &result);
if (s != 0) {
+ /* Retry if well-known service name is recognized */
+ char *svc[][2] = {
+ {"http", "80"},
+ {"https", "443"}
+ };
+ int i;
+ for (i = 0; i < (int)(sizeof(svc) / sizeof(svc[0])); i++) {
+ if (!strcmp(port, svc[i][0])) {
+ s = getaddrinfo(host, svc[i][1], &hints, &result);
+ break;
+ }
+ }
+ }
+
+ if (s != 0) {
gpr_log(GPR_ERROR, "getaddrinfo: %s", gai_strerror(s));
goto done;
}
diff --git a/src/core/support/histogram.c b/src/core/support/histogram.c
index eacb77082f..ed344b43e8 100644
--- a/src/core/support/histogram.c
+++ b/src/core/support/histogram.c
@@ -126,25 +126,35 @@ void gpr_histogram_add(gpr_histogram *h, double x) {
}
int gpr_histogram_merge(gpr_histogram *dst, gpr_histogram *src) {
- size_t i;
if ((dst->num_buckets != src->num_buckets) ||
(dst->multiplier != src->multiplier)) {
/* Fail because these histograms don't match */
return 0;
}
- dst->sum += src->sum;
- dst->sum_of_squares += src->sum_of_squares;
- dst->count += src->count;
- if (src->min_seen < dst->min_seen) {
- dst->min_seen = src->min_seen;
+ gpr_histogram_merge_contents(dst, src->buckets, src->num_buckets,
+ src->min_seen, src->max_seen, src->sum,
+ src->sum_of_squares, src->count);
+ return 1;
+}
+
+void gpr_histogram_merge_contents(gpr_histogram *dst, const gpr_uint32 *data,
+ size_t data_count, double min_seen,
+ double max_seen, double sum,
+ double sum_of_squares, double count) {
+ size_t i;
+ GPR_ASSERT(dst->num_buckets == data_count);
+ dst->sum += sum;
+ dst->sum_of_squares += sum_of_squares;
+ dst->count += count;
+ if (min_seen < dst->min_seen) {
+ dst->min_seen = min_seen;
}
- if (src->max_seen > dst->max_seen) {
- dst->max_seen = src->max_seen;
+ if (max_seen > dst->max_seen) {
+ dst->max_seen = max_seen;
}
for (i = 0; i < dst->num_buckets; i++) {
- dst->buckets[i] += src->buckets[i];
+ dst->buckets[i] += data[i];
}
- return 1;
}
static double threshold_for_count_below(gpr_histogram *h, double count_below) {
@@ -222,3 +232,8 @@ double gpr_histogram_sum(gpr_histogram *h) { return h->sum; }
double gpr_histogram_sum_of_squares(gpr_histogram *h) {
return h->sum_of_squares;
}
+
+const gpr_uint32 *gpr_histogram_get_contents(gpr_histogram *h, size_t *size) {
+ *size = h->num_buckets;
+ return h->buckets;
+}
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index b2033f3dc0..cfce943794 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -375,6 +375,7 @@ static void unlock(grpc_call *call) {
sizeof(completed_requests));
call->num_completed_requests = 0;
call->completing = 1;
+ grpc_call_internal_ref(call);
}
if (!call->sending) {
@@ -403,6 +404,7 @@ static void unlock(grpc_call *call) {
lock(call);
call->completing = 0;
unlock(call);
+ grpc_call_internal_unref(call, 0);
}
}
diff --git a/src/node/binding.gyp b/src/node/binding.gyp
index 10afaf6962..7ef3bdf4bd 100644
--- a/src/node/binding.gyp
+++ b/src/node/binding.gyp
@@ -1,9 +1,4 @@
{
- "variables" : {
- 'no_install': "<!(echo $GRPC_NO_INSTALL)",
- 'grpc_root': "<!(echo $GRPC_ROOT)",
- 'grpc_lib_subdir': "<!(echo $GRPC_LIB_SUBDIR)"
- },
"targets" : [
{
'include_dirs': [
@@ -24,7 +19,9 @@
'link_settings': {
'libraries': [
'-lrt',
- '-lpthread'
+ '-lpthread',
+ '-lgrpc',
+ '-lgpr'
],
},
"target_name": "grpc",
@@ -38,27 +35,6 @@
"ext/server.cc",
"ext/server_credentials.cc",
"ext/timeval.cc"
- ],
- 'conditions' : [
- ['no_install=="yes"', {
- 'include_dirs': [
- "<(grpc_root)/include"
- ],
- 'link_settings': {
- 'libraries': [
- '<(grpc_root)/<(grpc_lib_subdir)/libgrpc.a',
- '<(grpc_root)/<(grpc_lib_subdir)/libgpr.a'
- ]
- }
- }],
- ['no_install!="yes"', {
- 'link_settings': {
- 'libraries': [
- '-lgrpc',
- '-lgpr'
- ]
- }
- }]
]
}
]
diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc
index c165d26e47..5235c8e083 100644
--- a/src/node/ext/byte_buffer.cc
+++ b/src/node/ext/byte_buffer.cc
@@ -44,7 +44,6 @@
namespace grpc {
namespace node {
-using ::node::Buffer;
using v8::Context;
using v8::Function;
using v8::Handle;
@@ -54,8 +53,8 @@ using v8::Value;
grpc_byte_buffer *BufferToByteBuffer(Handle<Value> buffer) {
NanScope();
- int length = Buffer::Length(buffer);
- char *data = Buffer::Data(buffer);
+ int length = ::node::Buffer::Length(buffer);
+ char *data = ::node::Buffer::Data(buffer);
gpr_slice slice = gpr_slice_malloc(length);
memcpy(GPR_SLICE_START_PTR(slice), data, length);
grpc_byte_buffer *byte_buffer(grpc_byte_buffer_create(&slice, 1));
@@ -66,7 +65,7 @@ grpc_byte_buffer *BufferToByteBuffer(Handle<Value> buffer) {
Handle<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
NanEscapableScope();
if (buffer == NULL) {
- NanReturnNull();
+ return NanNull();
}
size_t length = grpc_byte_buffer_length(buffer);
char *result = reinterpret_cast<char *>(calloc(length, sizeof(char)));
@@ -82,12 +81,14 @@ Handle<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
Handle<Value> MakeFastBuffer(Handle<Value> slowBuffer) {
NanEscapableScope();
- Handle<Object> globalObj = Context::GetCurrent()->Global();
+ Handle<Object> globalObj = NanGetCurrentContext()->Global();
Handle<Function> bufferConstructor = Handle<Function>::Cast(
globalObj->Get(NanNew("Buffer")));
- Handle<Value> consArgs[3] = { slowBuffer,
- NanNew<Number>(Buffer::Length(slowBuffer)),
- NanNew<Number>(0) };
+ Handle<Value> consArgs[3] = {
+ slowBuffer,
+ NanNew<Number>(::node::Buffer::Length(slowBuffer)),
+ NanNew<Number>(0)
+ };
Handle<Object> fastBuffer = bufferConstructor->NewInstance(3, consArgs);
return NanEscapeScope(fastBuffer);
}
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index 9ed389f3bc..afb6541783 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -54,8 +54,6 @@ using std::vector;
namespace grpc {
namespace node {
-using ::node::Buffer;
-using v8::Arguments;
using v8::Array;
using v8::Boolean;
using v8::Exception;
@@ -74,7 +72,7 @@ using v8::Uint32;
using v8::String;
using v8::Value;
-Persistent<Function> Call::constructor;
+NanCallback *Call::constructor;
Persistent<FunctionTemplate> Call::fun_tpl;
@@ -101,11 +99,11 @@ bool CreateMetadataArray(Handle<Object> metadata, grpc_metadata_array *array,
Handle<Value> value = values->Get(j);
grpc_metadata *current = &array->metadata[array->count];
current->key = **utf8_key;
- if (Buffer::HasInstance(value)) {
- current->value = Buffer::Data(value);
- current->value_length = Buffer::Length(value);
- Persistent<Value> handle;
- NanAssignPersistent(handle, value);
+ if (::node::Buffer::HasInstance(value)) {
+ current->value = ::node::Buffer::Data(value);
+ current->value_length = ::node::Buffer::Length(value);
+ Persistent<Value> *handle = new Persistent<Value>();
+ NanAssignPersistent(*handle, value);
resources->handles.push_back(unique_ptr<PersistentHolder>(
new PersistentHolder(handle)));
} else if (value->IsString()) {
@@ -140,7 +138,7 @@ Handle<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
Handle<Object> metadata_object = NanNew<Object>();
for (unsigned int i = 0; i < length; i++) {
grpc_metadata* elem = &metadata_elements[i];
- Handle<String> key_string = String::New(elem->key);
+ Handle<String> key_string = NanNew(elem->key);
Handle<Array> array;
if (metadata_object->Has(key_string)) {
array = Handle<Array>::Cast(metadata_object->Get(key_string));
@@ -194,12 +192,12 @@ class SendMessageOp : public Op {
}
bool ParseOp(Handle<Value> value, grpc_op *out,
shared_ptr<Resources> resources) {
- if (!Buffer::HasInstance(value)) {
+ if (!::node::Buffer::HasInstance(value)) {
return false;
}
out->data.send_message = BufferToByteBuffer(value);
- Persistent<Value> handle;
- NanAssignPersistent(handle, value);
+ Persistent<Value> *handle = new Persistent<Value>();
+ NanAssignPersistent(*handle, value);
resources->handles.push_back(unique_ptr<PersistentHolder>(
new PersistentHolder(handle)));
return true;
@@ -357,7 +355,7 @@ class ClientStatusOp : public Op {
Handle<Object> status_obj = NanNew<Object>();
status_obj->Set(NanNew("code"), NanNew<Number>(status));
if (status_details != NULL) {
- status_obj->Set(NanNew("details"), String::New(status_details));
+ status_obj->Set(NanNew("details"), NanNew(status_details));
}
status_obj->Set(NanNew("metadata"), ParseMetadata(&metadata_array));
return NanEscapeScope(status_obj);
@@ -436,20 +434,21 @@ Call::~Call() {
void Call::Init(Handle<Object> exports) {
NanScope();
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
tpl->SetClassName(NanNew("Call"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NanSetPrototypeTemplate(tpl, "startBatch",
- FunctionTemplate::New(StartBatch)->GetFunction());
+ NanNew<FunctionTemplate>(StartBatch)->GetFunction());
NanSetPrototypeTemplate(tpl, "cancel",
- FunctionTemplate::New(Cancel)->GetFunction());
+ NanNew<FunctionTemplate>(Cancel)->GetFunction());
NanAssignPersistent(fun_tpl, tpl);
- NanAssignPersistent(constructor, tpl->GetFunction());
- constructor->Set(NanNew("WRITE_BUFFER_HINT"),
- NanNew<Uint32, uint32_t>(GRPC_WRITE_BUFFER_HINT));
- constructor->Set(NanNew("WRITE_NO_COMPRESS"),
- NanNew<Uint32, uint32_t>(GRPC_WRITE_NO_COMPRESS));
- exports->Set(String::NewSymbol("Call"), constructor);
+ Handle<Function> ctr = tpl->GetFunction();
+ ctr->Set(NanNew("WRITE_BUFFER_HINT"),
+ NanNew<Uint32, uint32_t>(GRPC_WRITE_BUFFER_HINT));
+ ctr->Set(NanNew("WRITE_NO_COMPRESS"),
+ NanNew<Uint32, uint32_t>(GRPC_WRITE_NO_COMPRESS));
+ exports->Set(NanNew("Call"), ctr);
+ constructor = new NanCallback(ctr);
}
bool Call::HasInstance(Handle<Value> val) {
@@ -463,8 +462,8 @@ Handle<Value> Call::WrapStruct(grpc_call *call) {
return NanEscapeScope(NanNull());
}
const int argc = 1;
- Handle<Value> argv[argc] = {External::New(reinterpret_cast<void *>(call))};
- return NanEscapeScope(constructor->NewInstance(argc, argv));
+ Handle<Value> argv[argc] = {NanNew<External>(reinterpret_cast<void *>(call))};
+ return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv));
}
NAN_METHOD(Call::New) {
@@ -473,9 +472,10 @@ NAN_METHOD(Call::New) {
if (args.IsConstructCall()) {
Call *call;
if (args[0]->IsExternal()) {
+ Handle<External> ext = args[0].As<External>();
// This option is used for wrapping an existing call
grpc_call *call_value =
- reinterpret_cast<grpc_call *>(External::Unwrap(args[0]));
+ reinterpret_cast<grpc_call *>(ext->Value());
call = new Call(call_value);
} else {
if (!Channel::HasInstance(args[0])) {
@@ -500,15 +500,14 @@ NAN_METHOD(Call::New) {
wrapped_channel, CompletionQueueAsyncWorker::GetQueue(), *method,
channel->GetHost(), MillisecondsToTimespec(deadline));
call = new Call(wrapped_call);
- args.This()->SetHiddenValue(String::NewSymbol("channel_"),
- channel_object);
+ args.This()->SetHiddenValue(NanNew("channel_"), channel_object);
}
call->Wrap(args.This());
NanReturnValue(args.This());
} else {
const int argc = 4;
Local<Value> argv[argc] = {args[0], args[1], args[2], args[3]};
- NanReturnValue(constructor->NewInstance(argc, argv));
+ NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
}
}
diff --git a/src/node/ext/call.h b/src/node/ext/call.h
index 933541ce5b..43142c7091 100644
--- a/src/node/ext/call.h
+++ b/src/node/ext/call.h
@@ -40,6 +40,7 @@
#include <node.h>
#include <nan.h>
#include "grpc/grpc.h"
+#include "grpc/support/log.h"
#include "channel.h"
@@ -54,16 +55,17 @@ v8::Handle<v8::Value> ParseMetadata(const grpc_metadata_array *metadata_array);
class PersistentHolder {
public:
- explicit PersistentHolder(v8::Persistent<v8::Value> persist) :
+ explicit PersistentHolder(v8::Persistent<v8::Value> *persist) :
persist(persist) {
}
~PersistentHolder() {
- NanDisposePersistent(persist);
+ NanDisposePersistent(*persist);
+ delete persist;
}
private:
- v8::Persistent<v8::Value> persist;
+ v8::Persistent<v8::Value> *persist;
};
struct Resources {
@@ -118,7 +120,7 @@ class Call : public ::node::ObjectWrap {
static NAN_METHOD(New);
static NAN_METHOD(StartBatch);
static NAN_METHOD(Cancel);
- static v8::Persistent<v8::Function> constructor;
+ static NanCallback *constructor;
// Used for typechecking instances of this javascript class
static v8::Persistent<v8::FunctionTemplate> fun_tpl;
diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc
index bc9461d7df..787e274973 100644
--- a/src/node/ext/channel.cc
+++ b/src/node/ext/channel.cc
@@ -45,7 +45,6 @@
namespace grpc {
namespace node {
-using v8::Arguments;
using v8::Array;
using v8::Exception;
using v8::Function;
@@ -59,7 +58,7 @@ using v8::Persistent;
using v8::String;
using v8::Value;
-Persistent<Function> Channel::constructor;
+NanCallback *Channel::constructor;
Persistent<FunctionTemplate> Channel::fun_tpl;
Channel::Channel(grpc_channel *channel, NanUtf8String *host)
@@ -74,14 +73,15 @@ Channel::~Channel() {
void Channel::Init(Handle<Object> exports) {
NanScope();
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
tpl->SetClassName(NanNew("Channel"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NanSetPrototypeTemplate(tpl, "close",
- FunctionTemplate::New(Close)->GetFunction());
+ NanNew<FunctionTemplate>(Close)->GetFunction());
NanAssignPersistent(fun_tpl, tpl);
- NanAssignPersistent(constructor, tpl->GetFunction());
- exports->Set(NanNew("Channel"), constructor);
+ Handle<Function> ctr = tpl->GetFunction();
+ constructor = new NanCallback(ctr);
+ exports->Set(NanNew("Channel"), ctr);
}
bool Channel::HasInstance(Handle<Value> val) {
@@ -170,7 +170,7 @@ NAN_METHOD(Channel::New) {
} else {
const int argc = 2;
Local<Value> argv[argc] = {args[0], args[1]};
- NanReturnValue(constructor->NewInstance(argc, argv));
+ NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
}
}
diff --git a/src/node/ext/channel.h b/src/node/ext/channel.h
index bf793194d9..b3aa0f700f 100644
--- a/src/node/ext/channel.h
+++ b/src/node/ext/channel.h
@@ -66,7 +66,7 @@ class Channel : public ::node::ObjectWrap {
static NAN_METHOD(New);
static NAN_METHOD(Close);
- static v8::Persistent<v8::Function> constructor;
+ static NanCallback *constructor;
static v8::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_channel *wrapped_channel;
diff --git a/src/node/ext/credentials.cc b/src/node/ext/credentials.cc
index 3f65d59c76..34872017ea 100644
--- a/src/node/ext/credentials.cc
+++ b/src/node/ext/credentials.cc
@@ -41,8 +41,6 @@
namespace grpc {
namespace node {
-using ::node::Buffer;
-using v8::Arguments;
using v8::Exception;
using v8::External;
using v8::Function;
@@ -56,7 +54,7 @@ using v8::ObjectTemplate;
using v8::Persistent;
using v8::Value;
-Persistent<Function> Credentials::constructor;
+NanCallback *Credentials::constructor;
Persistent<FunctionTemplate> Credentials::fun_tpl;
Credentials::Credentials(grpc_credentials *credentials)
@@ -68,24 +66,25 @@ Credentials::~Credentials() {
void Credentials::Init(Handle<Object> exports) {
NanScope();
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
tpl->SetClassName(NanNew("Credentials"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NanAssignPersistent(fun_tpl, tpl);
- NanAssignPersistent(constructor, tpl->GetFunction());
- constructor->Set(NanNew("createDefault"),
- FunctionTemplate::New(CreateDefault)->GetFunction());
- constructor->Set(NanNew("createSsl"),
- FunctionTemplate::New(CreateSsl)->GetFunction());
- constructor->Set(NanNew("createComposite"),
- FunctionTemplate::New(CreateComposite)->GetFunction());
- constructor->Set(NanNew("createGce"),
- FunctionTemplate::New(CreateGce)->GetFunction());
- constructor->Set(NanNew("createFake"),
- FunctionTemplate::New(CreateFake)->GetFunction());
- constructor->Set(NanNew("createIam"),
- FunctionTemplate::New(CreateIam)->GetFunction());
- exports->Set(NanNew("Credentials"), constructor);
+ Handle<Function> ctr = tpl->GetFunction();
+ ctr->Set(NanNew("createDefault"),
+ NanNew<FunctionTemplate>(CreateDefault)->GetFunction());
+ ctr->Set(NanNew("createSsl"),
+ NanNew<FunctionTemplate>(CreateSsl)->GetFunction());
+ ctr->Set(NanNew("createComposite"),
+ NanNew<FunctionTemplate>(CreateComposite)->GetFunction());
+ ctr->Set(NanNew("createGce"),
+ NanNew<FunctionTemplate>(CreateGce)->GetFunction());
+ ctr->Set(NanNew("createFake"),
+ NanNew<FunctionTemplate>(CreateFake)->GetFunction());
+ ctr->Set(NanNew("createIam"),
+ NanNew<FunctionTemplate>(CreateIam)->GetFunction());
+ constructor = new NanCallback(ctr);
+ exports->Set(NanNew("Credentials"), ctr);
}
bool Credentials::HasInstance(Handle<Value> val) {
@@ -100,8 +99,8 @@ Handle<Value> Credentials::WrapStruct(grpc_credentials *credentials) {
}
const int argc = 1;
Handle<Value> argv[argc] = {
- External::New(reinterpret_cast<void *>(credentials))};
- return NanEscapeScope(constructor->NewInstance(argc, argv));
+ NanNew<External>(reinterpret_cast<void *>(credentials))};
+ return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv));
}
grpc_credentials *Credentials::GetWrappedCredentials() {
@@ -116,15 +115,16 @@ NAN_METHOD(Credentials::New) {
return NanThrowTypeError(
"Credentials can only be created with the provided functions");
}
+ Handle<External> ext = args[0].As<External>();
grpc_credentials *creds_value =
- reinterpret_cast<grpc_credentials *>(External::Unwrap(args[0]));
+ reinterpret_cast<grpc_credentials *>(ext->Value());
Credentials *credentials = new Credentials(creds_value);
credentials->Wrap(args.This());
NanReturnValue(args.This());
} else {
const int argc = 1;
Local<Value> argv[argc] = {args[0]};
- NanReturnValue(constructor->NewInstance(argc, argv));
+ NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
}
}
@@ -137,19 +137,19 @@ NAN_METHOD(Credentials::CreateSsl) {
NanScope();
char *root_certs = NULL;
grpc_ssl_pem_key_cert_pair key_cert_pair = {NULL, NULL};
- if (Buffer::HasInstance(args[0])) {
- root_certs = Buffer::Data(args[0]);
+ if (::node::Buffer::HasInstance(args[0])) {
+ root_certs = ::node::Buffer::Data(args[0]);
} else if (!(args[0]->IsNull() || args[0]->IsUndefined())) {
return NanThrowTypeError("createSsl's first argument must be a Buffer");
}
- if (Buffer::HasInstance(args[1])) {
- key_cert_pair.private_key = Buffer::Data(args[1]);
+ if (::node::Buffer::HasInstance(args[1])) {
+ key_cert_pair.private_key = ::node::Buffer::Data(args[1]);
} else if (!(args[1]->IsNull() || args[1]->IsUndefined())) {
return NanThrowTypeError(
"createSSl's second argument must be a Buffer if provided");
}
- if (Buffer::HasInstance(args[2])) {
- key_cert_pair.cert_chain = Buffer::Data(args[2]);
+ if (::node::Buffer::HasInstance(args[2])) {
+ key_cert_pair.cert_chain = ::node::Buffer::Data(args[2]);
} else if (!(args[2]->IsNull() || args[2]->IsUndefined())) {
return NanThrowTypeError(
"createSSl's third argument must be a Buffer if provided");
diff --git a/src/node/ext/credentials.h b/src/node/ext/credentials.h
index e60be3d4e1..794736fe1a 100644
--- a/src/node/ext/credentials.h
+++ b/src/node/ext/credentials.h
@@ -68,7 +68,7 @@ class Credentials : public ::node::ObjectWrap {
static NAN_METHOD(CreateGce);
static NAN_METHOD(CreateFake);
static NAN_METHOD(CreateIam);
- static v8::Persistent<v8::Function> constructor;
+ static NanCallback *constructor;
// Used for typechecking instances of this javascript class
static v8::Persistent<v8::FunctionTemplate> fun_tpl;
diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc
index 9f5095839c..4e31cbaa27 100644
--- a/src/node/ext/node_grpc.cc
+++ b/src/node/ext/node_grpc.cc
@@ -51,7 +51,7 @@ using v8::String;
void InitStatusConstants(Handle<Object> exports) {
NanScope();
- Handle<Object> status = Object::New();
+ Handle<Object> status = NanNew<Object>();
exports->Set(NanNew("status"), status);
Handle<Value> OK(NanNew<Uint32, uint32_t>(GRPC_STATUS_OK));
status->Set(NanNew("OK"), OK);
@@ -100,7 +100,7 @@ void InitStatusConstants(Handle<Object> exports) {
void InitCallErrorConstants(Handle<Object> exports) {
NanScope();
- Handle<Object> call_error = Object::New();
+ Handle<Object> call_error = NanNew<Object>();
exports->Set(NanNew("callError"), call_error);
Handle<Value> OK(NanNew<Uint32, uint32_t>(GRPC_CALL_OK));
call_error->Set(NanNew("OK"), OK);
@@ -131,7 +131,7 @@ void InitCallErrorConstants(Handle<Object> exports) {
void InitOpTypeConstants(Handle<Object> exports) {
NanScope();
- Handle<Object> op_type = Object::New();
+ Handle<Object> op_type = NanNew<Object>();
exports->Set(NanNew("opType"), op_type);
Handle<Value> SEND_INITIAL_METADATA(
NanNew<Uint32, uint32_t>(GRPC_OP_SEND_INITIAL_METADATA));
diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc
index a87f9194e9..e47bac833b 100644
--- a/src/node/ext/server.cc
+++ b/src/node/ext/server.cc
@@ -53,7 +53,6 @@ namespace grpc {
namespace node {
using std::unique_ptr;
-using v8::Arguments;
using v8::Array;
using v8::Boolean;
using v8::Date;
@@ -69,7 +68,7 @@ using v8::Persistent;
using v8::String;
using v8::Value;
-Persistent<Function> Server::constructor;
+NanCallback *Server::constructor;
Persistent<FunctionTemplate> Server::fun_tpl;
class NewCallOp : public Op {
@@ -121,28 +120,30 @@ Server::~Server() { grpc_server_destroy(wrapped_server); }
void Server::Init(Handle<Object> exports) {
NanScope();
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
- tpl->SetClassName(String::NewSymbol("Server"));
+ Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
+ tpl->SetClassName(NanNew("Server"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NanSetPrototypeTemplate(tpl, "requestCall",
- FunctionTemplate::New(RequestCall)->GetFunction());
+ NanNew<FunctionTemplate>(RequestCall)->GetFunction());
- NanSetPrototypeTemplate(tpl, "addHttp2Port",
- FunctionTemplate::New(AddHttp2Port)->GetFunction());
+ NanSetPrototypeTemplate(
+ tpl, "addHttp2Port",
+ NanNew<FunctionTemplate>(AddHttp2Port)->GetFunction());
NanSetPrototypeTemplate(
tpl, "addSecureHttp2Port",
- FunctionTemplate::New(AddSecureHttp2Port)->GetFunction());
+ NanNew<FunctionTemplate>(AddSecureHttp2Port)->GetFunction());
NanSetPrototypeTemplate(tpl, "start",
- FunctionTemplate::New(Start)->GetFunction());
+ NanNew<FunctionTemplate>(Start)->GetFunction());
NanSetPrototypeTemplate(tpl, "shutdown",
- FunctionTemplate::New(Shutdown)->GetFunction());
+ NanNew<FunctionTemplate>(Shutdown)->GetFunction());
NanAssignPersistent(fun_tpl, tpl);
- NanAssignPersistent(constructor, tpl->GetFunction());
- exports->Set(String::NewSymbol("Server"), constructor);
+ Handle<Function> ctr = tpl->GetFunction();
+ constructor = new NanCallback(ctr);
+ exports->Set(NanNew("Server"), ctr);
}
bool Server::HasInstance(Handle<Value> val) {
@@ -157,7 +158,7 @@ NAN_METHOD(Server::New) {
if (!args.IsConstructCall()) {
const int argc = 1;
Local<Value> argv[argc] = {args[0]};
- NanReturnValue(constructor->NewInstance(argc, argv));
+ NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
}
grpc_server *wrapped_server;
grpc_completion_queue *queue = CompletionQueueAsyncWorker::GetQueue();
diff --git a/src/node/ext/server.h b/src/node/ext/server.h
index 2056fe7d3f..641d5ccb3e 100644
--- a/src/node/ext/server.h
+++ b/src/node/ext/server.h
@@ -67,7 +67,7 @@ class Server : public ::node::ObjectWrap {
static NAN_METHOD(AddSecureHttp2Port);
static NAN_METHOD(Start);
static NAN_METHOD(Shutdown);
- static v8::Persistent<v8::Function> constructor;
+ static NanCallback *constructor;
static v8::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_server *wrapped_server;
diff --git a/src/node/ext/server_credentials.cc b/src/node/ext/server_credentials.cc
index f75a2bf79c..d2b63cdc4e 100644
--- a/src/node/ext/server_credentials.cc
+++ b/src/node/ext/server_credentials.cc
@@ -41,8 +41,6 @@
namespace grpc {
namespace node {
-using ::node::Buffer;
-using v8::Arguments;
using v8::Exception;
using v8::External;
using v8::Function;
@@ -56,7 +54,7 @@ using v8::ObjectTemplate;
using v8::Persistent;
using v8::Value;
-Persistent<Function> ServerCredentials::constructor;
+NanCallback *ServerCredentials::constructor;
Persistent<FunctionTemplate> ServerCredentials::fun_tpl;
ServerCredentials::ServerCredentials(grpc_server_credentials *credentials)
@@ -68,16 +66,17 @@ ServerCredentials::~ServerCredentials() {
void ServerCredentials::Init(Handle<Object> exports) {
NanScope();
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
tpl->SetClassName(NanNew("ServerCredentials"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NanAssignPersistent(fun_tpl, tpl);
- NanAssignPersistent(constructor, tpl->GetFunction());
- constructor->Set(NanNew("createSsl"),
- FunctionTemplate::New(CreateSsl)->GetFunction());
- constructor->Set(NanNew("createFake"),
- FunctionTemplate::New(CreateFake)->GetFunction());
- exports->Set(NanNew("ServerCredentials"), constructor);
+ Handle<Function> ctr = tpl->GetFunction();
+ ctr->Set(NanNew("createSsl"),
+ NanNew<FunctionTemplate>(CreateSsl)->GetFunction());
+ ctr->Set(NanNew("createFake"),
+ NanNew<FunctionTemplate>(CreateFake)->GetFunction());
+ constructor = new NanCallback(ctr);
+ exports->Set(NanNew("ServerCredentials"), ctr);
}
bool ServerCredentials::HasInstance(Handle<Value> val) {
@@ -93,8 +92,8 @@ Handle<Value> ServerCredentials::WrapStruct(
}
const int argc = 1;
Handle<Value> argv[argc] = {
- External::New(reinterpret_cast<void *>(credentials))};
- return NanEscapeScope(constructor->NewInstance(argc, argv));
+ NanNew<External>(reinterpret_cast<void *>(credentials))};
+ return NanEscapeScope(constructor->GetFunction()->NewInstance(argc, argv));
}
grpc_server_credentials *ServerCredentials::GetWrappedServerCredentials() {
@@ -109,15 +108,16 @@ NAN_METHOD(ServerCredentials::New) {
return NanThrowTypeError(
"ServerCredentials can only be created with the provide functions");
}
+ Handle<External> ext = args[0].As<External>();
grpc_server_credentials *creds_value =
- reinterpret_cast<grpc_server_credentials *>(External::Unwrap(args[0]));
+ reinterpret_cast<grpc_server_credentials *>(ext->Value());
ServerCredentials *credentials = new ServerCredentials(creds_value);
credentials->Wrap(args.This());
NanReturnValue(args.This());
} else {
const int argc = 1;
Local<Value> argv[argc] = {args[0]};
- NanReturnValue(constructor->NewInstance(argc, argv));
+ NanReturnValue(constructor->GetFunction()->NewInstance(argc, argv));
}
}
@@ -126,20 +126,20 @@ NAN_METHOD(ServerCredentials::CreateSsl) {
NanScope();
char *root_certs = NULL;
grpc_ssl_pem_key_cert_pair key_cert_pair;
- if (Buffer::HasInstance(args[0])) {
- root_certs = Buffer::Data(args[0]);
+ if (::node::Buffer::HasInstance(args[0])) {
+ root_certs = ::node::Buffer::Data(args[0]);
} else if (!(args[0]->IsNull() || args[0]->IsUndefined())) {
return NanThrowTypeError(
"createSSl's first argument must be a Buffer if provided");
}
- if (!Buffer::HasInstance(args[1])) {
+ if (!::node::Buffer::HasInstance(args[1])) {
return NanThrowTypeError("createSsl's second argument must be a Buffer");
}
- key_cert_pair.private_key = Buffer::Data(args[1]);
- if (!Buffer::HasInstance(args[2])) {
+ key_cert_pair.private_key = ::node::Buffer::Data(args[1]);
+ if (!::node::Buffer::HasInstance(args[2])) {
return NanThrowTypeError("createSsl's third argument must be a Buffer");
}
- key_cert_pair.cert_chain = Buffer::Data(args[2]);
+ key_cert_pair.cert_chain = ::node::Buffer::Data(args[2]);
NanReturnValue(WrapStruct(
grpc_ssl_server_credentials_create(root_certs, &key_cert_pair, 1)));
}
diff --git a/src/node/ext/server_credentials.h b/src/node/ext/server_credentials.h
index f09902420c..aaa7ef297a 100644
--- a/src/node/ext/server_credentials.h
+++ b/src/node/ext/server_credentials.h
@@ -64,7 +64,7 @@ class ServerCredentials : public ::node::ObjectWrap {
static NAN_METHOD(New);
static NAN_METHOD(CreateSsl);
static NAN_METHOD(CreateFake);
- static v8::Persistent<v8::Function> constructor;
+ static NanCallback *constructor;
// Used for typechecking instances of this javascript class
static v8::Persistent<v8::FunctionTemplate> fun_tpl;
diff --git a/src/node/package.json b/src/node/package.json
index 0ef1c990b1..20eb21fc47 100644
--- a/src/node/package.json
+++ b/src/node/package.json
@@ -1,6 +1,6 @@
{
"name": "grpc",
- "version": "0.5.1",
+ "version": "0.5.2",
"author": "Google Inc.",
"description": "gRPC Library for Node",
"homepage": "http://www.grpc.io/",
@@ -24,20 +24,23 @@
"test": "node ./node_modules/mocha/bin/mocha && npm run-script lint"
},
"dependencies": {
- "bindings": "^1.2.1",
- "jshint": "^2.5.5",
- "nan": "~1.3.0",
+ "bindings": "^1.2.0",
+ "nan": "^1.5.0",
"protobufjs": "murgatroid99/ProtoBuf.js",
- "underscore": "^1.7.0",
+ "underscore": "^1.6.0",
"underscore.string": "^3.0.0"
},
"devDependencies": {
"async": "^0.9.0",
"google-auth-library": "^0.9.2",
+ "jshint": "^2.5.0",
"minimist": "^1.1.0",
"mocha": "~1.21.0",
"strftime": "^0.8.2"
},
+ "engines": {
+ "node": ">=0.10.13"
+ },
"files": [
"LICENSE",
"README.md",
diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb
index 483a31f60c..f15f85bf56 100644
--- a/src/ruby/ext/grpc/extconf.rb
+++ b/src/ruby/ext/grpc/extconf.rb
@@ -77,7 +77,6 @@ end
dir_config('grpc', HEADER_DIRS, LIB_DIRS)
-$CFLAGS << ' -std=c89 '
$CFLAGS << ' -Wno-implicit-function-declaration '
$CFLAGS << ' -Wno-pointer-sign '
$CFLAGS << ' -Wno-return-type '
diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c
index c7671c8a77..400efd0dfa 100644
--- a/src/ruby/ext/grpc/rb_grpc.c
+++ b/src/ruby/ext/grpc/rb_grpc.c
@@ -119,12 +119,12 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
break;
case T_FLOAT:
- if (interval && RFLOAT(time)->float_value < 0.0)
+ if (interval && RFLOAT_VALUE(time) < 0.0)
rb_raise(rb_eArgError, "%s must be positive", tstr);
else {
double f, d;
- d = modf(RFLOAT(time)->float_value, &f);
+ d = modf(RFLOAT_VALUE(time), &f);
if (d < 0) {
d += 1;
f -= 1;
@@ -132,7 +132,7 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
t.tv_sec = (time_t)f;
if (f != t.tv_sec) {
rb_raise(rb_eRangeError, "%f out of Time range",
- RFLOAT(time)->float_value);
+ RFLOAT_VALUE(time));
}
t.tv_nsec = (time_t)(d * 1e9 + 0.5);
}