diff options
author | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2015-07-24 13:25:44 -0700 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2015-07-24 13:25:44 -0700 |
commit | e8cdd54d6f43be0d1f4115a5ab240f31d6305a3d (patch) | |
tree | 6dd9f4343e8f8ec1e52c6d75ef8cd635e1be23e8 /src/node/ext | |
parent | 7e06b6ffe276f8ceaafc601b09e53971e5eead15 (diff) | |
parent | ea12b97243f95d1830a9f70c3c176b82ef37cb04 (diff) |
Merge pull request #2651 from murgatroid99/node_call_peer_address
Exposed channel target and call peer in Node wrapper
Diffstat (limited to 'src/node/ext')
-rw-r--r-- | src/node/ext/call.cc | 14 | ||||
-rw-r--r-- | src/node/ext/call.h | 1 | ||||
-rw-r--r-- | src/node/ext/channel.cc | 11 | ||||
-rw-r--r-- | src/node/ext/channel.h | 1 |
4 files changed, 27 insertions, 0 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 15c9b2d97d..b647735ead 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -453,6 +453,8 @@ void Call::Init(Handle<Object> exports) { NanNew<FunctionTemplate>(StartBatch)->GetFunction()); NanSetPrototypeTemplate(tpl, "cancel", NanNew<FunctionTemplate>(Cancel)->GetFunction()); + NanSetPrototypeTemplate(tpl, "getPeer", + NanNew<FunctionTemplate>(GetPeer)->GetFunction()); NanAssignPersistent(fun_tpl, tpl); Handle<Function> ctr = tpl->GetFunction(); ctr->Set(NanNew("WRITE_BUFFER_HINT"), @@ -608,5 +610,17 @@ NAN_METHOD(Call::Cancel) { NanReturnUndefined(); } +NAN_METHOD(Call::GetPeer) { + NanScope(); + if (!HasInstance(args.This())) { + return NanThrowTypeError("getPeer can only be called on Call objects"); + } + Call *call = ObjectWrap::Unwrap<Call>(args.This()); + char *peer = grpc_call_get_peer(call->wrapped_call); + Handle<Value> peer_value = NanNew(peer); + gpr_free(peer); + NanReturnValue(peer_value); +} + } // namespace node } // namespace grpc diff --git a/src/node/ext/call.h b/src/node/ext/call.h index 43142c7091..6acda76197 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -120,6 +120,7 @@ class Call : public ::node::ObjectWrap { static NAN_METHOD(New); static NAN_METHOD(StartBatch); static NAN_METHOD(Cancel); + static NAN_METHOD(GetPeer); 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 d37bf763dd..0b7333e450 100644 --- a/src/node/ext/channel.cc +++ b/src/node/ext/channel.cc @@ -76,6 +76,8 @@ void Channel::Init(Handle<Object> exports) { tpl->InstanceTemplate()->SetInternalFieldCount(1); NanSetPrototypeTemplate(tpl, "close", NanNew<FunctionTemplate>(Close)->GetFunction()); + NanSetPrototypeTemplate(tpl, "getTarget", + NanNew<FunctionTemplate>(GetTarget)->GetFunction()); NanAssignPersistent(fun_tpl, tpl); Handle<Function> ctr = tpl->GetFunction(); constructor = new NanCallback(ctr); @@ -185,5 +187,14 @@ NAN_METHOD(Channel::Close) { NanReturnUndefined(); } +NAN_METHOD(Channel::GetTarget) { + NanScope(); + if (!HasInstance(args.This())) { + return NanThrowTypeError("getTarget can only be called on Channel objects"); + } + Channel *channel = ObjectWrap::Unwrap<Channel>(args.This()); + NanReturnValue(NanNew(grpc_channel_get_target(channel->wrapped_channel))); +} + } // namespace node } // namespace grpc diff --git a/src/node/ext/channel.h b/src/node/ext/channel.h index b3aa0f700f..6725ebb03f 100644 --- a/src/node/ext/channel.h +++ b/src/node/ext/channel.h @@ -66,6 +66,7 @@ class Channel : public ::node::ObjectWrap { static NAN_METHOD(New); static NAN_METHOD(Close); + static NAN_METHOD(GetTarget); static NanCallback *constructor; static v8::Persistent<v8::FunctionTemplate> fun_tpl; |