mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Refine generate_id, never set the cid for current thread
This commit is contained in:
parent
7052a1fafb
commit
bbc168d980
6 changed files with 13 additions and 14 deletions
|
@ -817,7 +817,7 @@ srs_error_t SrsServer::initialize_st()
|
|||
}
|
||||
|
||||
// set current log id.
|
||||
_srs_context->generate_id();
|
||||
_srs_context->set_id(_srs_context->generate_id());
|
||||
|
||||
// check asprocess.
|
||||
bool asprocess = _srs_config->get_asprocess();
|
||||
|
|
|
@ -197,11 +197,10 @@ SrsContextId SrsSTCoroutine::cid()
|
|||
srs_error_t SrsSTCoroutine::cycle()
|
||||
{
|
||||
if (_srs_context) {
|
||||
if (!cid_.empty()) {
|
||||
_srs_context->set_id(cid_);
|
||||
} else {
|
||||
if (cid_.empty()) {
|
||||
cid_ = _srs_context->generate_id();
|
||||
}
|
||||
_srs_context->set_id(cid_);
|
||||
}
|
||||
|
||||
srs_error_t err = handler->cycle();
|
||||
|
|
|
@ -80,21 +80,22 @@ public:
|
|||
// The logic context, for example, a RTMP connection, or RTC Session, etc.
|
||||
// We can grep the context id to identify the logic unit, for debugging.
|
||||
// For example:
|
||||
// _srs_context->generate_id(); // Generate a new context id.
|
||||
// _srs_context->get_id(); // Get current context id.
|
||||
// int old_id = _srs_context->set_id("1000"); // Change the context id.
|
||||
// SrsContextId cid = _srs_context->get_id(); // Get current context id.
|
||||
// SrsContextId new_cid = _srs_context->generate_id(); // Generate a new context id.
|
||||
// SrsContextId old_cid = _srs_context->set_id(new_cid); // Change the context id.
|
||||
class ISrsContext
|
||||
{
|
||||
public:
|
||||
ISrsContext();
|
||||
virtual ~ISrsContext();
|
||||
public:
|
||||
// Generate the id for current context.
|
||||
// Generate a new context id.
|
||||
// @remark We do not set to current thread, user should do this.
|
||||
virtual SrsContextId generate_id() = 0;
|
||||
// Get the generated id of current context.
|
||||
// Get the context id of current thread.
|
||||
virtual SrsContextId get_id() = 0;
|
||||
// Set the id of current context.
|
||||
// @return the previous id value; 0 if no context.
|
||||
// Set the context id of current thread.
|
||||
// @return the previous context id.
|
||||
virtual SrsContextId set_id(SrsContextId v) = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ srs_error_t do_main(int argc, char** argv)
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
// For background context id.
|
||||
_srs_context->generate_id();
|
||||
_srs_context->set_id(_srs_context->generate_id());
|
||||
|
||||
srs_error_t err = do_main(argc, argv);
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ SrsThreadContext::~SrsThreadContext()
|
|||
SrsContextId SrsThreadContext::generate_id()
|
||||
{
|
||||
SrsContextId cid = SrsContextId(srs_random_str(8));
|
||||
cache[srs_thread_self()] = cid;
|
||||
return cid;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ srs_error_t srs_st_init()
|
|||
return srs_error_new(ERROR_ST_SET_EPOLL, "st enable st failed, current is %s", st_get_eventsys_name());
|
||||
}
|
||||
|
||||
// Before ST init, we might have already inited the background cid.
|
||||
// Before ST init, we might have already initialized the background cid.
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
if (cid.empty()) {
|
||||
cid = _srs_context->generate_id();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue