mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
support reload the removed vhost
This commit is contained in:
parent
f016914ac1
commit
e2bb38c483
13 changed files with 119 additions and 6 deletions
|
@ -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 on;
|
||||
enabled off;
|
||||
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
|
||||
engine dev {
|
||||
enabled on;
|
||||
|
|
|
@ -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.
|
||||
|
@ -113,6 +117,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()
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
@ -476,6 +490,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
|
||||
|
||||
|
@ -785,12 +839,17 @@ SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost)
|
|||
bool SrsConfig::get_vhost_enabled(string vhost)
|
||||
{
|
||||
SrsConfDirective* vhost_conf = get_vhost(vhost);
|
||||
|
||||
return get_vhost_enabled(vhost_conf);
|
||||
}
|
||||
|
||||
if (!vhost_conf) {
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -43,3 +43,8 @@ int ISrsReloadHandler::on_reload_pithy_print()
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_vhost_removed(SrsConfDirective* /*vhost*/)
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue