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
ef638390
Commit
ef638390
authored
10 years ago
by
Craig Tiller
Browse files
Options
Downloads
Patches
Plain Diff
Async client works
parent
d1e18fae
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/cpp/qps/client_async.cc
+24
-1
24 additions, 1 deletion
test/cpp/qps/client_async.cc
with
24 additions
and
1 deletion
test/cpp/qps/client_async.cc
+
24
−
1
View file @
ef638390
...
...
@@ -60,6 +60,7 @@ class ClientRpcContext {
ClientRpcContext
()
{}
virtual
~
ClientRpcContext
()
{}
virtual
bool
RunNextState
()
=
0
;
// do next state, return false if steps done
virtual
void
StartNewClone
()
=
0
;
static
void
*
tag
(
ClientRpcContext
*
c
)
{
return
reinterpret_cast
<
void
*>
(
c
);
}
static
ClientRpcContext
*
detag
(
void
*
t
)
{
return
reinterpret_cast
<
ClientRpcContext
*>
(
t
);
...
...
@@ -83,7 +84,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
req_
(
req
),
response_
(),
next_state_
(
&
ClientRpcContextUnaryImpl
::
ReqSent
),
callback_
(
on_done
),
callback_
(
on_done
),
start_req_
(
start_req
),
start_
(
Timer
::
Now
()),
response_reader_
(
start_req
(
stub_
,
&
context_
,
req_
,
ClientRpcContext
::
tag
(
this
)))
{}
...
...
@@ -93,6 +94,10 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
hist
->
Add
((
Timer
::
Now
()
-
start_
)
*
1e9
);
}
void
StartNewClone
()
{
new
ClientRpcContextUnaryImpl
(
stub_
,
req_
,
start_req_
,
callback_
);
}
private
:
bool
ReqSent
()
{
next_state_
=
&
ClientRpcContextUnaryImpl
::
RespDone
;
...
...
@@ -113,6 +118,10 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
ResponseType
response_
;
bool
(
ClientRpcContextUnaryImpl
::*
next_state_
)();
std
::
function
<
void
(
grpc
::
Status
,
ResponseType
*
)
>
callback_
;
std
::
function
<
std
::
unique_ptr
<
grpc
::
ClientAsyncResponseReader
<
ResponseType
>>
(
TestService
::
Stub
*
,
grpc
::
ClientContext
*
,
const
RequestType
&
,
void
*
)
>
start_req_
;
grpc
::
Status
status_
;
double
start_
;
std
::
unique_ptr
<
grpc
::
ClientAsyncResponseReader
<
ResponseType
>>
...
...
@@ -152,6 +161,19 @@ class AsyncClient GRPC_FINAL : public Client {
StartThreads
(
config
.
async_client_threads
());
}
~
AsyncClient
()
GRPC_OVERRIDE
{
EndThreads
();
for
(
auto
&
cq
:
cli_cqs_
)
{
cq
->
Shutdown
();
void
*
got_tag
;
bool
ok
;
while
(
cq
->
Next
(
&
got_tag
,
&
ok
))
{
delete
ClientRpcContext
::
detag
(
got_tag
);
}
}
}
void
ThreadFunc
(
Histogram
*
histogram
,
size_t
thread_idx
)
{
void
*
got_tag
;
bool
ok
;
...
...
@@ -162,6 +184,7 @@ class AsyncClient GRPC_FINAL : public Client {
// call the callback and then delete it
ctx
->
report_stats
(
histogram
);
ctx
->
RunNextState
();
ctx
->
StartNewClone
();
delete
ctx
;
}
}
...
...
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