|
|
@ -67,12 +67,9 @@ using v8::Value; |
|
|
|
Persistent<Function> Call::constructor; |
|
|
|
Persistent<Function> Call::constructor; |
|
|
|
Persistent<FunctionTemplate> Call::fun_tpl; |
|
|
|
Persistent<FunctionTemplate> Call::fun_tpl; |
|
|
|
|
|
|
|
|
|
|
|
Call::Call(grpc_call *call) : wrapped_call(call) { |
|
|
|
Call::Call(grpc_call *call) : wrapped_call(call) {} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Call::~Call() { |
|
|
|
Call::~Call() { grpc_call_destroy(wrapped_call); } |
|
|
|
grpc_call_destroy(wrapped_call); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Call::Init(Handle<Object> exports) { |
|
|
|
void Call::Init(Handle<Object> exports) { |
|
|
|
NanScope(); |
|
|
|
NanScope(); |
|
|
@ -86,8 +83,7 @@ void Call::Init(Handle<Object> exports) { |
|
|
|
NanSetPrototypeTemplate(tpl, "serverAccept", |
|
|
|
NanSetPrototypeTemplate(tpl, "serverAccept", |
|
|
|
FunctionTemplate::New(ServerAccept)->GetFunction()); |
|
|
|
FunctionTemplate::New(ServerAccept)->GetFunction()); |
|
|
|
NanSetPrototypeTemplate( |
|
|
|
NanSetPrototypeTemplate( |
|
|
|
tpl, |
|
|
|
tpl, "serverEndInitialMetadata", |
|
|
|
"serverEndInitialMetadata", |
|
|
|
|
|
|
|
FunctionTemplate::New(ServerEndInitialMetadata)->GetFunction()); |
|
|
|
FunctionTemplate::New(ServerEndInitialMetadata)->GetFunction()); |
|
|
|
NanSetPrototypeTemplate(tpl, "cancel", |
|
|
|
NanSetPrototypeTemplate(tpl, "cancel", |
|
|
|
FunctionTemplate::New(Cancel)->GetFunction()); |
|
|
|
FunctionTemplate::New(Cancel)->GetFunction()); |
|
|
@ -122,7 +118,7 @@ Handle<Value> Call::WrapStruct(grpc_call *call) { |
|
|
|
return NanEscapeScope(NanNull()); |
|
|
|
return NanEscapeScope(NanNull()); |
|
|
|
} |
|
|
|
} |
|
|
|
const int argc = 1; |
|
|
|
const int argc = 1; |
|
|
|
Handle<Value> argv[argc] = { External::New(reinterpret_cast<void*>(call)) }; |
|
|
|
Handle<Value> argv[argc] = {External::New(reinterpret_cast<void *>(call))}; |
|
|
|
return NanEscapeScope(constructor->NewInstance(argc, argv)); |
|
|
|
return NanEscapeScope(constructor->NewInstance(argc, argv)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -133,8 +129,8 @@ NAN_METHOD(Call::New) { |
|
|
|
Call *call; |
|
|
|
Call *call; |
|
|
|
if (args[0]->IsExternal()) { |
|
|
|
if (args[0]->IsExternal()) { |
|
|
|
// This option is used for wrapping an existing call
|
|
|
|
// This option is used for wrapping an existing call
|
|
|
|
grpc_call *call_value = reinterpret_cast<grpc_call*>( |
|
|
|
grpc_call *call_value = |
|
|
|
External::Unwrap(args[0])); |
|
|
|
reinterpret_cast<grpc_call *>(External::Unwrap(args[0])); |
|
|
|
call = new Call(call_value); |
|
|
|
call = new Call(call_value); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (!Channel::HasInstance(args[0])) { |
|
|
|
if (!Channel::HasInstance(args[0])) { |
|
|
@ -155,11 +151,9 @@ NAN_METHOD(Call::New) { |
|
|
|
NanUtf8String method(args[1]); |
|
|
|
NanUtf8String method(args[1]); |
|
|
|
double deadline = args[2]->NumberValue(); |
|
|
|
double deadline = args[2]->NumberValue(); |
|
|
|
grpc_channel *wrapped_channel = channel->GetWrappedChannel(); |
|
|
|
grpc_channel *wrapped_channel = channel->GetWrappedChannel(); |
|
|
|
grpc_call *wrapped_call = grpc_channel_create_call( |
|
|
|
grpc_call *wrapped_call = |
|
|
|
wrapped_channel, |
|
|
|
grpc_channel_create_call(wrapped_channel, *method, channel->GetHost(), |
|
|
|
*method, |
|
|
|
MillisecondsToTimespec(deadline)); |
|
|
|
channel->GetHost(), |
|
|
|
|
|
|
|
MillisecondsToTimespec(deadline)); |
|
|
|
|
|
|
|
call = new Call(wrapped_call); |
|
|
|
call = new Call(wrapped_call); |
|
|
|
args.This()->SetHiddenValue(String::NewSymbol("channel_"), |
|
|
|
args.This()->SetHiddenValue(String::NewSymbol("channel_"), |
|
|
|
channel_object); |
|
|
|
channel_object); |
|
|
@ -168,7 +162,7 @@ NAN_METHOD(Call::New) { |
|
|
|
NanReturnValue(args.This()); |
|
|
|
NanReturnValue(args.This()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const int argc = 4; |
|
|
|
const int argc = 4; |
|
|
|
Local<Value> argv[argc] = { args[0], args[1], args[2], args[3] }; |
|
|
|
Local<Value> argv[argc] = {args[0], args[1], args[2], args[3]}; |
|
|
|
NanReturnValue(constructor->NewInstance(argc, argv)); |
|
|
|
NanReturnValue(constructor->NewInstance(argc, argv)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -176,11 +170,10 @@ NAN_METHOD(Call::New) { |
|
|
|
NAN_METHOD(Call::AddMetadata) { |
|
|
|
NAN_METHOD(Call::AddMetadata) { |
|
|
|
NanScope(); |
|
|
|
NanScope(); |
|
|
|
if (!HasInstance(args.This())) { |
|
|
|
if (!HasInstance(args.This())) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError("addMetadata can only be called on Call objects"); |
|
|
|
"addMetadata can only be called on Call objects"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
for (int i=0; !args[i]->IsUndefined(); i++) { |
|
|
|
for (int i = 0; !args[i]->IsUndefined(); i++) { |
|
|
|
if (!args[i]->IsObject()) { |
|
|
|
if (!args[i]->IsObject()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError( |
|
|
|
"addMetadata arguments must be objects with key and value"); |
|
|
|
"addMetadata arguments must be objects with key and value"); |
|
|
@ -201,9 +194,8 @@ NAN_METHOD(Call::AddMetadata) { |
|
|
|
metadata.key = *utf8_key; |
|
|
|
metadata.key = *utf8_key; |
|
|
|
metadata.value = Buffer::Data(value); |
|
|
|
metadata.value = Buffer::Data(value); |
|
|
|
metadata.value_length = Buffer::Length(value); |
|
|
|
metadata.value_length = Buffer::Length(value); |
|
|
|
grpc_call_error error = grpc_call_add_metadata(call->wrapped_call, |
|
|
|
grpc_call_error error = |
|
|
|
&metadata, |
|
|
|
grpc_call_add_metadata(call->wrapped_call, &metadata, 0); |
|
|
|
0); |
|
|
|
|
|
|
|
if (error != GRPC_CALL_OK) { |
|
|
|
if (error != GRPC_CALL_OK) { |
|
|
|
return NanThrowError("addMetadata failed", error); |
|
|
|
return NanThrowError("addMetadata failed", error); |
|
|
|
} |
|
|
|
} |
|
|
@ -217,16 +209,14 @@ NAN_METHOD(Call::StartInvoke) { |
|
|
|
return NanThrowTypeError("startInvoke can only be called on Call objects"); |
|
|
|
return NanThrowTypeError("startInvoke can only be called on Call objects"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[0]->IsFunction()) { |
|
|
|
if (!args[0]->IsFunction()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError("StartInvoke's first argument must be a function"); |
|
|
|
"StartInvoke's first argument must be a function"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[1]->IsFunction()) { |
|
|
|
if (!args[1]->IsFunction()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError( |
|
|
|
"StartInvoke's second argument must be a function"); |
|
|
|
"StartInvoke's second argument must be a function"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[2]->IsFunction()) { |
|
|
|
if (!args[2]->IsFunction()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError("StartInvoke's third argument must be a function"); |
|
|
|
"StartInvoke's third argument must be a function"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[3]->IsUint32()) { |
|
|
|
if (!args[3]->IsUint32()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError( |
|
|
@ -235,12 +225,9 @@ NAN_METHOD(Call::StartInvoke) { |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
unsigned int flags = args[3]->Uint32Value(); |
|
|
|
unsigned int flags = args[3]->Uint32Value(); |
|
|
|
grpc_call_error error = grpc_call_start_invoke( |
|
|
|
grpc_call_error error = grpc_call_start_invoke( |
|
|
|
call->wrapped_call, |
|
|
|
call->wrapped_call, CompletionQueueAsyncWorker::GetQueue(), |
|
|
|
CompletionQueueAsyncWorker::GetQueue(), |
|
|
|
CreateTag(args[0], args.This()), CreateTag(args[1], args.This()), |
|
|
|
CreateTag(args[0], args.This()), |
|
|
|
CreateTag(args[2], args.This()), flags); |
|
|
|
CreateTag(args[1], args.This()), |
|
|
|
|
|
|
|
CreateTag(args[2], args.This()), |
|
|
|
|
|
|
|
flags); |
|
|
|
|
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
@ -257,13 +244,11 @@ NAN_METHOD(Call::ServerAccept) { |
|
|
|
return NanThrowTypeError("accept can only be called on Call objects"); |
|
|
|
return NanThrowTypeError("accept can only be called on Call objects"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[0]->IsFunction()) { |
|
|
|
if (!args[0]->IsFunction()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError("accept's first argument must be a function"); |
|
|
|
"accept's first argument must be a function"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
grpc_call_error error = grpc_call_server_accept( |
|
|
|
grpc_call_error error = grpc_call_server_accept( |
|
|
|
call->wrapped_call, |
|
|
|
call->wrapped_call, CompletionQueueAsyncWorker::GetQueue(), |
|
|
|
CompletionQueueAsyncWorker::GetQueue(), |
|
|
|
|
|
|
|
CreateTag(args[0], args.This())); |
|
|
|
CreateTag(args[0], args.This())); |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
@ -285,9 +270,8 @@ NAN_METHOD(Call::ServerEndInitialMetadata) { |
|
|
|
} |
|
|
|
} |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
unsigned int flags = args[1]->Uint32Value(); |
|
|
|
unsigned int flags = args[1]->Uint32Value(); |
|
|
|
grpc_call_error error = grpc_call_server_end_initial_metadata( |
|
|
|
grpc_call_error error = |
|
|
|
call->wrapped_call, |
|
|
|
grpc_call_server_end_initial_metadata(call->wrapped_call, flags); |
|
|
|
flags); |
|
|
|
|
|
|
|
if (error != GRPC_CALL_OK) { |
|
|
|
if (error != GRPC_CALL_OK) { |
|
|
|
return NanThrowError("serverEndInitialMetadata failed", error); |
|
|
|
return NanThrowError("serverEndInitialMetadata failed", error); |
|
|
|
} |
|
|
|
} |
|
|
@ -313,12 +297,10 @@ NAN_METHOD(Call::StartWrite) { |
|
|
|
return NanThrowTypeError("startWrite can only be called on Call objects"); |
|
|
|
return NanThrowTypeError("startWrite can only be called on Call objects"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!Buffer::HasInstance(args[0])) { |
|
|
|
if (!Buffer::HasInstance(args[0])) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError("startWrite's first argument must be a Buffer"); |
|
|
|
"startWrite's first argument must be a Buffer"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[1]->IsFunction()) { |
|
|
|
if (!args[1]->IsFunction()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError("startWrite's second argument must be a function"); |
|
|
|
"startWrite's second argument must be a function"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[2]->IsUint32()) { |
|
|
|
if (!args[2]->IsUint32()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError( |
|
|
@ -327,10 +309,8 @@ NAN_METHOD(Call::StartWrite) { |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
grpc_byte_buffer *buffer = BufferToByteBuffer(args[0]); |
|
|
|
grpc_byte_buffer *buffer = BufferToByteBuffer(args[0]); |
|
|
|
unsigned int flags = args[2]->Uint32Value(); |
|
|
|
unsigned int flags = args[2]->Uint32Value(); |
|
|
|
grpc_call_error error = grpc_call_start_write(call->wrapped_call, |
|
|
|
grpc_call_error error = grpc_call_start_write( |
|
|
|
buffer, |
|
|
|
call->wrapped_call, buffer, CreateTag(args[1], args.This()), flags); |
|
|
|
CreateTag(args[1], args.This()), |
|
|
|
|
|
|
|
flags); |
|
|
|
|
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -360,9 +340,7 @@ NAN_METHOD(Call::StartWriteStatus) { |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
NanUtf8String details(args[1]); |
|
|
|
NanUtf8String details(args[1]); |
|
|
|
grpc_call_error error = grpc_call_start_write_status( |
|
|
|
grpc_call_error error = grpc_call_start_write_status( |
|
|
|
call->wrapped_call, |
|
|
|
call->wrapped_call, (grpc_status_code)args[0]->Uint32Value(), *details, |
|
|
|
(grpc_status_code)args[0]->Uint32Value(), |
|
|
|
|
|
|
|
*details, |
|
|
|
|
|
|
|
CreateTag(args[2], args.This())); |
|
|
|
CreateTag(args[2], args.This())); |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
@ -378,13 +356,11 @@ NAN_METHOD(Call::WritesDone) { |
|
|
|
return NanThrowTypeError("writesDone can only be called on Call objects"); |
|
|
|
return NanThrowTypeError("writesDone can only be called on Call objects"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[0]->IsFunction()) { |
|
|
|
if (!args[0]->IsFunction()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError("writesDone's first argument must be a function"); |
|
|
|
"writesDone's first argument must be a function"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
grpc_call_error error = grpc_call_writes_done( |
|
|
|
grpc_call_error error = grpc_call_writes_done( |
|
|
|
call->wrapped_call, |
|
|
|
call->wrapped_call, CreateTag(args[0], args.This())); |
|
|
|
CreateTag(args[0], args.This())); |
|
|
|
|
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -399,12 +375,11 @@ NAN_METHOD(Call::StartRead) { |
|
|
|
return NanThrowTypeError("startRead can only be called on Call objects"); |
|
|
|
return NanThrowTypeError("startRead can only be called on Call objects"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!args[0]->IsFunction()) { |
|
|
|
if (!args[0]->IsFunction()) { |
|
|
|
return NanThrowTypeError( |
|
|
|
return NanThrowTypeError("startRead's first argument must be a function"); |
|
|
|
"startRead's first argument must be a function"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
Call *call = ObjectWrap::Unwrap<Call>(args.This()); |
|
|
|
grpc_call_error error = grpc_call_start_read(call->wrapped_call, |
|
|
|
grpc_call_error error = |
|
|
|
CreateTag(args[0], args.This())); |
|
|
|
grpc_call_start_read(call->wrapped_call, CreateTag(args[0], args.This())); |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
if (error == GRPC_CALL_OK) { |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
CompletionQueueAsyncWorker::Next(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|