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
98654160
Commit
98654160
authored
Nov 01, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move grpc timeout related code to grpc.cpp
parent
0f9d7878
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
50 deletions
+52
-50
grpc.cpp
src/brpc/grpc.cpp
+45
-0
http_rpc_protocol.cpp
src/brpc/policy/http_rpc_protocol.cpp
+7
-50
No files found.
src/brpc/grpc.cpp
View file @
98654160
...
...
@@ -166,4 +166,49 @@ void PercentDecode(const std::string& str, std::string* str_out) {
}
}
int64_t
ConvertGrpcTimeoutToUS
(
const
std
::
string
*
grpc_timeout
)
{
if
(
!
grpc_timeout
||
grpc_timeout
->
empty
())
{
return
-
1
;
}
const
char
timeout_unit
=
grpc_timeout
->
back
();
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 is treated as no deadline.
// For example:
// "1H", "2993S", "82m" is valid.
// "30A" is also valid, but the following switch would fall into default
// case and 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
((
size_t
)(
endptr
-
grpc_timeout
->
data
())
!=
grpc_timeout
->
size
()
-
1
)
{
return
-
1
;
}
switch
(
timeout_unit
)
{
case
'H'
:
timeout_value
*=
(
3600
*
1000000L
);
break
;
case
'M'
:
timeout_value
*=
(
60
*
1000000L
);
break
;
case
'S'
:
timeout_value
*=
1000000L
;
break
;
case
'm'
:
timeout_value
*=
1000L
;
break
;
case
'u'
:
break
;
case
'n'
:
timeout_value
=
(
timeout_value
+
500
)
/
1000
;
if
(
timeout_value
==
0
)
{
timeout_value
=
1
;
}
break
;
default
:
return
-
1
;
}
return
timeout_value
;
}
}
// namespace brpc
src/brpc/policy/http_rpc_protocol.cpp
View file @
98654160
...
...
@@ -50,6 +50,8 @@ int is_failed_after_queries(const http_parser* parser);
int
is_failed_after_http_version
(
const
http_parser
*
parser
);
DECLARE_bool
(
http_verbose
);
DECLARE_int32
(
http_verbose_max_body_length
);
// Defined in grpc.cpp
int64_t
ConvertGrpcTimeoutToUS
(
const
std
::
string
*
grpc_timeout
);
namespace
policy
{
...
...
@@ -1194,35 +1196,6 @@ void EndRunningCallMethodInPool(
::
google
::
protobuf
::
Message
*
response
,
::
google
::
protobuf
::
Closure
*
done
);
static
int64_t
ConvertGrpcTimeoutToUS
(
int64_t
timeout_value
,
const
char
timeout_unit
)
{
switch
(
timeout_unit
)
{
case
'H'
:
timeout_value
*=
(
3600
*
1000000L
);
break
;
case
'M'
:
timeout_value
*=
(
60
*
1000000L
);
break
;
case
'S'
:
timeout_value
*=
1000000L
;
break
;
case
'm'
:
timeout_value
*=
1000L
;
break
;
case
'u'
:
break
;
case
'n'
:
timeout_value
=
(
timeout_value
+
500
)
/
1000
;
if
(
timeout_value
==
0
)
{
timeout_value
=
1
;
}
break
;
default:
return
-
1
;
}
return
timeout_value
;
}
void
ProcessHttpRequest
(
InputMessageBase
*
msg
)
{
const
int64_t
start_parse_us
=
butil
::
cpuwide_time_us
();
DestroyingPtr
<
HttpContext
>
imsg_guard
(
static_cast
<
HttpContext
*>
(
msg
));
...
...
@@ -1451,27 +1424,11 @@ void ProcessHttpRequest(InputMessageBase *msg) {
return
;
}
}
const
std
::
string
*
grpc_timeout
=
req_header
.
GetHeader
(
common
->
GRPC_TIMEOUT
);
if
(
grpc_timeout
&&
!
grpc_timeout
->
empty
())
{
const
char
timeout_unit
=
grpc_timeout
->
back
();
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 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
((
size_t
)(
endptr
-
grpc_timeout
->
data
())
==
grpc_timeout
->
size
()
-
1
)
{
int64_t
timeout_value_us
=
ConvertGrpcTimeoutToUS
(
timeout_value
,
timeout_unit
);
if
(
timeout_value_us
>=
0
)
{
accessor
.
set_deadline_us
(
butil
::
gettimeofday_us
()
+
timeout_value_us
);
}
}
int64_t
timeout_value_us
=
ConvertGrpcTimeoutToUS
(
req_header
.
GetHeader
(
common
->
GRPC_TIMEOUT
));
if
(
timeout_value_us
>=
0
)
{
accessor
.
set_deadline_us
(
butil
::
gettimeofday_us
()
+
timeout_value_us
);
}
}
}
else
{
...
...
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