Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
3a44dd7c
Commit
3a44dd7c
authored
Nov 03, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more comment to IsCanceled() and NotifyOnCancel()
parent
05af6714
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
7 deletions
+12
-7
controller.cpp
src/brpc/controller.cpp
+4
-2
controller.h
src/brpc/controller.h
+7
-4
brpc_grpc_protocol_unittest.cpp
test/brpc_grpc_protocol_unittest.cpp
+1
-1
No files found.
src/brpc/controller.cpp
View file @
3a44dd7c
...
...
@@ -456,9 +456,11 @@ void Controller::CloseConnection(const char* reason_fmt, ...) {
}
bool
Controller
::
IsCanceled
()
const
{
if
(
_deadline_us
>=
0
&&
butil
::
gettimeofday_us
()
>=
_deadline_us
)
{
return
false
;
}
SocketUniquePtr
sock
;
return
(
Socket
::
Address
(
_current_call
.
peer_id
,
&
sock
)
!=
0
)
||
(
_deadline_us
>=
0
&&
butil
::
gettimeofday_us
()
>=
_deadline_us
);
return
Socket
::
Address
(
_current_call
.
peer_id
,
&
sock
)
!=
0
;
}
class
RunOnCancelThread
{
...
...
src/brpc/controller.h
View file @
3a44dd7c
...
...
@@ -309,9 +309,9 @@ public:
// undefined on the client side (may crash).
// ------------------------------------------------------------------------
//
If true, indicates that the client canceled the RPC or the connection has
//
broken, so the server may as well give up on replying to it. The server
// should still call the final "done" callback.
//
Returns true if the client canceled the RPC or the connection has broken
//
or deadline has been reached, so the server may as well give up on replying
//
to it. The server
should still call the final "done" callback.
bool
IsCanceled
()
const
;
// Asks that the given callback be called when the RPC is canceled or the
...
...
@@ -319,8 +319,11 @@ public:
// If the RPC completes without being canceled/broken connection, the callback
// will be called after completion. If the RPC has already been canceled/broken
// when NotifyOnCancel() is called, the callback will be called immediately.
//
// NotifyOnCancel() must be called no more than once per request.
//
// NOTE: If the RPC is canceled since deadline has been reached, the callback
// would not be called immediately and still be called after the completion of
// RPC.
void
NotifyOnCancel
(
google
::
protobuf
::
Closure
*
callback
);
// Returns the authenticated result. NULL if there is no authentication
...
...
test/brpc_grpc_protocol_unittest.cpp
View file @
3a44dd7c
...
...
@@ -70,7 +70,7 @@ public:
EXPECT_EQ
(
-
1
,
cntl
->
deadline_us
());
}
else
{
EXPECT_NEAR
(
cntl
->
deadline_us
(),
butil
::
gettimeofday_us
()
+
req
->
timeout_us
(),
3
0
);
butil
::
gettimeofday_us
()
+
req
->
timeout_us
(),
6
0
);
if
(
req
->
timeout_us
()
<
10
)
{
bthread_usleep
(
req
->
timeout_us
()
+
1
);
EXPECT_TRUE
(
cntl
->
IsCanceled
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment