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

For #2369, #1708, #1941: Check errno when close fd or stop thread

This commit is contained in:
winlin 2021-10-31 18:16:33 +08:00
parent 60ab81a5c7
commit ab5079909d
5 changed files with 57 additions and 4 deletions

View file

@ -24,6 +24,7 @@ using namespace std;
#include <srs_service_conn.hpp>
#include <sys/socket.h>
#include <netdb.h>
#include <st.h>
MockSrsConnection::MockSrsConnection()
{
@ -1452,3 +1453,35 @@ VOID TEST(TCPServerTest, ContextUtility)
}
}
class MockStopSelfThread : public ISrsCoroutineHandler
{
public:
int r0;
int r1;
SrsFastCoroutine trd;
MockStopSelfThread() : trd("mock", this), r0(0), r1(0) {
}
virtual ~MockStopSelfThread() {
}
srs_error_t start() {
return trd.start();
}
void stop() {
trd.stop();
}
virtual srs_error_t cycle() {
r0 = st_thread_join((st_thread_t)trd.trd, NULL);
r1 = errno;
return srs_success;
}
};
VOID TEST(StopSelfThreadTest, ShouldFailWhenStopSelf)
{
MockStopSelfThread trd;
trd.start();
srs_usleep(0);
EXPECT_EQ(-1, trd.r0);
EXPECT_EQ(EDEADLK, trd.r1);
}