mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
parent
60ab81a5c7
commit
ab5079909d
5 changed files with 57 additions and 4 deletions
|
@ -202,7 +202,16 @@ void SrsFastCoroutine::stop()
|
||||||
if (trd) {
|
if (trd) {
|
||||||
void* res = NULL;
|
void* res = NULL;
|
||||||
int r0 = st_thread_join((st_thread_t)trd, &res);
|
int r0 = st_thread_join((st_thread_t)trd, &res);
|
||||||
|
if (r0) {
|
||||||
|
// By st_thread_join
|
||||||
|
if (errno == EINVAL) srs_assert(!r0);
|
||||||
|
if (errno == EDEADLK) srs_assert(!r0);
|
||||||
|
// By st_cond_timedwait
|
||||||
|
if (errno == EINTR) srs_assert(!r0);
|
||||||
|
if (errno == ETIME) srs_assert(!r0);
|
||||||
|
// Others
|
||||||
srs_assert(!r0);
|
srs_assert(!r0);
|
||||||
|
}
|
||||||
|
|
||||||
srs_error_t err_res = (srs_error_t)res;
|
srs_error_t err_res = (srs_error_t)res;
|
||||||
if (err_res != srs_success) {
|
if (err_res != srs_success) {
|
||||||
|
|
|
@ -54,7 +54,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#ifndef srs_assert
|
||||||
#define srs_assert(expression) assert(expression)
|
#define srs_assert(expression) assert(expression)
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
|
@ -74,8 +74,17 @@ void srs_close_stfd(srs_netfd_t& stfd)
|
||||||
{
|
{
|
||||||
if (stfd) {
|
if (stfd) {
|
||||||
// we must ensure the close is ok.
|
// we must ensure the close is ok.
|
||||||
int err = st_netfd_close((st_netfd_t)stfd);
|
int r0 = st_netfd_close((st_netfd_t)stfd);
|
||||||
srs_assert(err != -1);
|
if (r0) {
|
||||||
|
// By _st_epoll_fd_close or _st_kq_fd_close
|
||||||
|
if (errno == EBUSY) srs_assert(!r0);
|
||||||
|
// By close
|
||||||
|
if (errno == EBADF) srs_assert(!r0);
|
||||||
|
if (errno == EINTR) srs_assert(!r0);
|
||||||
|
if (errno == EIO) srs_assert(!r0);
|
||||||
|
// Others
|
||||||
|
srs_assert(!r0);
|
||||||
|
}
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/*
|
/*
|
||||||
#include <srs_utest_reload.hpp>
|
#include <srs_utest_reload.hpp>
|
||||||
*/
|
*/
|
||||||
#include <srs_core.hpp>
|
#include <srs_utest.hpp>
|
||||||
|
|
||||||
#include <srs_utest_config.hpp>
|
#include <srs_utest_config.hpp>
|
||||||
#include <srs_app_reload.hpp>
|
#include <srs_app_reload.hpp>
|
||||||
|
|
|
@ -24,6 +24,7 @@ using namespace std;
|
||||||
#include <srs_service_conn.hpp>
|
#include <srs_service_conn.hpp>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <st.h>
|
||||||
|
|
||||||
MockSrsConnection::MockSrsConnection()
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue