1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #906, #902, use connection manager to remove connection

This commit is contained in:
winlin 2017-05-29 18:34:41 +08:00
parent 44f542f77f
commit 3ffb0980f5
6 changed files with 108 additions and 9 deletions

View file

@ -26,6 +26,58 @@
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <vector>
using namespace std;
SrsCoroutineManager::SrsCoroutineManager()
{
cond = st_cond_new();
trd = new SrsCoroutine("manager", this);
}
SrsCoroutineManager::~SrsCoroutineManager()
{
srs_freep(trd);
st_cond_destroy(cond);
clear();
}
int SrsCoroutineManager::start()
{
return trd->start();
}
int SrsCoroutineManager::cycle()
{
while (!trd->pull()) {
st_cond_wait(cond);
clear();
}
return ERROR_SUCCESS;
}
void SrsCoroutineManager::remove(ISrsConnection* c)
{
conns.push_back(c);
st_cond_signal(cond);
}
void SrsCoroutineManager::clear()
{
// To prevent thread switch when delete connection,
// we copy all connections then free one by one.
vector<ISrsConnection*> copy = conns;
conns.clear();
vector<ISrsConnection*>::iterator it;
for (it = copy.begin(); it != copy.end(); ++it) {
ISrsConnection* conn = *it;
srs_freep(conn);
}
}
ISrsOneCycleThreadHandler::ISrsOneCycleThreadHandler()
{
}