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
985463d3
Commit
985463d3
authored
10 years ago
by
Craig Tiller
Browse files
Options
Downloads
Patches
Plain Diff
Remove sprintf from timeout_encoding
parent
c0fc6a1f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/transport/chttp2/timeout_encoding.c
+23
-15
23 additions, 15 deletions
src/core/transport/chttp2/timeout_encoding.c
with
23 additions
and
15 deletions
src/core/transport/chttp2/timeout_encoding.c
+
23
−
15
View file @
985463d3
...
@@ -36,6 +36,8 @@
...
@@ -36,6 +36,8 @@
#include
<stdio.h>
#include
<stdio.h>
#include
<string.h>
#include
<string.h>
#include
<grpc/support/string.h>
static
int
round_up
(
int
x
,
int
divisor
)
{
static
int
round_up
(
int
x
,
int
divisor
)
{
return
(
x
/
divisor
+
(
x
%
divisor
!=
0
))
*
divisor
;
return
(
x
/
divisor
+
(
x
%
divisor
!=
0
))
*
divisor
;
}
}
...
@@ -53,15 +55,21 @@ static int round_up_to_three_sig_figs(int x) {
...
@@ -53,15 +55,21 @@ static int round_up_to_three_sig_figs(int x) {
}
}
/* encode our minimum viable timeout value */
/* encode our minimum viable timeout value */
static
void
enc_tiny
(
char
*
buffer
)
{
strcpy
(
buffer
,
"1n"
);
}
static
void
enc_tiny
(
char
*
buffer
)
{
memcpy
(
buffer
,
"1n"
,
3
);
}
static
void
enc_ext
(
char
*
buffer
,
long
value
,
char
ext
)
{
int
n
=
gpr_ltoa
(
value
,
buffer
);
buffer
[
n
]
=
ext
;
buffer
[
n
+
1
]
=
0
;
}
static
void
enc_seconds
(
char
*
buffer
,
long
sec
)
{
static
void
enc_seconds
(
char
*
buffer
,
long
sec
)
{
if
(
sec
%
3600
==
0
)
{
if
(
sec
%
3600
==
0
)
{
sprintf
(
buffer
,
"%ldH"
,
sec
/
3600
);
enc_ext
(
buffer
,
sec
/
3600
,
'H'
);
}
else
if
(
sec
%
60
==
0
)
{
}
else
if
(
sec
%
60
==
0
)
{
sprintf
(
buffer
,
"%ldM"
,
sec
/
60
);
enc_ext
(
buffer
,
sec
/
60
,
'M'
);
}
else
{
}
else
{
sprintf
(
buffer
,
"%ldS"
,
sec
);
enc_ext
(
buffer
,
sec
,
'S'
);
}
}
}
}
...
@@ -69,23 +77,23 @@ static void enc_nanos(char *buffer, int x) {
...
@@ -69,23 +77,23 @@ static void enc_nanos(char *buffer, int x) {
x
=
round_up_to_three_sig_figs
(
x
);
x
=
round_up_to_three_sig_figs
(
x
);
if
(
x
<
100000
)
{
if
(
x
<
100000
)
{
if
(
x
%
1000
==
0
)
{
if
(
x
%
1000
==
0
)
{
sprintf
(
buffer
,
"%du"
,
x
/
1000
);
enc_ext
(
buffer
,
x
/
1000
,
'u'
);
}
else
{
}
else
{
sprintf
(
buffer
,
"%dn"
,
x
);
enc_ext
(
buffer
,
x
,
'n'
);
}
}
}
else
if
(
x
<
100000000
)
{
}
else
if
(
x
<
100000000
)
{
if
(
x
%
1000000
==
0
)
{
if
(
x
%
1000000
==
0
)
{
sprintf
(
buffer
,
"%dm"
,
x
/
1000000
);
enc_ext
(
buffer
,
x
/
1000000
,
'm'
);
}
else
{
}
else
{
sprintf
(
buffer
,
"%du"
,
x
/
1000
);
enc_ext
(
buffer
,
x
/
1000
,
'u'
);
}
}
}
else
if
(
x
<
1000000000
)
{
}
else
if
(
x
<
1000000000
)
{
sprintf
(
buffer
,
"%dm"
,
x
/
1000000
);
enc_ext
(
buffer
,
x
/
1000000
,
'm'
);
}
else
{
}
else
{
/* note that this is only ever called with times of less than one second,
/* note that this is only ever called with times of less than one second,
so if we reach here the time must have been rounded up to a whole second
so if we reach here the time must have been rounded up to a whole second
(and no more) */
(and no more) */
str
cpy
(
buffer
,
"1S"
);
mem
cpy
(
buffer
,
"1S"
,
3
);
}
}
}
}
...
@@ -93,18 +101,18 @@ static void enc_micros(char *buffer, int x) {
...
@@ -93,18 +101,18 @@ static void enc_micros(char *buffer, int x) {
x
=
round_up_to_three_sig_figs
(
x
);
x
=
round_up_to_three_sig_figs
(
x
);
if
(
x
<
100000
)
{
if
(
x
<
100000
)
{
if
(
x
%
1000
==
0
)
{
if
(
x
%
1000
==
0
)
{
sprintf
(
buffer
,
"%dm"
,
x
/
1000
);
enc_ext
(
buffer
,
x
/
1000
,
'm'
);
}
else
{
}
else
{
sprintf
(
buffer
,
"%du"
,
x
);
enc_ext
(
buffer
,
x
,
'u'
);
}
}
}
else
if
(
x
<
100000000
)
{
}
else
if
(
x
<
100000000
)
{
if
(
x
%
1000000
==
0
)
{
if
(
x
%
1000000
==
0
)
{
sprintf
(
buffer
,
"%dS"
,
x
/
1000000
);
enc_ext
(
buffer
,
x
/
1000000
,
'S'
);
}
else
{
}
else
{
sprintf
(
buffer
,
"%dm"
,
x
/
1000
);
enc_ext
(
buffer
,
x
/
1000
,
'm'
);
}
}
}
else
{
}
else
{
sprintf
(
buffer
,
"%dS"
,
x
/
1000000
);
enc_ext
(
buffer
,
x
/
1000000
,
'S'
);
}
}
}
}
...
...
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