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
2013-12-14 22:54:10 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e2bb38c48395bd3d996fd311b82534f6490d5399
e2bb38c4
1 parent
f016914a
support reload the removed vhost
显示空白字符变更
内嵌
并排对比
正在显示
13 个修改的文件
包含
119 行增加
和
6 行删除
trunk/conf/srs.conf
trunk/src/core/srs_core_client.cpp
trunk/src/core/srs_core_client.hpp
trunk/src/core/srs_core_config.cpp
trunk/src/core/srs_core_config.hpp
trunk/src/core/srs_core_protocol.cpp
trunk/src/core/srs_core_protocol.hpp
trunk/src/core/srs_core_reload.cpp
trunk/src/core/srs_core_reload.hpp
trunk/src/core/srs_core_rtmp.cpp
trunk/src/core/srs_core_rtmp.hpp
trunk/src/core/srs_core_socket.cpp
trunk/src/core/srs_core_socket.hpp
trunk/conf/srs.conf
查看文件 @
e2bb38c
...
...
@@ -83,7 +83,7 @@ vhost __defaultVhost__ {
vhost
dev
{
enabled
on
;
gop_cache
on
;
forward
127
.
0
.
0
.
1
:
19350
;
#
forward 127.0.0.1:19350;
hls
{
hls
off
;
hls_path
./
objs
/
nginx
/
html
;
...
...
@@ -100,7 +100,7 @@ vhost dev {
on_stop
http
://
127
.
0
.
0
.
1
:
8085
/
api
/
v1
/
sessions
;
}
transcode
{
enabled
o
n
;
enabled
o
ff
;
ffmpeg
./
objs
/
ffmpeg
/
bin
/
ffmpeg
;
engine
dev
{
enabled
on
;
...
...
trunk/src/core/srs_core_client.cpp
查看文件 @
e2bb38c
...
...
@@ -55,6 +55,8 @@ SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
#ifdef SRS_HTTP
http_hooks
=
new
SrsHttpHooks
();
#endif
config
->
subscribe
(
this
);
}
SrsClient
::~
SrsClient
()
...
...
@@ -67,6 +69,8 @@ SrsClient::~SrsClient()
#ifdef SRS_HTTP
srs_freep
(
http_hooks
);
#endif
config
->
unsubscribe
(
this
);
}
// TODO: return detail message when error for client.
...
...
@@ -114,6 +118,18 @@ int SrsClient::do_cycle()
return
ret
;
}
int
SrsClient
::
on_reload_vhost_removed
(
SrsConfDirective
*
vhost
)
{
int
ret
=
ERROR_SUCCESS
;
// if the vhost connected is removed, disconnect the client.
if
(
req
->
vhost
==
vhost
->
arg0
())
{
srs_close_stfd
(
stfd
);
}
return
ret
;
}
int
SrsClient
::
service_cycle
()
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/core/srs_core_client.hpp
查看文件 @
e2bb38c
...
...
@@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp>
#include <srs_core_conn.hpp>
#include <srs_core_reload.hpp>
class
SrsRtmp
;
class
SrsRequest
;
...
...
@@ -46,7 +47,7 @@ class SrsHttpHooks;
/**
* the client provides the main logic control for RTMP clients.
*/
class
SrsClient
:
public
SrsConnection
class
SrsClient
:
public
SrsConnection
,
public
ISrsReloadHandler
{
private
:
char
*
ip
;
...
...
@@ -62,6 +63,9 @@ public:
virtual
~
SrsClient
();
protected
:
virtual
int
do_cycle
();
// interface ISrsReloadHandler
public:
virtual
int
on_reload_vhost_removed
(
SrsConfDirective
*
vhost
);
private
:
// when valid and connected to vhost/app, service the client.
virtual
int
service_cycle
();
...
...
trunk/src/core/srs_core_config.cpp
查看文件 @
e2bb38c
...
...
@@ -198,6 +198,19 @@ SrsConfDirective* SrsConfDirective::get(string _name)
return
NULL
;
}
SrsConfDirective
*
SrsConfDirective
::
get
(
string
_name
,
string
_arg0
)
{
std
::
vector
<
SrsConfDirective
*>::
iterator
it
;
for
(
it
=
directives
.
begin
();
it
!=
directives
.
end
();
++
it
)
{
SrsConfDirective
*
directive
=
*
it
;
if
(
directive
->
name
==
_name
&&
directive
->
arg0
()
==
_arg0
)
{
return
directive
;
}
}
return
NULL
;
}
int
SrsConfDirective
::
parse
(
const
char
*
filename
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -465,6 +478,7 @@ int SrsConfig::reload()
}
srs_trace
(
"reload listen success."
);
}
// merge config: pithy_print
if
(
!
srs_directive_equals
(
root
->
get
(
"pithy_print"
),
old_root
->
get
(
"pithy_print"
)))
{
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
...
...
@@ -477,6 +491,46 @@ int SrsConfig::reload()
srs_trace
(
"reload pithy_print success."
);
}
// merge config: vhost added, directly supported.
// merge config: vhost removed/disabled/modified.
for
(
int
i
=
0
;
i
<
(
int
)
old_root
->
directives
.
size
();
i
++
)
{
SrsConfDirective
*
old_vhost
=
old_root
->
at
(
i
);
// only process vhost directives.
if
(
old_vhost
->
name
!=
"vhost"
)
{
continue
;
}
SrsConfDirective
*
new_vhost
=
root
->
get
(
"vhost"
,
old_vhost
->
arg0
());
// ignore if absolutely equal
if
(
new_vhost
&&
srs_directive_equals
(
old_vhost
,
new_vhost
))
{
continue
;
}
// ignore if enable the new vhost when old vhost is disabled.
if
(
get_vhost_enabled
(
new_vhost
)
&&
!
get_vhost_enabled
(
old_vhost
))
{
continue
;
}
// ignore if both old and new vhost are disabled.
if
(
!
get_vhost_enabled
(
new_vhost
)
&&
!
get_vhost_enabled
(
old_vhost
))
{
continue
;
}
// merge config: vhost removed/disabled.
if
(
!
get_vhost_enabled
(
new_vhost
)
&&
get_vhost_enabled
(
old_vhost
))
{
srs_trace
(
"vhost %s disabled, reload it."
,
old_vhost
->
name
.
c_str
());
for
(
it
=
subscribes
.
begin
();
it
!=
subscribes
.
end
();
++
it
)
{
ISrsReloadHandler
*
subscribe
=
*
it
;
if
((
ret
=
subscribe
->
on_reload_vhost_removed
(
old_vhost
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"notify subscribes pithy_print remove vhost failed. ret=%d"
,
ret
);
return
ret
;
}
}
srs_trace
(
"reload remove vhost success."
);
}
// merge config: vhost modified.
}
// TODO: suppor reload hls/forward/ffmpeg/http
return
ret
;
...
...
@@ -786,11 +840,16 @@ bool SrsConfig::get_vhost_enabled(string vhost)
{
SrsConfDirective
*
vhost_conf
=
get_vhost
(
vhost
);
if
(
!
vhost_conf
)
{
return
true
;
return
get_vhost_enabled
(
vhost_conf
);
}
bool
SrsConfig
::
get_vhost_enabled
(
SrsConfDirective
*
vhost
)
{
if
(
!
vhost
)
{
return
false
;
}
SrsConfDirective
*
conf
=
vhost
_conf
->
get
(
"enabled"
);
SrsConfDirective
*
conf
=
vhost
->
get
(
"enabled"
);
if
(
!
conf
)
{
return
true
;
}
...
...
trunk/src/core/srs_core_config.hpp
查看文件 @
e2bb38c
...
...
@@ -74,6 +74,7 @@ public:
std
::
string
arg2
();
SrsConfDirective
*
at
(
int
index
);
SrsConfDirective
*
get
(
std
::
string
_name
);
SrsConfDirective
*
get
(
std
::
string
_name
,
std
::
string
_arg0
);
public
:
virtual
int
parse
(
const
char
*
filename
);
public
:
...
...
@@ -113,6 +114,7 @@ private:
public
:
virtual
SrsConfDirective
*
get_vhost
(
std
::
string
vhost
);
virtual
bool
get_vhost_enabled
(
std
::
string
vhost
);
virtual
bool
get_vhost_enabled
(
SrsConfDirective
*
vhost
);
virtual
SrsConfDirective
*
get_vhost_on_connect
(
std
::
string
vhost
);
virtual
SrsConfDirective
*
get_vhost_on_close
(
std
::
string
vhost
);
virtual
SrsConfDirective
*
get_vhost_on_publish
(
std
::
string
vhost
);
...
...
trunk/src/core/srs_core_protocol.cpp
查看文件 @
e2bb38c
...
...
@@ -307,6 +307,11 @@ void SrsProtocol::set_send_timeout(int64_t timeout_us)
return
skt
->
set_send_timeout
(
timeout_us
);
}
int64_t
SrsProtocol
::
get_send_timeout
()
{
return
skt
->
get_send_timeout
();
}
int64_t
SrsProtocol
::
get_recv_bytes
()
{
return
skt
->
get_recv_bytes
();
...
...
trunk/src/core/srs_core_protocol.hpp
查看文件 @
e2bb38c
...
...
@@ -115,6 +115,7 @@ public:
virtual
void
set_recv_timeout
(
int64_t
timeout_us
);
virtual
int64_t
get_recv_timeout
();
virtual
void
set_send_timeout
(
int64_t
timeout_us
);
virtual
int64_t
get_send_timeout
();
virtual
int64_t
get_recv_bytes
();
virtual
int64_t
get_send_bytes
();
virtual
int
get_recv_kbps
();
...
...
trunk/src/core/srs_core_reload.cpp
查看文件 @
e2bb38c
...
...
@@ -43,3 +43,8 @@ int ISrsReloadHandler::on_reload_pithy_print()
return
ERROR_SUCCESS
;
}
int
ISrsReloadHandler
::
on_reload_vhost_removed
(
SrsConfDirective
*
/*vhost*/
)
{
return
ERROR_SUCCESS
;
}
...
...
trunk/src/core/srs_core_reload.hpp
查看文件 @
e2bb38c
...
...
@@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_core.hpp>
class
SrsConfDirective
;
/**
* the handler for config reload.
*/
...
...
@@ -40,6 +42,7 @@ public:
public
:
virtual
int
on_reload_listen
();
virtual
int
on_reload_pithy_print
();
virtual
int
on_reload_vhost_removed
(
SrsConfDirective
*
vhost
);
};
#endif
\ No newline at end of file
...
...
trunk/src/core/srs_core_rtmp.cpp
查看文件 @
e2bb38c
...
...
@@ -231,6 +231,9 @@ int SrsRtmpClient::handshake()
SrsSocket
skt
(
stfd
);
skt
.
set_recv_timeout
(
protocol
->
get_recv_timeout
());
skt
.
set_send_timeout
(
protocol
->
get_send_timeout
());
SrsComplexHandshake
complex_hs
;
SrsSimpleHandshake
simple_hs
;
if
((
ret
=
simple_hs
.
handshake_with_server
(
skt
,
complex_hs
))
!=
ERROR_SUCCESS
)
{
...
...
@@ -422,6 +425,11 @@ void SrsRtmp::set_send_timeout(int64_t timeout_us)
protocol
->
set_send_timeout
(
timeout_us
);
}
int64_t
SrsRtmp
::
get_send_timeout
()
{
return
protocol
->
get_send_timeout
();
}
int64_t
SrsRtmp
::
get_recv_bytes
()
{
return
protocol
->
get_recv_bytes
();
...
...
@@ -458,6 +466,9 @@ int SrsRtmp::handshake()
SrsSocket
skt
(
stfd
);
skt
.
set_recv_timeout
(
protocol
->
get_recv_timeout
());
skt
.
set_send_timeout
(
protocol
->
get_send_timeout
());
SrsComplexHandshake
complex_hs
;
SrsSimpleHandshake
simple_hs
;
if
((
ret
=
simple_hs
.
handshake_with_client
(
skt
,
complex_hs
))
!=
ERROR_SUCCESS
)
{
...
...
trunk/src/core/srs_core_rtmp.hpp
查看文件 @
e2bb38c
...
...
@@ -144,6 +144,7 @@ public:
virtual
void
set_recv_timeout
(
int64_t
timeout_us
);
virtual
int64_t
get_recv_timeout
();
virtual
void
set_send_timeout
(
int64_t
timeout_us
);
virtual
int64_t
get_send_timeout
();
virtual
int64_t
get_recv_bytes
();
virtual
int64_t
get_send_bytes
();
virtual
int
get_recv_kbps
();
...
...
trunk/src/core/srs_core_socket.cpp
查看文件 @
e2bb38c
...
...
@@ -52,6 +52,11 @@ void SrsSocket::set_send_timeout(int64_t timeout_us)
send_timeout
=
timeout_us
;
}
int64_t
SrsSocket
::
get_send_timeout
()
{
return
send_timeout
;
}
int64_t
SrsSocket
::
get_recv_bytes
()
{
return
recv_bytes
;
...
...
trunk/src/core/srs_core_socket.hpp
查看文件 @
e2bb38c
...
...
@@ -50,6 +50,7 @@ public:
virtual
void
set_recv_timeout
(
int64_t
timeout_us
);
virtual
int64_t
get_recv_timeout
();
virtual
void
set_send_timeout
(
int64_t
timeout_us
);
virtual
int64_t
get_send_timeout
();
virtual
int64_t
get_recv_bytes
();
virtual
int64_t
get_send_bytes
();
virtual
int
get_recv_kbps
();
...
...
请
注册
或
登录
后发表评论