Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-09-09 23:32:02 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c4feb8f6ed92cd329955728e04e27506fc3d1fb5
c4feb8f6
1 parent
6aafd072
for #319, raw api support update all globals.
隐藏空白字符变更
内嵌
并排对比
正在显示
9 个修改的文件
包含
236 行增加
和
21 行删除
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_config.hpp
trunk/src/app/srs_app_http_api.cpp
trunk/src/app/srs_app_log.cpp
trunk/src/app/srs_app_log.hpp
trunk/src/app/srs_app_reload.cpp
trunk/src/app/srs_app_reload.hpp
trunk/src/app/srs_app_utility.cpp
trunk/src/app/srs_app_utility.hpp
trunk/src/app/srs_app_config.cpp
查看文件 @
c4feb8f
...
...
@@ -922,18 +922,6 @@ int SrsConfig::reload_conf(SrsConfig* conf)
// chunk_size, ff_log_dir,
// bandcheck, http_hooks, heartbeat,
// security
// merge config: max_connections
if
(
!
srs_directive_equals
(
root
->
get
(
"max_connections"
),
old_root
->
get
(
"max_connections"
)))
{
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_max_conns
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes reload max_connections failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_trace
(
"reload max_connections success."
);
}
// merge config: listen
if
(
!
srs_directive_equals
(
root
->
get
(
"listen"
),
old_root
->
get
(
"listen"
)))
{
...
...
@@ -970,16 +958,25 @@ int SrsConfig::reload_conf(SrsConfig* conf)
}
}
// merge config: max_connections
if
(
!
srs_directive_equals
(
root
->
get
(
"max_connections"
),
old_root
->
get
(
"max_connections"
)))
{
if
((
ret
=
do_reload_max_connections
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
}
// merge config: utc_time
if
(
!
srs_directive_equals
(
root
->
get
(
"utc_time"
),
old_root
->
get
(
"utc_time"
)))
{
if
((
ret
=
do_reload_utc_time
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
}
// merge config: pithy_print_ms
if
(
!
srs_directive_equals
(
root
->
get
(
"pithy_print_ms"
),
old_root
->
get
(
"pithy_print_ms"
)))
{
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_pithy_print
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes pithy_print_ms listen failed. ret=%d"
,
ret
);
return
ret
;
}
if
((
ret
=
do_reload_pithy_print_ms
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
srs_trace
(
"reload pithy_print_ms success."
);
}
// merge config: http_api
...
...
@@ -2376,6 +2373,81 @@ int SrsConfig::raw_set_srs_log_file(string srs_log_file, bool& applied)
return
ret
;
}
int
SrsConfig
::
raw_set_max_connections
(
string
max_connections
,
bool
&
applied
)
{
int
ret
=
ERROR_SUCCESS
;
applied
=
false
;
SrsConfDirective
*
conf
=
root
->
get_or_create
(
"max_connections"
);
if
(
conf
->
arg0
()
==
max_connections
)
{
return
ret
;
}
conf
->
args
.
clear
();
conf
->
args
.
push_back
(
max_connections
);
if
((
ret
=
do_reload_max_connections
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
applied
=
true
;
return
ret
;
}
int
SrsConfig
::
raw_set_utc_time
(
string
utc_time
,
bool
&
applied
)
{
int
ret
=
ERROR_SUCCESS
;
applied
=
false
;
SrsConfDirective
*
conf
=
root
->
get_or_create
(
"utc_time"
);
if
(
conf
->
arg0
()
==
utc_time
)
{
return
ret
;
}
conf
->
args
.
clear
();
conf
->
args
.
push_back
(
utc_time
);
if
((
ret
=
do_reload_utc_time
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
applied
=
true
;
return
ret
;
}
int
SrsConfig
::
raw_set_pithy_print_ms
(
string
pithy_print_ms
,
bool
&
applied
)
{
int
ret
=
ERROR_SUCCESS
;
applied
=
false
;
SrsConfDirective
*
conf
=
root
->
get_or_create
(
"pithy_print_ms"
);
if
(
conf
->
arg0
()
==
pithy_print_ms
)
{
return
ret
;
}
conf
->
args
.
clear
();
conf
->
args
.
push_back
(
pithy_print_ms
);
if
((
ret
=
do_reload_pithy_print_ms
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
applied
=
true
;
return
ret
;
}
int
SrsConfig
::
do_reload_listen
()
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -2461,6 +2533,57 @@ int SrsConfig::do_reload_srs_log_file()
return
ret
;
}
int
SrsConfig
::
do_reload_max_connections
()
{
int
ret
=
ERROR_SUCCESS
;
vector
<
ISrsReloadHandler
*>::
iterator
it
;
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_max_conns
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes reload max_connections failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_trace
(
"reload max_connections success."
);
return
ret
;
}
int
SrsConfig
::
do_reload_utc_time
()
{
int
ret
=
ERROR_SUCCESS
;
vector
<
ISrsReloadHandler
*>::
iterator
it
;
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_utc_time
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes utc_time failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_trace
(
"reload utc_time success."
);
return
ret
;
}
int
SrsConfig
::
do_reload_pithy_print_ms
()
{
int
ret
=
ERROR_SUCCESS
;
vector
<
ISrsReloadHandler
*>::
iterator
it
;
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_pithy_print
())
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes pithy_print_ms failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_trace
(
"reload pithy_print_ms success."
);
return
ret
;
}
string
SrsConfig
::
config
()
{
return
config_file
;
...
...
@@ -5989,6 +6112,11 @@ bool srs_stream_caster_is_flv(string caster)
return
caster
==
"flv"
;
}
string
srs_config_bool2switch
(
const
string
&
sbool
)
{
return
sbool
==
"true"
?
"on"
:
"off"
;
}
int
srs_config_transform_vhost
(
SrsConfDirective
*
root
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_config.hpp
查看文件 @
c4feb8f
...
...
@@ -361,12 +361,27 @@ public:
* raw set the global log file path for file tank.
*/
virtual
int
raw_set_srs_log_file
(
std
::
string
srs_log_file
,
bool
&
applied
);
/**
* raw set the global max connections of srs.
*/
virtual
int
raw_set_max_connections
(
std
::
string
max_connections
,
bool
&
applied
);
/**
* raw set the global whether use utc time.
*/
virtual
int
raw_set_utc_time
(
std
::
string
utc_time
,
bool
&
applied
);
/**
* raw set the global pithy print interval in ms.
*/
virtual
int
raw_set_pithy_print_ms
(
std
::
string
pithy_print_ms
,
bool
&
applied
);
private
:
virtual
int
do_reload_listen
();
virtual
int
do_reload_pid
();
virtual
int
do_reload_srs_log_tank
();
virtual
int
do_reload_srs_log_level
();
virtual
int
do_reload_srs_log_file
();
virtual
int
do_reload_max_connections
();
virtual
int
do_reload_utc_time
();
virtual
int
do_reload_pithy_print_ms
();
public
:
/**
* get the config file path.
...
...
@@ -1279,6 +1294,11 @@ extern bool srs_stream_caster_is_rtsp(std::string caster);
extern
bool
srs_stream_caster_is_flv
(
std
::
string
caster
);
/**
* convert bool in str to on/off
*/
extern
std
::
string
srs_config_bool2switch
(
const
std
::
string
&
sbool
);
/**
* parse loaded vhost directives to compatible mode.
* for exmaple, SRS1/2 use the follow refer style:
* refer a.domain.com b.domain.com;
...
...
trunk/src/app/srs_app_http_api.cpp
查看文件 @
c4feb8f
...
...
@@ -993,6 +993,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
// srs_log_tank file the tank to log, file or console.
// srs_log_level trace the level of log, verbose, info, trace, warn, error.
// srs_log_file ./objs/srs.log the log file when tank is file.
// max_connections 1000 the max connections of srs.
// utc_time false whether enable utc time.
// pithy_print_ms 10000 the pithy print interval in ms.
if
(
rpc
==
"update"
)
{
if
(
!
allow_update
)
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_DISABLED
;
...
...
@@ -1009,7 +1012,8 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
}
if
(
scope
!=
"listen"
&&
scope
!=
"pid"
&&
scope
!=
"chunk_size"
&&
scope
!=
"ff_log_dir"
&&
scope
!=
"srs_log_tank"
&&
scope
!=
"srs_log_level"
&&
scope
!=
"srs_log_file"
&&
scope
!=
"srs_log_file"
&&
scope
!=
"max_connections"
&&
scope
!=
"utc_time"
&&
scope
!=
"pithy_print_ms"
)
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED
;
srs_error
(
"raw api query invalid scope=%s. ret=%d"
,
scope
.
c_str
(),
ret
);
...
...
@@ -1106,6 +1110,41 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
srs_error
(
"raw api update srs_log_file=%s failed. ret=%d"
,
value
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
}
else
if
(
scope
==
"max_connections"
)
{
int
mcv
=
::
atoi
(
value
.
c_str
());
if
(
mcv
<
10
||
mcv
>
65535
||
!
srs_is_digit_number
(
value
))
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_PARAMS
;
srs_error
(
"raw api update check max_connections=%s/%d failed. ret=%d"
,
value
.
c_str
(),
mcv
,
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
if
((
ret
=
_srs_config
->
raw_set_max_connections
(
value
,
applied
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"raw api update max_connections=%s/%d failed. ret=%d"
,
value
.
c_str
(),
mcv
,
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
}
else
if
(
scope
==
"utc_time"
)
{
if
(
!
srs_is_boolean
(
value
))
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_PARAMS
;
srs_error
(
"raw api update check utc_time=%s failed. ret=%d"
,
value
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
if
((
ret
=
_srs_config
->
raw_set_utc_time
(
srs_config_bool2switch
(
value
),
applied
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"raw api update utc_time=%s failed. ret=%d"
,
value
.
c_str
(),
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
}
else
if
(
scope
==
"pithy_print_ms"
)
{
int
ppmv
=
::
atoi
(
value
.
c_str
());
if
(
ppmv
<
100
||
ppmv
>
300000
||
!
srs_is_digit_number
(
value
))
{
ret
=
ERROR_SYSTEM_CONFIG_RAW_PARAMS
;
srs_error
(
"raw api update check pithy_print_ms=%s/%d failed. ret=%d"
,
value
.
c_str
(),
ppmv
,
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
if
((
ret
=
_srs_config
->
raw_set_pithy_print_ms
(
value
,
applied
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"raw api update pithy_print_ms=%s/%d failed. ret=%d"
,
value
.
c_str
(),
ppmv
,
ret
);
return
srs_api_response_code
(
w
,
r
,
ret
);
}
}
// whether the config applied.
...
...
trunk/src/app/srs_app_log.cpp
查看文件 @
c4feb8f
...
...
@@ -86,6 +86,7 @@ SrsFastLog::SrsFastLog()
fd
=
-
1
;
log_to_file_tank
=
false
;
utc
=
false
;
}
SrsFastLog
::~
SrsFastLog
()
...
...
@@ -111,6 +112,7 @@ int SrsFastLog::initialize()
log_to_file_tank
=
_srs_config
->
get_log_tank_file
();
_level
=
srs_get_log_level
(
_srs_config
->
get_log_level
());
utc
=
_srs_config
->
get_utc_time
();
}
return
ret
;
...
...
@@ -221,6 +223,13 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...)
write_log
(
fd
,
log_data
,
size
,
SrsLogLevel
::
Error
);
}
int
SrsFastLog
::
on_reload_utc_time
()
{
utc
=
_srs_config
->
get_utc_time
();
return
ERROR_SUCCESS
;
}
int
SrsFastLog
::
on_reload_log_tank
()
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -291,7 +300,7 @@ bool SrsFastLog::generate_header(bool error, const char* tag, int context_id, co
// to calendar time
struct
tm
*
tm
;
if
(
_srs_config
&&
_srs_config
->
get_utc_time
()
)
{
if
(
utc
)
{
if
((
tm
=
gmtime
(
&
tv
.
tv_sec
))
==
NULL
)
{
return
false
;
}
...
...
trunk/src/app/srs_app_log.hpp
查看文件 @
c4feb8f
...
...
@@ -73,6 +73,8 @@ private:
int
fd
;
// whether log to file tank
bool
log_to_file_tank
;
// whether use utc time.
bool
utc
;
public
:
SrsFastLog
();
virtual
~
SrsFastLog
();
...
...
@@ -85,6 +87,7 @@ public:
virtual
void
error
(
const
char
*
tag
,
int
context_id
,
const
char
*
fmt
,
...);
// interface ISrsReloadHandler.
public:
virtual
int
on_reload_utc_time
();
virtual
int
on_reload_log_tank
();
virtual
int
on_reload_log_level
();
virtual
int
on_reload_log_file
();
...
...
trunk/src/app/srs_app_reload.cpp
查看文件 @
c4feb8f
...
...
@@ -45,6 +45,11 @@ int ISrsReloadHandler::on_reload_max_conns()
return
ERROR_SUCCESS
;
}
int
ISrsReloadHandler
::
on_reload_utc_time
()
{
return
ERROR_SUCCESS
;
}
int
ISrsReloadHandler
::
on_reload_pid
()
{
return
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_reload.hpp
查看文件 @
c4feb8f
...
...
@@ -45,6 +45,7 @@ public:
virtual
~
ISrsReloadHandler
();
public
:
virtual
int
on_reload_max_conns
();
virtual
int
on_reload_utc_time
();
virtual
int
on_reload_listen
();
virtual
int
on_reload_pid
();
virtual
int
on_reload_log_tank
();
...
...
trunk/src/app/srs_app_utility.cpp
查看文件 @
c4feb8f
...
...
@@ -1367,6 +1367,11 @@ bool srs_is_digit_number(const string& str)
return
v
/
powv
>=
1
&&
v
/
powv
<=
9
;
}
bool
srs_is_boolean
(
const
string
&
str
)
{
return
str
==
"true"
||
str
==
"false"
;
}
void
srs_api_dump_summaries
(
SrsAmf0Object
*
obj
)
{
SrsRusage
*
r
=
srs_get_system_rusage
();
...
...
trunk/src/app/srs_app_utility.hpp
查看文件 @
c4feb8f
...
...
@@ -675,6 +675,11 @@ extern std::string srs_get_peer_ip(int fd);
// is_digit("1234567890a") === false
// is_digit("a1234567890") === false
extern
bool
srs_is_digit_number
(
const
std
::
string
&
str
);
// whether string is boolean
// is_bool("true") == true
// is_bool("false") == true
// otherwise, false.
extern
bool
srs_is_boolean
(
const
std
::
string
&
str
);
// dump summaries for /api/v1/summaries.
extern
void
srs_api_dump_summaries
(
SrsAmf0Object
*
obj
);
...
...
请
注册
或
登录
后发表评论