Run clang-format against node

pull/17/head
Craig Tiller 10 years ago
parent a8185661f5
commit e8e304e27b
  1. 83
      src/node/call.cc
  2. 20
      src/node/channel.cc
  3. 16
      src/node/completion_queue_async_worker.cc
  4. 20
      src/node/credentials.cc
  5. 37
      src/node/event.cc
  6. 6
      src/node/node_grpc.cc
  7. 33
      src/node/server.cc
  8. 13
      src/node/server_credentials.cc
  9. 7
      src/node/tag.cc

@ -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());
@ -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,10 +151,8 @@ 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,
channel->GetHost(),
MillisecondsToTimespec(deadline)); MillisecondsToTimespec(deadline));
call = new Call(wrapped_call); call = new Call(wrapped_call);
args.This()->SetHiddenValue(String::NewSymbol("channel_"), args.This()->SetHiddenValue(String::NewSymbol("channel_"),
@ -176,8 +170,7 @@ 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++) {
@ -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 {

@ -63,8 +63,7 @@ Persistent<Function> Channel::constructor;
Persistent<FunctionTemplate> Channel::fun_tpl; Persistent<FunctionTemplate> Channel::fun_tpl;
Channel::Channel(grpc_channel *channel, NanUtf8String *host) Channel::Channel(grpc_channel *channel, NanUtf8String *host)
: wrapped_channel(channel), host(host) { : wrapped_channel(channel), host(host) {}
}
Channel::~Channel() { Channel::~Channel() {
if (wrapped_channel != NULL) { if (wrapped_channel != NULL) {
@ -90,13 +89,9 @@ bool Channel::HasInstance(Handle<Value> val) {
return NanHasInstance(fun_tpl, val); return NanHasInstance(fun_tpl, val);
} }
grpc_channel *Channel::GetWrappedChannel() { grpc_channel *Channel::GetWrappedChannel() { return this->wrapped_channel; }
return this->wrapped_channel;
}
char *Channel::GetHost() { char *Channel::GetHost() { return **this->host; }
return **this->host;
}
NAN_METHOD(Channel::New) { NAN_METHOD(Channel::New) {
NanScope(); NanScope();
@ -119,8 +114,8 @@ NAN_METHOD(Channel::New) {
return NanThrowTypeError( return NanThrowTypeError(
"credentials arg must be a Credentials object"); "credentials arg must be a Credentials object");
} }
Credentials *creds_object = ObjectWrap::Unwrap<Credentials>( Credentials *creds_object =
creds_value->ToObject()); ObjectWrap::Unwrap<Credentials>(creds_value->ToObject());
creds = creds_object->GetWrappedCredentials(); creds = creds_object->GetWrappedCredentials();
args_hash->Delete(NanNew("credentials")); args_hash->Delete(NanNew("credentials"));
} }
@ -153,9 +148,8 @@ NAN_METHOD(Channel::New) {
if (creds == NULL) { if (creds == NULL) {
wrapped_channel = grpc_channel_create(**host, &channel_args); wrapped_channel = grpc_channel_create(**host, &channel_args);
} else { } else {
wrapped_channel = grpc_secure_channel_create(creds, wrapped_channel =
**host, grpc_secure_channel_create(creds, **host, &channel_args);
&channel_args);
} }
free(channel_args.args); free(channel_args.args);
} else { } else {

@ -51,20 +51,16 @@ using v8::Value;
grpc_completion_queue *CompletionQueueAsyncWorker::queue; grpc_completion_queue *CompletionQueueAsyncWorker::queue;
CompletionQueueAsyncWorker::CompletionQueueAsyncWorker() : CompletionQueueAsyncWorker::CompletionQueueAsyncWorker()
NanAsyncWorker(NULL) { : NanAsyncWorker(NULL) {}
}
CompletionQueueAsyncWorker::~CompletionQueueAsyncWorker() { CompletionQueueAsyncWorker::~CompletionQueueAsyncWorker() {}
}
void CompletionQueueAsyncWorker::Execute() { void CompletionQueueAsyncWorker::Execute() {
result = grpc_completion_queue_next(queue, gpr_inf_future); result = grpc_completion_queue_next(queue, gpr_inf_future);
} }
grpc_completion_queue *CompletionQueueAsyncWorker::GetQueue() { grpc_completion_queue *CompletionQueueAsyncWorker::GetQueue() { return queue; }
return queue;
}
void CompletionQueueAsyncWorker::Next() { void CompletionQueueAsyncWorker::Next() {
NanScope(); NanScope();
@ -80,9 +76,7 @@ void CompletionQueueAsyncWorker::Init(Handle<Object> exports) {
void CompletionQueueAsyncWorker::HandleOKCallback() { void CompletionQueueAsyncWorker::HandleOKCallback() {
NanScope(); NanScope();
NanCallback event_callback(GetTagHandle(result->tag).As<Function>()); NanCallback event_callback(GetTagHandle(result->tag).As<Function>());
Handle<Value> argv[] = { Handle<Value> argv[] = {CreateEventObject(result)};
CreateEventObject(result)
};
DestroyTag(result->tag); DestroyTag(result->tag);
grpc_event_finish(result); grpc_event_finish(result);

@ -60,8 +60,7 @@ Persistent<Function> Credentials::constructor;
Persistent<FunctionTemplate> Credentials::fun_tpl; Persistent<FunctionTemplate> Credentials::fun_tpl;
Credentials::Credentials(grpc_credentials *credentials) Credentials::Credentials(grpc_credentials *credentials)
: wrapped_credentials(credentials) { : wrapped_credentials(credentials) {}
}
Credentials::~Credentials() { Credentials::~Credentials() {
gpr_log(GPR_DEBUG, "Destroying credentials object"); gpr_log(GPR_DEBUG, "Destroying credentials object");
@ -118,8 +117,8 @@ NAN_METHOD(Credentials::New) {
return NanThrowTypeError( return NanThrowTypeError(
"Credentials can only be created with the provided functions"); "Credentials can only be created with the provided functions");
} }
grpc_credentials *creds_value = reinterpret_cast<grpc_credentials*>( grpc_credentials *creds_value =
External::Unwrap(args[0])); reinterpret_cast<grpc_credentials *>(External::Unwrap(args[0]));
Credentials *credentials = new Credentials(creds_value); Credentials *credentials = new Credentials(creds_value);
credentials->Wrap(args.This()); credentials->Wrap(args.This());
NanReturnValue(args.This()); NanReturnValue(args.This());
@ -142,8 +141,7 @@ NAN_METHOD(Credentials::CreateSsl) {
char *cert_chain = NULL; char *cert_chain = NULL;
int root_certs_length, private_key_length = 0, cert_chain_length = 0; int root_certs_length, private_key_length = 0, cert_chain_length = 0;
if (!Buffer::HasInstance(args[0])) { if (!Buffer::HasInstance(args[0])) {
return NanThrowTypeError( return NanThrowTypeError("createSsl's first argument must be a Buffer");
"createSsl's first argument must be a Buffer");
} }
root_certs = Buffer::Data(args[0]); root_certs = Buffer::Data(args[0]);
root_certs_length = Buffer::Length(args[0]); root_certs_length = Buffer::Length(args[0]);
@ -196,17 +194,15 @@ NAN_METHOD(Credentials::CreateFake) {
NAN_METHOD(Credentials::CreateIam) { NAN_METHOD(Credentials::CreateIam) {
NanScope(); NanScope();
if (!args[0]->IsString()) { if (!args[0]->IsString()) {
return NanThrowTypeError( return NanThrowTypeError("createIam's first argument must be a string");
"createIam's first argument must be a string");
} }
if (!args[1]->IsString()) { if (!args[1]->IsString()) {
return NanThrowTypeError( return NanThrowTypeError("createIam's second argument must be a string");
"createIam's second argument must be a string");
} }
NanUtf8String auth_token(args[0]); NanUtf8String auth_token(args[0]);
NanUtf8String auth_selector(args[1]); NanUtf8String auth_selector(args[1]);
NanReturnValue(WrapStruct(grpc_iam_credentials_create(*auth_token, NanReturnValue(
*auth_selector))); WrapStruct(grpc_iam_credentials_create(*auth_token, *auth_selector)));
} }
} // namespace node } // namespace node

@ -77,20 +77,19 @@ Handle<Value> GetEventData(grpc_event *event) {
Handle<Object> item_obj = NanNew<Object>(); Handle<Object> item_obj = NanNew<Object>();
item_obj->Set(NanNew<String, const char *>("key"), item_obj->Set(NanNew<String, const char *>("key"),
NanNew<String, char *>(items[i].key)); NanNew<String, char *>(items[i].key));
item_obj->Set(NanNew<String, const char *>("value"), item_obj->Set(
NanNew<String, char *>( NanNew<String, const char *>("value"),
items[i].value, NanNew<String, char *>(items[i].value,
static_cast<int>(items[i].value_length))); static_cast<int>(items[i].value_length)));
metadata->Set(i, item_obj); metadata->Set(i, item_obj);
} }
return NanEscapeScope(metadata); return NanEscapeScope(metadata);
case GRPC_FINISHED: case GRPC_FINISHED:
status = NanNew<Object>(); status = NanNew<Object>();
status->Set(NanNew("code"), NanNew<Number>( status->Set(NanNew("code"), NanNew<Number>(event->data.finished.status));
event->data.finished.status));
if (event->data.finished.details != NULL) { if (event->data.finished.details != NULL) {
status->Set(NanNew("details"), String::New( status->Set(NanNew("details"),
event->data.finished.details)); String::New(event->data.finished.details));
} }
count = event->data.finished.metadata_count; count = event->data.finished.metadata_count;
items = event->data.finished.metadata_elements; items = event->data.finished.metadata_elements;
@ -99,9 +98,9 @@ Handle<Value> GetEventData(grpc_event *event) {
Handle<Object> item_obj = NanNew<Object>(); Handle<Object> item_obj = NanNew<Object>();
item_obj->Set(NanNew<String, const char *>("key"), item_obj->Set(NanNew<String, const char *>("key"),
NanNew<String, char *>(items[i].key)); NanNew<String, char *>(items[i].key));
item_obj->Set(NanNew<String, const char *>("value"), item_obj->Set(
NanNew<String, char *>( NanNew<String, const char *>("value"),
items[i].value, NanNew<String, char *>(items[i].value,
static_cast<int>(items[i].value_length))); static_cast<int>(items[i].value_length)));
metadata->Set(i, item_obj); metadata->Set(i, item_obj);
} }
@ -112,12 +111,12 @@ Handle<Value> GetEventData(grpc_event *event) {
if (event->data.server_rpc_new.method == NULL) { if (event->data.server_rpc_new.method == NULL) {
return NanEscapeScope(NanNull()); return NanEscapeScope(NanNull());
} }
rpc_new->Set(NanNew<String, const char *>("method"), rpc_new->Set(
NanNew<String, const char *>( NanNew<String, const char *>("method"),
event->data.server_rpc_new.method)); NanNew<String, const char *>(event->data.server_rpc_new.method));
rpc_new->Set(NanNew<String, const char *>("host"), rpc_new->Set(
NanNew<String, const char *>( NanNew<String, const char *>("host"),
event->data.server_rpc_new.host)); NanNew<String, const char *>(event->data.server_rpc_new.host));
rpc_new->Set(NanNew<String, const char *>("absolute_deadline"), rpc_new->Set(NanNew<String, const char *>("absolute_deadline"),
NanNew<Date>(TimespecToMilliseconds( NanNew<Date>(TimespecToMilliseconds(
event->data.server_rpc_new.deadline))); event->data.server_rpc_new.deadline)));
@ -128,9 +127,9 @@ Handle<Value> GetEventData(grpc_event *event) {
Handle<Object> item_obj = Object::New(); Handle<Object> item_obj = Object::New();
item_obj->Set(NanNew<String, const char *>("key"), item_obj->Set(NanNew<String, const char *>("key"),
NanNew<String, char *>(items[i].key)); NanNew<String, char *>(items[i].key));
item_obj->Set(NanNew<String, const char *>("value"), item_obj->Set(
NanNew<String, char *>( NanNew<String, const char *>("value"),
items[i].value, NanNew<String, char *>(items[i].value,
static_cast<int>(items[i].value_length))); static_cast<int>(items[i].value_length)));
metadata->Set(i, item_obj); metadata->Set(i, item_obj);
} }

@ -124,8 +124,7 @@ void InitCallErrorConstants(Handle<Object> exports) {
call_error->Set(NanNew("ALREADY_FINISHED"), ALREADY_FINISHED); call_error->Set(NanNew("ALREADY_FINISHED"), ALREADY_FINISHED);
Handle<Value> TOO_MANY_OPERATIONS( Handle<Value> TOO_MANY_OPERATIONS(
NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS)); NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS));
call_error->Set(NanNew("TOO_MANY_OPERATIONS"), call_error->Set(NanNew("TOO_MANY_OPERATIONS"), TOO_MANY_OPERATIONS);
TOO_MANY_OPERATIONS);
Handle<Value> INVALID_FLAGS( Handle<Value> INVALID_FLAGS(
NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_INVALID_FLAGS)); NanNew<Uint32, uint32_t>(GRPC_CALL_ERROR_INVALID_FLAGS));
call_error->Set(NanNew("INVALID_FLAGS"), INVALID_FLAGS); call_error->Set(NanNew("INVALID_FLAGS"), INVALID_FLAGS);
@ -157,8 +156,7 @@ void InitCompletionTypeConstants(Handle<Object> exports) {
completion_type->Set(NanNew("FINISH_ACCEPTED"), FINISH_ACCEPTED); completion_type->Set(NanNew("FINISH_ACCEPTED"), FINISH_ACCEPTED);
Handle<Value> CLIENT_METADATA_READ( Handle<Value> CLIENT_METADATA_READ(
NanNew<Uint32, uint32_t>(GRPC_CLIENT_METADATA_READ)); NanNew<Uint32, uint32_t>(GRPC_CLIENT_METADATA_READ));
completion_type->Set(NanNew("CLIENT_METADATA_READ"), completion_type->Set(NanNew("CLIENT_METADATA_READ"), CLIENT_METADATA_READ);
CLIENT_METADATA_READ);
Handle<Value> FINISHED(NanNew<Uint32, uint32_t>(GRPC_FINISHED)); Handle<Value> FINISHED(NanNew<Uint32, uint32_t>(GRPC_FINISHED));
completion_type->Set(NanNew("FINISHED"), FINISHED); completion_type->Set(NanNew("FINISHED"), FINISHED);
Handle<Value> SERVER_RPC_NEW(NanNew<Uint32, uint32_t>(GRPC_SERVER_RPC_NEW)); Handle<Value> SERVER_RPC_NEW(NanNew<Uint32, uint32_t>(GRPC_SERVER_RPC_NEW));

@ -67,12 +67,9 @@ using v8::Value;
Persistent<Function> Server::constructor; Persistent<Function> Server::constructor;
Persistent<FunctionTemplate> Server::fun_tpl; Persistent<FunctionTemplate> Server::fun_tpl;
Server::Server(grpc_server *server) : wrapped_server(server) { Server::Server(grpc_server *server) : wrapped_server(server) {}
}
Server::~Server() { Server::~Server() { grpc_server_destroy(wrapped_server); }
grpc_server_destroy(wrapped_server);
}
void Server::Init(Handle<Object> exports) { void Server::Init(Handle<Object> exports) {
NanScope(); NanScope();
@ -85,9 +82,9 @@ void Server::Init(Handle<Object> exports) {
NanSetPrototypeTemplate(tpl, "addHttp2Port", NanSetPrototypeTemplate(tpl, "addHttp2Port",
FunctionTemplate::New(AddHttp2Port)->GetFunction()); FunctionTemplate::New(AddHttp2Port)->GetFunction());
NanSetPrototypeTemplate(tpl, "addSecureHttp2Port", NanSetPrototypeTemplate(
FunctionTemplate::New( tpl, "addSecureHttp2Port",
AddSecureHttp2Port)->GetFunction()); FunctionTemplate::New(AddSecureHttp2Port)->GetFunction());
NanSetPrototypeTemplate(tpl, "start", NanSetPrototypeTemplate(tpl, "start",
FunctionTemplate::New(Start)->GetFunction()); FunctionTemplate::New(Start)->GetFunction());
@ -127,8 +124,8 @@ NAN_METHOD(Server::New) {
return NanThrowTypeError( return NanThrowTypeError(
"credentials arg must be a ServerCredentials object"); "credentials arg must be a ServerCredentials object");
} }
ServerCredentials *creds_object = ObjectWrap::Unwrap<ServerCredentials>( ServerCredentials *creds_object =
creds_value->ToObject()); ObjectWrap::Unwrap<ServerCredentials>(creds_value->ToObject());
creds = creds_object->GetWrappedServerCredentials(); creds = creds_object->GetWrappedServerCredentials();
args_hash->Delete(NanNew("credentials")); args_hash->Delete(NanNew("credentials"));
} }
@ -159,12 +156,9 @@ NAN_METHOD(Server::New) {
} }
} }
if (creds == NULL) { if (creds == NULL) {
wrapped_server = grpc_server_create(queue, wrapped_server = grpc_server_create(queue, &channel_args);
&channel_args);
} else { } else {
wrapped_server = grpc_secure_server_create(creds, wrapped_server = grpc_secure_server_create(creds, queue, &channel_args);
queue,
&channel_args);
} }
free(channel_args.args); free(channel_args.args);
} else { } else {
@ -182,8 +176,7 @@ NAN_METHOD(Server::RequestCall) {
} }
Server *server = ObjectWrap::Unwrap<Server>(args.This()); Server *server = ObjectWrap::Unwrap<Server>(args.This());
grpc_call_error error = grpc_server_request_call( grpc_call_error error = grpc_server_request_call(
server->wrapped_server, server->wrapped_server, CreateTag(args[0], NanNull()));
CreateTag(args[0], NanNull()));
if (error == GRPC_CALL_OK) { if (error == GRPC_CALL_OK) {
CompletionQueueAsyncWorker::Next(); CompletionQueueAsyncWorker::Next();
} else { } else {
@ -202,8 +195,7 @@ NAN_METHOD(Server::AddHttp2Port) {
} }
Server *server = ObjectWrap::Unwrap<Server>(args.This()); Server *server = ObjectWrap::Unwrap<Server>(args.This());
NanReturnValue(NanNew<Boolean>(grpc_server_add_http2_port( NanReturnValue(NanNew<Boolean>(grpc_server_add_http2_port(
server->wrapped_server, server->wrapped_server, *NanUtf8String(args[0]))));
*NanUtf8String(args[0]))));
} }
NAN_METHOD(Server::AddSecureHttp2Port) { NAN_METHOD(Server::AddSecureHttp2Port) {
@ -217,8 +209,7 @@ NAN_METHOD(Server::AddSecureHttp2Port) {
} }
Server *server = ObjectWrap::Unwrap<Server>(args.This()); Server *server = ObjectWrap::Unwrap<Server>(args.This());
NanReturnValue(NanNew<Boolean>(grpc_server_add_secure_http2_port( NanReturnValue(NanNew<Boolean>(grpc_server_add_secure_http2_port(
server->wrapped_server, server->wrapped_server, *NanUtf8String(args[0]))));
*NanUtf8String(args[0]))));
} }
NAN_METHOD(Server::Start) { NAN_METHOD(Server::Start) {

@ -60,8 +60,7 @@ Persistent<Function> ServerCredentials::constructor;
Persistent<FunctionTemplate> ServerCredentials::fun_tpl; Persistent<FunctionTemplate> ServerCredentials::fun_tpl;
ServerCredentials::ServerCredentials(grpc_server_credentials *credentials) ServerCredentials::ServerCredentials(grpc_server_credentials *credentials)
: wrapped_credentials(credentials) { : wrapped_credentials(credentials) {}
}
ServerCredentials::~ServerCredentials() { ServerCredentials::~ServerCredentials() {
gpr_log(GPR_DEBUG, "Destroying server credentials object"); gpr_log(GPR_DEBUG, "Destroying server credentials object");
@ -137,14 +136,12 @@ NAN_METHOD(ServerCredentials::CreateSsl) {
"createSSl's first argument must be a Buffer if provided"); "createSSl's first argument must be a Buffer if provided");
} }
if (!Buffer::HasInstance(args[1])) { if (!Buffer::HasInstance(args[1])) {
return NanThrowTypeError( return NanThrowTypeError("createSsl's second argument must be a Buffer");
"createSsl's second argument must be a Buffer");
} }
private_key = Buffer::Data(args[1]); private_key = Buffer::Data(args[1]);
private_key_length = Buffer::Length(args[1]); private_key_length = Buffer::Length(args[1]);
if (!Buffer::HasInstance(args[2])) { if (!Buffer::HasInstance(args[2])) {
return NanThrowTypeError( return NanThrowTypeError("createSsl's third argument must be a Buffer");
"createSsl's third argument must be a Buffer");
} }
cert_chain = Buffer::Data(args[2]); cert_chain = Buffer::Data(args[2]);
cert_chain_length = Buffer::Length(args[2]); cert_chain_length = Buffer::Length(args[2]);
@ -156,8 +153,8 @@ NAN_METHOD(ServerCredentials::CreateSsl) {
NAN_METHOD(ServerCredentials::CreateFake) { NAN_METHOD(ServerCredentials::CreateFake) {
NanScope(); NanScope();
NanReturnValue(WrapStruct( NanReturnValue(
grpc_fake_transport_security_server_credentials_create())); WrapStruct(grpc_fake_transport_security_server_credentials_create()));
} }
} // namespace node } // namespace node

@ -46,8 +46,7 @@ using v8::Value;
struct tag { struct tag {
tag(Persistent<Value> *tag, Persistent<Value> *call) tag(Persistent<Value> *tag, Persistent<Value> *call)
: persist_tag(tag), persist_call(call) { : persist_tag(tag), persist_call(call) {}
}
~tag() { ~tag() {
persist_tag->Dispose(); persist_tag->Dispose();
@ -96,9 +95,7 @@ Handle<Value> TagGetCall(void *tag) {
return NanEscapeScope(call_value); return NanEscapeScope(call_value);
} }
void DestroyTag(void *tag) { void DestroyTag(void *tag) { delete reinterpret_cast<struct tag *>(tag); }
delete reinterpret_cast<struct tag*>(tag);
}
} // namespace node } // namespace node
} // namespace grpc } // namespace grpc

Loading…
Cancel
Save