mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Log: Use string compare function
This commit is contained in:
parent
6624b8acca
commit
f551ff5ae8
6 changed files with 22 additions and 12 deletions
|
@ -373,7 +373,7 @@ srs_error_t SrsPublishRecvThread::consume(SrsCommonMessage* msg)
|
|||
srs_error_t err = srs_success;
|
||||
|
||||
// when cid changed, change it.
|
||||
if (!ncid.equals(cid)) {
|
||||
if (ncid.compare(cid)) {
|
||||
_srs_context->set_id(ncid);
|
||||
cid = ncid;
|
||||
}
|
||||
|
|
|
@ -291,13 +291,13 @@ srs_error_t SrsRtcSource::on_source_id_changed(SrsContextId id)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (_source_id.equals(id)) {
|
||||
if (!_source_id.compare(id)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (_pre_source_id.empty()) {
|
||||
_pre_source_id = id;
|
||||
} else if (!_pre_source_id.equals(_source_id)) {
|
||||
} else if (_pre_source_id.compare(_source_id)) {
|
||||
_pre_source_id = _source_id;
|
||||
}
|
||||
|
||||
|
|
|
@ -2068,13 +2068,13 @@ srs_error_t SrsSource::on_source_id_changed(SrsContextId id)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (_source_id.equals(id)) {
|
||||
if (!_source_id.compare(id)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (_pre_source_id.empty()) {
|
||||
_pre_source_id = id;
|
||||
} else if (!_pre_source_id.equals(_source_id)) {
|
||||
} else if (_pre_source_id.compare(_source_id)) {
|
||||
_pre_source_id = _source_id;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,8 +113,10 @@
|
|||
class SrsCplxError;
|
||||
typedef SrsCplxError* srs_error_t;
|
||||
|
||||
// The context ID, it default to a string object, we can also use other objects.
|
||||
#include <string>
|
||||
// The context ID, it default to a string object, we can also use other objects.
|
||||
// @remark User can directly user string as SrsContextId, we user struct to ensure the context is an object.
|
||||
#if 1
|
||||
struct _SrsContextId
|
||||
{
|
||||
std::string v_;
|
||||
|
@ -132,10 +134,18 @@ struct _SrsContextId
|
|||
bool empty() {
|
||||
return v_.empty();
|
||||
}
|
||||
bool equals(const _SrsContextId& to) {
|
||||
return v_ == to.v_;
|
||||
// Compare the two context id. @see http://www.cplusplus.com/reference/string/string/compare/
|
||||
// 0 They compare equal
|
||||
// <0 Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.
|
||||
// >0 Either the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer.
|
||||
int compare(const _SrsContextId& to) {
|
||||
return v_.compare(to.v_);
|
||||
}
|
||||
};
|
||||
typedef _SrsContextId SrsContextId;
|
||||
#else
|
||||
// Actually, we can directly user string as SrsContextId.
|
||||
typedef std::string SrsContextId;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -222,14 +222,14 @@ VOID TEST(AppCoroutineTest, Cycle)
|
|||
MockCoroutineHandler ch;
|
||||
SrsSTCoroutine sc("test", &ch, SrsContextId("250"));
|
||||
ch.trd = ≻
|
||||
EXPECT_TRUE(sc.cid().equals(SrsContextId("250")));
|
||||
EXPECT_TRUE(!sc.cid().compare(SrsContextId("250")));
|
||||
|
||||
EXPECT_TRUE(srs_success == sc.start());
|
||||
EXPECT_TRUE(srs_success == sc.pull());
|
||||
|
||||
// After running, the cid in cycle should equal to the thread.
|
||||
srs_cond_timedwait(ch.running, 100 * SRS_UTIME_MILLISECONDS);
|
||||
EXPECT_TRUE(ch.cid.equals(SrsContextId("250")));
|
||||
EXPECT_TRUE(!ch.cid.compare(SrsContextId("250")));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
|
|
|
@ -1383,8 +1383,8 @@ VOID TEST(TCPServerTest, ContextUtility)
|
|||
SrsThreadContext ctx;
|
||||
|
||||
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
|
||||
EXPECT_TRUE(ctx.set_id(SrsContextId("1000")).equals(SrsContextId("100")));
|
||||
EXPECT_TRUE(ctx.get_id().equals(SrsContextId("1000")));
|
||||
EXPECT_TRUE(!ctx.set_id(SrsContextId("1000")).compare(SrsContextId("100")));
|
||||
EXPECT_TRUE(!ctx.get_id().compare(SrsContextId("1000")));
|
||||
|
||||
ctx.clear_cid();
|
||||
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue