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
21c7f68b
Commit
21c7f68b
authored
9 years ago
by
Yang Gao
Browse files
Options
Downloads
Patches
Plain Diff
update code to reflect API changes
parent
00019f5a
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
cpp/helloworld/greeter_async_client.cc
+3
-7
3 additions, 7 deletions
cpp/helloworld/greeter_async_client.cc
cpp/helloworld/greeter_async_server.cc
+10
-10
10 additions, 10 deletions
cpp/helloworld/greeter_async_server.cc
with
13 additions
and
17 deletions
cpp/helloworld/greeter_async_client.cc
+
3
−
7
View file @
21c7f68b
...
@@ -71,18 +71,14 @@ class GreeterClient {
...
@@ -71,18 +71,14 @@ class GreeterClient {
Status
status
;
Status
status
;
std
::
unique_ptr
<
ClientAsyncResponseReader
<
HelloReply
>
>
rpc
(
std
::
unique_ptr
<
ClientAsyncResponseReader
<
HelloReply
>
>
rpc
(
stub_
->
AsyncSayHello
(
&
context
,
request
,
&
cq
,
(
void
*
)
1
));
stub_
->
AsyncSayHello
(
&
context
,
request
,
&
cq
));
rpc
->
Finish
(
&
reply
,
&
status
,
(
void
*
)
1
);
void
*
got_tag
;
void
*
got_tag
;
bool
ok
;
bool
ok
=
false
;
cq
.
Next
(
&
got_tag
,
&
ok
);
cq
.
Next
(
&
got_tag
,
&
ok
);
GPR_ASSERT
(
ok
);
GPR_ASSERT
(
ok
);
GPR_ASSERT
(
got_tag
==
(
void
*
)
1
);
GPR_ASSERT
(
got_tag
==
(
void
*
)
1
);
rpc
->
Finish
(
&
reply
,
&
status
,
(
void
*
)
2
);
cq
.
Next
(
&
got_tag
,
&
ok
);
GPR_ASSERT
(
ok
);
GPR_ASSERT
(
got_tag
==
(
void
*
)
2
);
if
(
status
.
IsOk
())
{
if
(
status
.
IsOk
())
{
return
reply
.
message
();
return
reply
.
message
();
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
cpp/helloworld/greeter_async_server.cc
+
10
−
10
View file @
21c7f68b
...
@@ -47,11 +47,11 @@
...
@@ -47,11 +47,11 @@
#include
<grpc++/status.h>
#include
<grpc++/status.h>
#include
"helloworld.grpc.pb.h"
#include
"helloworld.grpc.pb.h"
using
grpc
::
CompletionQueue
;
using
grpc
::
Server
;
using
grpc
::
Server
;
using
grpc
::
ServerAsyncResponseWriter
;
using
grpc
::
ServerAsyncResponseWriter
;
using
grpc
::
ServerBuilder
;
using
grpc
::
ServerBuilder
;
using
grpc
::
ServerContext
;
using
grpc
::
ServerContext
;
using
grpc
::
ServerCompletionQueue
;
using
grpc
::
Status
;
using
grpc
::
Status
;
using
helloworld
::
HelloRequest
;
using
helloworld
::
HelloRequest
;
using
helloworld
::
HelloReply
;
using
helloworld
::
HelloReply
;
...
@@ -59,11 +59,9 @@ using helloworld::Greeter;
...
@@ -59,11 +59,9 @@ using helloworld::Greeter;
class
ServerImpl
final
{
class
ServerImpl
final
{
public:
public:
ServerImpl
()
:
service_
(
&
cq_
)
{}
~
ServerImpl
()
{
~
ServerImpl
()
{
server_
->
Shutdown
();
server_
->
Shutdown
();
cq_
.
Shutdown
();
cq_
->
Shutdown
();
}
}
// There is no shutdown handling in this code.
// There is no shutdown handling in this code.
...
@@ -73,6 +71,7 @@ class ServerImpl final {
...
@@ -73,6 +71,7 @@ class ServerImpl final {
ServerBuilder
builder
;
ServerBuilder
builder
;
builder
.
AddListeningPort
(
server_address
,
grpc
::
InsecureServerCredentials
());
builder
.
AddListeningPort
(
server_address
,
grpc
::
InsecureServerCredentials
());
builder
.
RegisterAsyncService
(
&
service_
);
builder
.
RegisterAsyncService
(
&
service_
);
cq_
=
builder
.
AddCompletionQueue
();
server_
=
builder
.
BuildAndStart
();
server_
=
builder
.
BuildAndStart
();
std
::
cout
<<
"Server listening on "
<<
server_address
<<
std
::
endl
;
std
::
cout
<<
"Server listening on "
<<
server_address
<<
std
::
endl
;
...
@@ -82,14 +81,15 @@ class ServerImpl final {
...
@@ -82,14 +81,15 @@ class ServerImpl final {
private
:
private
:
class
CallData
{
class
CallData
{
public:
public:
CallData
(
Greeter
::
AsyncService
*
service
,
CompletionQueue
*
cq
)
CallData
(
Greeter
::
AsyncService
*
service
,
Server
CompletionQueue
*
cq
)
:
service_
(
service
),
cq_
(
cq
),
responder_
(
&
ctx_
),
status_
(
CREATE
)
{
:
service_
(
service
),
cq_
(
cq
),
responder_
(
&
ctx_
),
status_
(
CREATE
)
{
Proceed
();
Proceed
();
}
}
void
Proceed
()
{
void
Proceed
()
{
if
(
status_
==
CREATE
)
{
if
(
status_
==
CREATE
)
{
service_
->
RequestSayHello
(
&
ctx_
,
&
request_
,
&
responder_
,
cq_
,
this
);
service_
->
RequestSayHello
(
&
ctx_
,
&
request_
,
&
responder_
,
cq_
,
cq_
,
this
);
status_
=
PROCESS
;
status_
=
PROCESS
;
}
else
if
(
status_
==
PROCESS
)
{
}
else
if
(
status_
==
PROCESS
)
{
new
CallData
(
service_
,
cq_
);
new
CallData
(
service_
,
cq_
);
...
@@ -104,7 +104,7 @@ class ServerImpl final {
...
@@ -104,7 +104,7 @@ class ServerImpl final {
private
:
private
:
Greeter
::
AsyncService
*
service_
;
Greeter
::
AsyncService
*
service_
;
CompletionQueue
*
cq_
;
Server
CompletionQueue
*
cq_
;
ServerContext
ctx_
;
ServerContext
ctx_
;
HelloRequest
request_
;
HelloRequest
request_
;
HelloReply
reply_
;
HelloReply
reply_
;
...
@@ -115,17 +115,17 @@ class ServerImpl final {
...
@@ -115,17 +115,17 @@ class ServerImpl final {
// This can be run in multiple threads if needed.
// This can be run in multiple threads if needed.
void
HandleRpcs
()
{
void
HandleRpcs
()
{
new
CallData
(
&
service_
,
&
cq_
);
new
CallData
(
&
service_
,
cq_
.
get
()
);
void
*
tag
;
void
*
tag
;
bool
ok
;
bool
ok
;
while
(
true
)
{
while
(
true
)
{
cq_
.
Next
(
&
tag
,
&
ok
);
cq_
->
Next
(
&
tag
,
&
ok
);
GPR_ASSERT
(
ok
);
GPR_ASSERT
(
ok
);
static_cast
<
CallData
*>
(
tag
)
->
Proceed
();
static_cast
<
CallData
*>
(
tag
)
->
Proceed
();
}
}
}
}
CompletionQueue
cq_
;
std
::
unique_ptr
<
Server
CompletionQueue
>
cq_
;
Greeter
::
AsyncService
service_
;
Greeter
::
AsyncService
service_
;
std
::
unique_ptr
<
Server
>
server_
;
std
::
unique_ptr
<
Server
>
server_
;
};
};
...
...
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