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
a89bf50c
Commit
a89bf50c
authored
9 years ago
by
yang-g
Browse files
Options
Downloads
Patches
Plain Diff
Handle cancel before start case
parent
bef0d6d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/grpc++/client_context.h
+7
-4
7 additions, 4 deletions
include/grpc++/client_context.h
src/cpp/client/client_context.cc
+8
-0
8 additions, 0 deletions
src/cpp/client/client_context.cc
test/cpp/end2end/end2end_test.cc
+12
-0
12 additions, 0 deletions
test/cpp/end2end/end2end_test.cc
with
27 additions
and
4 deletions
include/grpc++/client_context.h
+
7
−
4
View file @
a89bf50c
...
@@ -53,15 +53,16 @@
...
@@ -53,15 +53,16 @@
#include
<memory>
#include
<memory>
#include
<string>
#include
<string>
#include
<grpc/compression.h>
#include
<grpc++/impl/sync.h>
#include
<grpc/grpc.h>
#include
<grpc/support/log.h>
#include
<grpc/support/time.h>
#include
<grpc++/security/auth_context.h>
#include
<grpc++/security/auth_context.h>
#include
<grpc++/support/config.h>
#include
<grpc++/support/config.h>
#include
<grpc++/support/status.h>
#include
<grpc++/support/status.h>
#include
<grpc++/support/string_ref.h>
#include
<grpc++/support/string_ref.h>
#include
<grpc++/support/time.h>
#include
<grpc++/support/time.h>
#include
<grpc/compression.h>
#include
<grpc/grpc.h>
#include
<grpc/support/log.h>
#include
<grpc/support/time.h>
struct
census_context
;
struct
census_context
;
...
@@ -315,7 +316,9 @@ class ClientContext {
...
@@ -315,7 +316,9 @@ class ClientContext {
bool
initial_metadata_received_
;
bool
initial_metadata_received_
;
std
::
shared_ptr
<
Channel
>
channel_
;
std
::
shared_ptr
<
Channel
>
channel_
;
grpc
::
mutex
mu_
;
grpc_call
*
call_
;
grpc_call
*
call_
;
bool
call_canceled_
;
gpr_timespec
deadline_
;
gpr_timespec
deadline_
;
grpc
::
string
authority_
;
grpc
::
string
authority_
;
std
::
shared_ptr
<
Credentials
>
creds_
;
std
::
shared_ptr
<
Credentials
>
creds_
;
...
...
This diff is collapsed.
Click to expand it.
src/cpp/client/client_context.cc
+
8
−
0
View file @
a89bf50c
...
@@ -48,6 +48,7 @@ namespace grpc {
...
@@ -48,6 +48,7 @@ namespace grpc {
ClientContext
::
ClientContext
()
ClientContext
::
ClientContext
()
:
initial_metadata_received_
(
false
),
:
initial_metadata_received_
(
false
),
call_
(
nullptr
),
call_
(
nullptr
),
call_canceled_
(
false
),
deadline_
(
gpr_inf_future
(
GPR_CLOCK_REALTIME
)),
deadline_
(
gpr_inf_future
(
GPR_CLOCK_REALTIME
)),
propagate_from_call_
(
nullptr
)
{}
propagate_from_call_
(
nullptr
)
{}
...
@@ -72,6 +73,7 @@ void ClientContext::AddMetadata(const grpc::string& meta_key,
...
@@ -72,6 +73,7 @@ void ClientContext::AddMetadata(const grpc::string& meta_key,
void
ClientContext
::
set_call
(
grpc_call
*
call
,
void
ClientContext
::
set_call
(
grpc_call
*
call
,
const
std
::
shared_ptr
<
Channel
>&
channel
)
{
const
std
::
shared_ptr
<
Channel
>&
channel
)
{
grpc
::
unique_lock
<
grpc
::
mutex
>
lock
(
mu_
);
GPR_ASSERT
(
call_
==
nullptr
);
GPR_ASSERT
(
call_
==
nullptr
);
call_
=
call
;
call_
=
call
;
channel_
=
channel
;
channel_
=
channel
;
...
@@ -79,6 +81,9 @@ void ClientContext::set_call(grpc_call* call,
...
@@ -79,6 +81,9 @@ void ClientContext::set_call(grpc_call* call,
grpc_call_cancel_with_status
(
call
,
GRPC_STATUS_CANCELLED
,
grpc_call_cancel_with_status
(
call
,
GRPC_STATUS_CANCELLED
,
"Failed to set credentials to rpc."
,
nullptr
);
"Failed to set credentials to rpc."
,
nullptr
);
}
}
if
(
call_canceled_
)
{
grpc_call_cancel
(
call_
,
nullptr
);
}
}
}
void
ClientContext
::
set_compression_algorithm
(
void
ClientContext
::
set_compression_algorithm
(
...
@@ -101,8 +106,11 @@ std::shared_ptr<const AuthContext> ClientContext::auth_context() const {
...
@@ -101,8 +106,11 @@ std::shared_ptr<const AuthContext> ClientContext::auth_context() const {
}
}
void
ClientContext
::
TryCancel
()
{
void
ClientContext
::
TryCancel
()
{
grpc
::
unique_lock
<
grpc
::
mutex
>
lock
(
mu_
);
if
(
call_
)
{
if
(
call_
)
{
grpc_call_cancel
(
call_
,
nullptr
);
grpc_call_cancel
(
call_
,
nullptr
);
}
else
{
call_canceled_
=
true
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
test/cpp/end2end/end2end_test.cc
+
12
−
0
View file @
a89bf50c
...
@@ -575,6 +575,18 @@ void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) {
...
@@ -575,6 +575,18 @@ void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) {
context
->
TryCancel
();
context
->
TryCancel
();
}
}
TEST_P
(
End2endTest
,
CancelRpcBeforeStart
)
{
ResetStub
();
EchoRequest
request
;
EchoResponse
response
;
ClientContext
context
;
request
.
set_message
(
"hello"
);
context
.
TryCancel
();
Status
s
=
stub_
->
Echo
(
&
context
,
request
,
&
response
);
EXPECT_EQ
(
""
,
response
.
message
());
EXPECT_EQ
(
grpc
::
StatusCode
::
CANCELLED
,
s
.
error_code
());
}
// Client cancels request stream after sending two messages
// Client cancels request stream after sending two messages
TEST_P
(
End2endTest
,
ClientCancelsRequestStream
)
{
TEST_P
(
End2endTest
,
ClientCancelsRequestStream
)
{
ResetStub
();
ResetStub
();
...
...
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