aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-08-03 15:17:53 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-08-03 15:17:53 -0700
commit3f507d074c1f44494717282bf294764ff96e239d (patch)
tree7db2323e796c605273454c029cb40da7c91e3442 /src
parentbee7b68b54ae379b89424fd207dfa47ec68f87a7 (diff)
Exposed host parameter in Call constructor, don't save it in Channel object
Diffstat (limited to 'src')
-rw-r--r--src/node/ext/call.cc14
-rw-r--r--src/node/ext/channel.cc25
-rw-r--r--src/node/ext/channel.h6
3 files changed, 19 insertions, 26 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index dc45c8d8ae..ab177e8513 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -510,9 +510,19 @@ NAN_METHOD(Call::New) {
NanUtf8String method(args[1]);
double deadline = args[2]->NumberValue();
grpc_channel *wrapped_channel = channel->GetWrappedChannel();
- grpc_call *wrapped_call = grpc_channel_create_call(
+ grpc_call *wrapped_call;
+ if (args[3]->IsString()) {
+ NanUtf8String host_override(args[3]);
+ wrapped_call = grpc_channel_create_call(
wrapped_channel, CompletionQueueAsyncWorker::GetQueue(), *method,
- channel->GetHost(), MillisecondsToTimespec(deadline));
+ *host_override, MillisecondsToTimespec(deadline));
+ } else if (args[3]->IsUndefined() || args[3]->IsNull()) {
+ wrapped_call = grpc_channel_create_call(
+ wrapped_channel, CompletionQueueAsyncWorker::GetQueue(), *method,
+ NULL, MillisecondsToTimespec(deadline));
+ } else {
+ return NanThrowTypeError("Call's fourth argument must be a string");
+ }
call = new Call(wrapped_call);
args.This()->SetHiddenValue(NanNew("channel_"), channel_object);
}
diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc
index d02ed95672..457a58c057 100644
--- a/src/node/ext/channel.cc
+++ b/src/node/ext/channel.cc
@@ -59,14 +59,12 @@ using v8::Value;
NanCallback *Channel::constructor;
Persistent<FunctionTemplate> Channel::fun_tpl;
-Channel::Channel(grpc_channel *channel, NanUtf8String *host)
- : wrapped_channel(channel), host(host) {}
+Channel::Channel(grpc_channel *channel) : wrapped_channel(channel) {}
Channel::~Channel() {
if (wrapped_channel != NULL) {
grpc_channel_destroy(wrapped_channel);
}
- delete host;
}
void Channel::Init(Handle<Object> exports) {
@@ -91,8 +89,6 @@ bool Channel::HasInstance(Handle<Value> val) {
grpc_channel *Channel::GetWrappedChannel() { return this->wrapped_channel; }
-char *Channel::GetHost() { return **this->host; }
-
NAN_METHOD(Channel::New) {
NanScope();
@@ -103,8 +99,7 @@ NAN_METHOD(Channel::New) {
}
grpc_channel *wrapped_channel;
// Owned by the Channel object
- NanUtf8String *host = new NanUtf8String(args[0]);
- NanUtf8String *host_override = NULL;
+ NanUtf8String host(args[0]);
grpc_credentials *creds;
if (!Credentials::HasInstance(args[1])) {
return NanThrowTypeError(
@@ -116,12 +111,9 @@ NAN_METHOD(Channel::New) {
grpc_channel_args *channel_args_ptr;
if (args[2]->IsUndefined()) {
channel_args_ptr = NULL;
- wrapped_channel = grpc_insecure_channel_create(**host, NULL);
+ wrapped_channel = grpc_insecure_channel_create(*host, NULL);
} else if (args[2]->IsObject()) {
Handle<Object> args_hash(args[2]->ToObject()->Clone());
- if (args_hash->HasOwnProperty(NanNew(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG))) {
- host_override = new NanUtf8String(args_hash->Get(NanNew(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)));
- }
Handle<Array> keys(args_hash->GetOwnPropertyNames());
grpc_channel_args channel_args;
channel_args.num_args = keys->Length();
@@ -153,20 +145,15 @@ NAN_METHOD(Channel::New) {
return NanThrowTypeError("Channel expects a string and an object");
}
if (creds == NULL) {
- wrapped_channel = grpc_insecure_channel_create(**host, channel_args_ptr);
+ wrapped_channel = grpc_insecure_channel_create(*host, channel_args_ptr);
} else {
wrapped_channel =
- grpc_secure_channel_create(creds, **host, channel_args_ptr);
+ grpc_secure_channel_create(creds, *host, channel_args_ptr);
}
if (channel_args_ptr != NULL) {
free(channel_args_ptr->args);
}
- Channel *channel;
- if (host_override == NULL) {
- channel = new Channel(wrapped_channel, host);
- } else {
- channel = new Channel(wrapped_channel, host_override);
- }
+ Channel *channel = new Channel(wrapped_channel);
channel->Wrap(args.This());
NanReturnValue(args.This());
} else {
diff --git a/src/node/ext/channel.h b/src/node/ext/channel.h
index 6725ebb03f..e2182cb45c 100644
--- a/src/node/ext/channel.h
+++ b/src/node/ext/channel.h
@@ -53,11 +53,8 @@ class Channel : public ::node::ObjectWrap {
/* Returns the grpc_channel struct that this object wraps */
grpc_channel *GetWrappedChannel();
- /* Return the hostname that this channel connects to */
- char *GetHost();
-
private:
- explicit Channel(grpc_channel *channel, NanUtf8String *host);
+ explicit Channel(grpc_channel *channel);
~Channel();
// Prevent copying
@@ -71,7 +68,6 @@ class Channel : public ::node::ObjectWrap {
static v8::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_channel *wrapped_channel;
- NanUtf8String *host;
};
} // namespace node