Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
956c1138
Commit
956c1138
authored
Jan 13, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Allow units (k, m, and g) in --{read,write}-{rate,burst}
So that you can specify --read-rate=1M --read-burst=4M
parent
5e8eb926
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
26 deletions
+142
-26
src/shrpx-unittest.cc
src/shrpx-unittest.cc
+4
-0
src/shrpx.cc
src/shrpx.cc
+4
-4
src/shrpx_config.cc
src/shrpx_config.cc
+23
-22
src/util.cc
src/util.cc
+51
-0
src/util.h
src/util.h
+25
-0
src/util_test.cc
src/util_test.cc
+33
-0
src/util_test.h
src/util_test.h
+2
-0
No files found.
src/shrpx-unittest.cc
View file @
956c1138
...
...
@@ -129,6 +129,10 @@ int main(int argc, char *argv[]) {
!
CU_add_test
(
pSuite
,
"util_select_h2"
,
shrpx
::
test_util_select_h2
)
||
!
CU_add_test
(
pSuite
,
"util_ipv6_numeric_addr"
,
shrpx
::
test_util_ipv6_numeric_addr
)
||
!
CU_add_test
(
pSuite
,
"util_utos_with_unit"
,
shrpx
::
test_util_utos_with_unit
)
||
!
CU_add_test
(
pSuite
,
"util_parse_uint_with_unit"
,
shrpx
::
test_util_parse_uint_with_unit
)
||
!
CU_add_test
(
pSuite
,
"gzip_inflate"
,
test_nghttp2_gzip_inflate
)
||
!
CU_add_test
(
pSuite
,
"ringbuf_write"
,
nghttp2
::
test_ringbuf_write
)
||
!
CU_add_test
(
pSuite
,
"ringbuf_iovec"
,
nghttp2
::
test_ringbuf_iovec
)
||
...
...
src/shrpx.cc
View file @
956c1138
...
...
@@ -816,7 +816,7 @@ Performance:
-n, --workers=<CORES>
Set the number of worker threads.
Default: )"
<<
get_config
()
->
num_worker
<<
R"(
--read-rate=<
RAT
E>
--read-rate=<
SIZ
E>
Set maximum average read rate on frontend
connection. Setting 0 to this option means read
rate is unlimited.
...
...
@@ -826,7 +826,7 @@ Performance:
connection. Setting 0 to this option means read
burst size is unlimited.
Default: )"
<<
get_config
()
->
read_burst
<<
R"(
--write-rate=<
RAT
E>
--write-rate=<
SIZ
E>
Set maximum average write rate on frontend
connection. Setting 0 to this option means write
rate is unlimited.
...
...
@@ -836,7 +836,7 @@ Performance:
connection. Setting 0 to this option means write
burst size is unlimited.
Default: )"
<<
get_config
()
->
write_burst
<<
R"(
--worker-read-rate=<
RAT
E>
--worker-read-rate=<
SIZ
E>
Set maximum average read rate on frontend
connection per worker. Setting 0 to this option
means read rate is unlimited. Not implemented
...
...
@@ -848,7 +848,7 @@ Performance:
means read burst size is unlimited. Not
implemented yet.
Default: )"
<<
get_config
()
->
worker_read_burst
<<
R"(
--worker-write-rate=<
RAT
E>
--worker-write-rate=<
SIZ
E>
Set maximum average write rate on frontend
connection per worker. Setting 0 to this option
means write rate is unlimited. Not implemented
...
...
src/shrpx_config.cc
View file @
956c1138
...
...
@@ -356,6 +356,21 @@ int parse_uint(T *dest, const char *opt, const char *optarg) {
return
0
;
}
namespace
{
template
<
typename
T
>
int
parse_uint_with_unit
(
T
*
dest
,
const
char
*
opt
,
const
char
*
optarg
)
{
auto
n
=
util
::
parse_uint_with_unit
(
optarg
);
if
(
n
==
-
1
)
{
LOG
(
ERROR
)
<<
opt
<<
": bad value: '"
<<
optarg
<<
"'"
;
return
-
1
;
}
*
dest
=
n
;
return
0
;
}
}
// namespace
template
<
typename
T
>
int
parse_int
(
T
*
dest
,
const
char
*
opt
,
const
char
*
optarg
)
{
char
*
end
=
nullptr
;
...
...
@@ -879,53 +894,39 @@ int parse_config(const char *opt, const char *optarg) {
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_READ_RATE
))
{
return
parse_uint
(
&
mod_config
()
->
read_rate
,
opt
,
optarg
);
return
parse_uint
_with_unit
(
&
mod_config
()
->
read_rate
,
opt
,
optarg
);
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_READ_BURST
))
{
int
n
;
if
(
parse_uint
(
&
n
,
opt
,
optarg
)
!=
0
)
{
return
-
1
;
}
if
(
n
==
0
)
{
LOG
(
ERROR
)
<<
opt
<<
": specify integer strictly larger than 0"
;
return
-
1
;
}
mod_config
()
->
read_burst
=
n
;
return
0
;
return
parse_uint_with_unit
(
&
mod_config
()
->
read_burst
,
opt
,
optarg
);
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_WRITE_RATE
))
{
return
parse_uint
(
&
mod_config
()
->
write_rate
,
opt
,
optarg
);
return
parse_uint
_with_unit
(
&
mod_config
()
->
write_rate
,
opt
,
optarg
);
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_WRITE_BURST
))
{
return
parse_uint
(
&
mod_config
()
->
write_burst
,
opt
,
optarg
);
return
parse_uint
_with_unit
(
&
mod_config
()
->
write_burst
,
opt
,
optarg
);
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_WORKER_READ_RATE
))
{
LOG
(
WARN
)
<<
opt
<<
": not implemented yet"
;
return
parse_uint
(
&
mod_config
()
->
worker_read_rate
,
opt
,
optarg
);
return
parse_uint
_with_unit
(
&
mod_config
()
->
worker_read_rate
,
opt
,
optarg
);
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_WORKER_READ_BURST
))
{
LOG
(
WARN
)
<<
opt
<<
": not implemented yet"
;
return
parse_uint
(
&
mod_config
()
->
worker_read_burst
,
opt
,
optarg
);
return
parse_uint
_with_unit
(
&
mod_config
()
->
worker_read_burst
,
opt
,
optarg
);
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_WORKER_WRITE_RATE
))
{
LOG
(
WARN
)
<<
opt
<<
": not implemented yet"
;
return
parse_uint
(
&
mod_config
()
->
worker_write_rate
,
opt
,
optarg
);
return
parse_uint
_with_unit
(
&
mod_config
()
->
worker_write_rate
,
opt
,
optarg
);
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_WORKER_WRITE_BURST
))
{
LOG
(
WARN
)
<<
opt
<<
": not implemented yet"
;
return
parse_uint
(
&
mod_config
()
->
worker_write_burst
,
opt
,
optarg
);
return
parse_uint
_with_unit
(
&
mod_config
()
->
worker_write_burst
,
opt
,
optarg
);
}
if
(
util
::
strieq
(
opt
,
SHRPX_OPT_NPN_LIST
))
{
...
...
src/util.cc
View file @
956c1138
...
...
@@ -899,6 +899,57 @@ bool ipv6_numeric_addr(const char *host) {
return
inet_pton
(
AF_INET6
,
host
,
dst
)
==
1
;
}
int64_t
parse_uint_with_unit
(
const
char
*
s
)
{
int64_t
n
=
0
;
size_t
i
;
auto
len
=
strlen
(
s
);
if
(
len
==
0
)
{
return
-
1
;
}
constexpr
int64_t
max
=
std
::
numeric_limits
<
int64_t
>::
max
();
for
(
i
=
0
;
i
<
len
;
++
i
)
{
if
(
'0'
<=
s
[
i
]
&&
s
[
i
]
<=
'9'
)
{
if
(
n
>
max
/
10
)
{
return
-
1
;
}
n
*=
10
;
if
(
n
>
max
-
(
s
[
i
]
-
'0'
))
{
return
-
1
;
}
n
+=
s
[
i
]
-
'0'
;
continue
;
}
break
;
}
if
(
i
==
len
)
{
return
n
;
}
if
(
i
==
0
||
i
+
1
!=
len
)
{
return
-
1
;
}
int
mul
=
1
;
switch
(
s
[
i
])
{
case
'K'
:
case
'k'
:
mul
=
1
<<
10
;
break
;
case
'M'
:
case
'm'
:
mul
=
1
<<
20
;
break
;
case
'G'
:
case
'g'
:
mul
=
1
<<
30
;
break
;
default:
return
-
1
;
}
if
(
n
>
max
/
mul
)
{
return
-
1
;
}
return
n
*
mul
;
}
}
// namespace util
}
// namespace nghttp2
src/util.h
View file @
956c1138
...
...
@@ -341,6 +341,24 @@ template <typename T> std::string utos(T n) {
return
res
;
}
template
<
typename
T
>
std
::
string
utos_with_unit
(
T
n
)
{
char
u
=
0
;
if
(
n
>=
(
1
<<
30
))
{
u
=
'G'
;
n
/=
(
1
<<
30
);
}
else
if
(
n
>=
(
1
<<
20
))
{
u
=
'M'
;
n
/=
(
1
<<
20
);
}
else
if
(
n
>=
(
1
<<
10
))
{
u
=
'K'
;
n
/=
(
1
<<
10
);
}
if
(
u
==
0
)
{
return
utos
(
n
);
}
return
utos
(
n
)
+
u
;
}
extern
const
char
UPPER_XDIGITS
[];
template
<
typename
T
>
std
::
string
utox
(
T
n
)
{
...
...
@@ -477,6 +495,13 @@ bool check_socket_connected(int fd);
// Returns true if |host| is IPv6 numeric address (e.g., ::1)
bool
ipv6_numeric_addr
(
const
char
*
host
);
// Parses NULL terminated string |s| as unsigned integer and returns
// the parsed integer. Additionally, if |s| ends with 'k', 'm', 'g'
// and its upper case characters, multiply the integer by 1024, 1024 *
// 1024 and 1024 * 1024 respectively. If there is an error, returns
// -1.
int64_t
parse_uint_with_unit
(
const
char
*
s
);
}
// namespace util
}
// namespace nghttp2
...
...
src/util_test.cc
View file @
956c1138
...
...
@@ -174,4 +174,37 @@ void test_util_ipv6_numeric_addr(void) {
CU_ASSERT
(
!
util
::
ipv6_numeric_addr
(
"localhost"
));
}
void
test_util_utos_with_unit
(
void
)
{
CU_ASSERT
(
"0"
==
util
::
utos_with_unit
(
0
));
CU_ASSERT
(
"1023"
==
util
::
utos_with_unit
(
1023
));
CU_ASSERT
(
"1K"
==
util
::
utos_with_unit
(
1024
));
CU_ASSERT
(
"1K"
==
util
::
utos_with_unit
(
1025
));
CU_ASSERT
(
"1M"
==
util
::
utos_with_unit
(
1
<<
20
));
CU_ASSERT
(
"1G"
==
util
::
utos_with_unit
(
1
<<
30
));
CU_ASSERT
(
"1024G"
==
util
::
utos_with_unit
(
1LL
<<
40
));
}
void
test_util_parse_uint_with_unit
(
void
)
{
CU_ASSERT
(
0
==
util
::
parse_uint_with_unit
(
"0"
));
CU_ASSERT
(
1023
==
util
::
parse_uint_with_unit
(
"1023"
));
CU_ASSERT
(
1024
==
util
::
parse_uint_with_unit
(
"1k"
));
CU_ASSERT
(
2048
==
util
::
parse_uint_with_unit
(
"2K"
));
CU_ASSERT
(
1
<<
20
==
util
::
parse_uint_with_unit
(
"1m"
));
CU_ASSERT
(
1
<<
21
==
util
::
parse_uint_with_unit
(
"2M"
));
CU_ASSERT
(
1
<<
30
==
util
::
parse_uint_with_unit
(
"1g"
));
CU_ASSERT
(
1LL
<<
31
==
util
::
parse_uint_with_unit
(
"2G"
));
CU_ASSERT
(
9223372036854775807LL
==
util
::
parse_uint_with_unit
(
"9223372036854775807"
));
// check overflow case
CU_ASSERT
(
-
1
==
util
::
parse_uint_with_unit
(
"9223372036854775808"
));
CU_ASSERT
(
-
1
==
util
::
parse_uint_with_unit
(
"10000000000000000000"
));
CU_ASSERT
(
-
1
==
util
::
parse_uint_with_unit
(
"9223372036854775807G"
));
// bad characters
CU_ASSERT
(
-
1
==
util
::
parse_uint_with_unit
(
"1.1"
));
CU_ASSERT
(
-
1
==
util
::
parse_uint_with_unit
(
"1a"
));
CU_ASSERT
(
-
1
==
util
::
parse_uint_with_unit
(
"a1"
));
CU_ASSERT
(
-
1
==
util
::
parse_uint_with_unit
(
"1T"
));
CU_ASSERT
(
-
1
==
util
::
parse_uint_with_unit
(
""
));
}
}
// namespace shrpx
src/util_test.h
View file @
956c1138
...
...
@@ -37,6 +37,8 @@ void test_util_utox(void);
void
test_util_http_date
(
void
);
void
test_util_select_h2
(
void
);
void
test_util_ipv6_numeric_addr
(
void
);
void
test_util_utos_with_unit
(
void
);
void
test_util_parse_uint_with_unit
(
void
);
}
// namespace shrpx
...
...
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