Commit 3a44dd7c authored by zhujiashun's avatar zhujiashun

add more comment to IsCanceled() and NotifyOnCancel()

parent 05af6714
......@@ -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 {
......
......@@ -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
......
......@@ -70,7 +70,7 @@ public:
EXPECT_EQ(-1, cntl->deadline_us());
} else {
EXPECT_NEAR(cntl->deadline_us(),
butil::gettimeofday_us() + req->timeout_us(), 30);
butil::gettimeofday_us() + req->timeout_us(), 60);
if (req->timeout_us() < 10) {
bthread_usleep(req->timeout_us() + 1);
EXPECT_TRUE(cntl->IsCanceled());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment