Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
cd35c4c1
Commit
cd35c4c1
authored
9 years ago
by
murgatroid99
Browse files
Options
Downloads
Patches
Plain Diff
Updated server to use new shutdown semantics
parent
10c763ac
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/node/ext/server.cc
+38
-3
38 additions, 3 deletions
src/node/ext/server.cc
src/node/ext/server.h
+3
-0
3 additions, 0 deletions
src/node/ext/server.h
with
41 additions
and
3 deletions
src/node/ext/server.cc
+
38
−
3
View file @
cd35c4c1
...
@@ -112,9 +112,17 @@ class NewCallOp : public Op {
...
@@ -112,9 +112,17 @@ class NewCallOp : public Op {
}
}
};
};
Server
::
Server
(
grpc_server
*
server
)
:
wrapped_server
(
server
)
{}
Server
::
Server
(
grpc_server
*
server
)
:
wrapped_server
(
server
)
{
shutdown_queue
=
grpc_completion_queue_create
();
grpc_server_register_completion_queue
(
server
,
shutdown_queue
);
}
Server
::~
Server
()
{
grpc_server_destroy
(
wrapped_server
);
}
Server
::~
Server
()
{
this
->
ShutdownServer
();
grpc_completion_queue_shutdown
(
this
->
shutdown_queue
);
grpc_server_destroy
(
wrapped_server
);
grpc_completion_queue_destroy
(
this
->
shutdown_queue
);
}
void
Server
::
Init
(
Handle
<
Object
>
exports
)
{
void
Server
::
Init
(
Handle
<
Object
>
exports
)
{
NanScope
();
NanScope
();
...
@@ -148,6 +156,16 @@ bool Server::HasInstance(Handle<Value> val) {
...
@@ -148,6 +156,16 @@ bool Server::HasInstance(Handle<Value> val) {
return
NanHasInstance
(
fun_tpl
,
val
);
return
NanHasInstance
(
fun_tpl
,
val
);
}
}
void
Server
::
ShutdownServer
()
{
if
(
this
->
wrapped_server
!=
NULL
)
{
grpc_server_shutdown_and_notify
(
this
->
wrapped_server
,
this
->
shutdown_queue
,
NULL
);
grpc_completion_queue_pluck
(
this
->
shutdown_queue
,
NULL
,
gpr_inf_future
);
this
->
wrapped_server
=
NULL
;
}
}
NAN_METHOD
(
Server
::
New
)
{
NAN_METHOD
(
Server
::
New
)
{
NanScope
();
NanScope
();
...
@@ -207,6 +225,9 @@ NAN_METHOD(Server::RequestCall) {
...
@@ -207,6 +225,9 @@ NAN_METHOD(Server::RequestCall) {
return
NanThrowTypeError
(
"requestCall can only be called on a Server"
);
return
NanThrowTypeError
(
"requestCall can only be called on a Server"
);
}
}
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
if
(
server
->
wrapped_server
==
NULL
)
{
return
NanThrowError
(
"requestCall cannot be called on a shut down Server"
);
}
NewCallOp
*
op
=
new
NewCallOp
();
NewCallOp
*
op
=
new
NewCallOp
();
unique_ptr
<
OpVec
>
ops
(
new
OpVec
());
unique_ptr
<
OpVec
>
ops
(
new
OpVec
());
ops
->
push_back
(
unique_ptr
<
Op
>
(
op
));
ops
->
push_back
(
unique_ptr
<
Op
>
(
op
));
...
@@ -232,6 +253,9 @@ NAN_METHOD(Server::AddHttp2Port) {
...
@@ -232,6 +253,9 @@ NAN_METHOD(Server::AddHttp2Port) {
return
NanThrowTypeError
(
"addHttp2Port's argument must be a String"
);
return
NanThrowTypeError
(
"addHttp2Port's argument must be a String"
);
}
}
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
if
(
server
->
wrapped_server
==
NULL
)
{
return
NanThrowError
(
"addHttp2Port cannot be called on a shut down Server"
);
}
NanReturnValue
(
NanNew
<
Number
>
(
grpc_server_add_http2_port
(
NanReturnValue
(
NanNew
<
Number
>
(
grpc_server_add_http2_port
(
server
->
wrapped_server
,
*
NanUtf8String
(
args
[
0
]))));
server
->
wrapped_server
,
*
NanUtf8String
(
args
[
0
]))));
}
}
...
@@ -251,6 +275,10 @@ NAN_METHOD(Server::AddSecureHttp2Port) {
...
@@ -251,6 +275,10 @@ NAN_METHOD(Server::AddSecureHttp2Port) {
"addSecureHttp2Port's second argument must be ServerCredentials"
);
"addSecureHttp2Port's second argument must be ServerCredentials"
);
}
}
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
if
(
server
->
wrapped_server
==
NULL
)
{
return
NanThrowError
(
"addSecureHttp2Port cannot be called on a shut down Server"
);
}
ServerCredentials
*
creds
=
ObjectWrap
::
Unwrap
<
ServerCredentials
>
(
ServerCredentials
*
creds
=
ObjectWrap
::
Unwrap
<
ServerCredentials
>
(
args
[
1
]
->
ToObject
());
args
[
1
]
->
ToObject
());
NanReturnValue
(
NanNew
<
Number
>
(
grpc_server_add_secure_http2_port
(
NanReturnValue
(
NanNew
<
Number
>
(
grpc_server_add_secure_http2_port
(
...
@@ -264,17 +292,24 @@ NAN_METHOD(Server::Start) {
...
@@ -264,17 +292,24 @@ NAN_METHOD(Server::Start) {
return
NanThrowTypeError
(
"start can only be called on a Server"
);
return
NanThrowTypeError
(
"start can only be called on a Server"
);
}
}
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
if
(
server
->
wrapped_server
==
NULL
)
{
return
NanThrowError
(
"start cannot be called on a shut down Server"
);
}
grpc_server_start
(
server
->
wrapped_server
);
grpc_server_start
(
server
->
wrapped_server
);
NanReturnUndefined
();
NanReturnUndefined
();
}
}
NAN_METHOD
(
ShutdownCallback
)
{
NanReturnUndefined
();
}
NAN_METHOD
(
Server
::
Shutdown
)
{
NAN_METHOD
(
Server
::
Shutdown
)
{
NanScope
();
NanScope
();
if
(
!
HasInstance
(
args
.
This
()))
{
if
(
!
HasInstance
(
args
.
This
()))
{
return
NanThrowTypeError
(
"shutdown can only be called on a Server"
);
return
NanThrowTypeError
(
"shutdown can only be called on a Server"
);
}
}
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
Server
*
server
=
ObjectWrap
::
Unwrap
<
Server
>
(
args
.
This
());
grpc_
server
_s
hutdown
(
server
->
wrapped_s
erver
);
server
->
S
hutdown
S
erver
(
);
NanReturnUndefined
();
NanReturnUndefined
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/node/ext/server.h
+
3
−
0
View file @
cd35c4c1
...
@@ -61,6 +61,8 @@ class Server : public ::node::ObjectWrap {
...
@@ -61,6 +61,8 @@ class Server : public ::node::ObjectWrap {
Server
(
const
Server
&
);
Server
(
const
Server
&
);
Server
&
operator
=
(
const
Server
&
);
Server
&
operator
=
(
const
Server
&
);
void
ShutdownServer
();
static
NAN_METHOD
(
New
);
static
NAN_METHOD
(
New
);
static
NAN_METHOD
(
RequestCall
);
static
NAN_METHOD
(
RequestCall
);
static
NAN_METHOD
(
AddHttp2Port
);
static
NAN_METHOD
(
AddHttp2Port
);
...
@@ -71,6 +73,7 @@ class Server : public ::node::ObjectWrap {
...
@@ -71,6 +73,7 @@ class Server : public ::node::ObjectWrap {
static
v8
::
Persistent
<
v8
::
FunctionTemplate
>
fun_tpl
;
static
v8
::
Persistent
<
v8
::
FunctionTemplate
>
fun_tpl
;
grpc_server
*
wrapped_server
;
grpc_server
*
wrapped_server
;
grpc_completion_queue
*
shutdown_queue
;
};
};
}
// namespace node
}
// namespace node
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment