Commit 6881c5bf authored by zhujiashun's avatar zhujiashun

refine comment

parent d35d8210
......@@ -128,6 +128,8 @@ public:
std::string& protocol_param() { return _cntl->protocol_param(); }
const std::string& protocol_param() const { return _cntl->protocol_param(); }
// Note: This function can only be called in server side. The deadline of client
// side is properly set in the RPC sending path.
void set_deadline_us(int64_t deadline_us) { _cntl->_deadline_us = deadline_us; }
private:
......
......@@ -1191,7 +1191,7 @@ void EndRunningCallMethodInPool(
::google::protobuf::Message* response,
::google::protobuf::Closure* done);
static int64_t ConvertGrpcTimeoutToMS(int64_t timeout_value, const char timeout_unit) {
static int64_t ConvertGrpcTimeoutToUS(int64_t timeout_value, const char timeout_unit) {
switch (timeout_unit) {
case 'H':
timeout_value *= (3600 * 1000000L);
......@@ -1451,12 +1451,23 @@ void ProcessHttpRequest(InputMessageBase *msg) {
const std::string* grpc_timeout = req_header.GetHeader(common->GRPC_TIMEOUT);
if (grpc_timeout && !grpc_timeout->empty()) {
const char timeout_unit = grpc_timeout->back();
// If no digits were found, strtol returns zero as timeout value
int64_t timeout_value_ms =
ConvertGrpcTimeoutToMS((int64_t)strtol(grpc_timeout->data(), NULL, 10), timeout_unit);
if (timeout_value_ms >= 0) {
accessor.set_deadline_us(
butil::gettimeofday_us() + timeout_value_ms);
char* endptr = NULL;
int64_t timeout_value = (int64_t)strtol(grpc_timeout->data(), &endptr, 10);
// Only the format that the digit number is equal to (timeout header size - 1) is valid.
// Otherwise the format is not valid and the is treated as no deadline.
// For example:
// 1H, 2993S, 82m is valid.
// 30A is also valid, but the following ConvertGrpcTimeoutToUS would return -1 since 'A'
// is not a valid time unit.
// 123ASH is not vaid since the digit number is 3, while the size is 6.
// HHH is not valid since the dight number is 0, while the size is 3.
if (endptr - grpc_timeout->data() == grpc_timeout->size() - 1) {
int64_t timeout_value_us =
ConvertGrpcTimeoutToUS( timeout_unit);
if (timeout_value_us >= 0) {
accessor.set_deadline_us(
butil::gettimeofday_us() + timeout_value_us);
}
}
}
}
......
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