mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine SRS_CONSTS_NO_TMMS to SRS_UTIME_NO_TIMEOUT
This commit is contained in:
parent
f8e6de71f3
commit
0879bef9b2
9 changed files with 23 additions and 28 deletions
|
@ -107,7 +107,7 @@ srs_error_t SrsRecvThread::cycle()
|
||||||
// to use isolate thread to recv, can improve about 33% performance.
|
// to use isolate thread to recv, can improve about 33% performance.
|
||||||
// @see https://github.com/ossrs/srs/issues/194
|
// @see https://github.com/ossrs/srs/issues/194
|
||||||
// @see: https://github.com/ossrs/srs/issues/217
|
// @see: https://github.com/ossrs/srs/issues/217
|
||||||
rtmp->set_recv_timeout(SRS_CONSTS_NO_TMMS);
|
rtmp->set_recv_timeout(SRS_UTIME_NO_TIMEOUT);
|
||||||
|
|
||||||
pumper->on_start();
|
pumper->on_start();
|
||||||
|
|
||||||
|
|
|
@ -64,11 +64,6 @@
|
||||||
// the following is the timeout for rtmp protocol,
|
// the following is the timeout for rtmp protocol,
|
||||||
// to avoid death connection.
|
// to avoid death connection.
|
||||||
|
|
||||||
// Never timeout in ms
|
|
||||||
// @remake Rename from SRS_CONSTS_NO_TIMEOUT
|
|
||||||
// @see ST_UTIME_NO_TIMEOUT
|
|
||||||
#define SRS_CONSTS_NO_TMMS ((int64_t) -1LL)
|
|
||||||
|
|
||||||
// the common io timeout, for connect, recv or send.
|
// the common io timeout, for connect, recv or send.
|
||||||
// TODO: FIXME: Maybe change to larger value, such as 90ms?
|
// TODO: FIXME: Maybe change to larger value, such as 90ms?
|
||||||
#define SRS_CONSTS_RTMP_TIMEOUT (30 * SRS_UTIME_MILLISECONDS)
|
#define SRS_CONSTS_RTMP_TIMEOUT (30 * SRS_UTIME_MILLISECONDS)
|
||||||
|
|
|
@ -86,7 +86,7 @@ struct SrsBlockSyncSocket
|
||||||
int64_t stm;
|
int64_t stm;
|
||||||
|
|
||||||
SrsBlockSyncSocket() {
|
SrsBlockSyncSocket() {
|
||||||
stm = rtm = SRS_CONSTS_NO_TMMS;
|
stm = rtm = SRS_UTIME_NO_TIMEOUT;
|
||||||
rbytes = sbytes = 0;
|
rbytes = sbytes = 0;
|
||||||
|
|
||||||
SOCKET_RESET(fd);
|
SOCKET_RESET(fd);
|
||||||
|
@ -191,7 +191,7 @@ int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t tm)
|
||||||
int32_t sec = 0;
|
int32_t sec = 0;
|
||||||
int32_t usec = 0;
|
int32_t usec = 0;
|
||||||
|
|
||||||
if (tm != SRS_CONSTS_NO_TMMS) {
|
if (tm != SRS_UTIME_NO_TIMEOUT) {
|
||||||
sec = (int32_t)(tm / 1000);
|
sec = (int32_t)(tm / 1000);
|
||||||
usec = (int32_t)((tm % 1000)*1000);
|
usec = (int32_t)((tm % 1000)*1000);
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t tm)
|
||||||
int32_t sec = 0;
|
int32_t sec = 0;
|
||||||
int32_t usec = 0;
|
int32_t usec = 0;
|
||||||
|
|
||||||
if (tm != SRS_CONSTS_NO_TMMS) {
|
if (tm != SRS_UTIME_NO_TIMEOUT) {
|
||||||
sec = (int32_t)(tm / 1000);
|
sec = (int32_t)(tm / 1000);
|
||||||
usec = (int32_t)((tm % 1000)*1000);
|
usec = (int32_t)((tm % 1000)*1000);
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ss
|
||||||
}
|
}
|
||||||
int srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm)
|
int srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm)
|
||||||
{
|
{
|
||||||
return tm == SRS_CONSTS_NO_TMMS;
|
return tm == SRS_UTIME_NO_TIMEOUT;
|
||||||
}
|
}
|
||||||
int srs_hijack_io_read_fully(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nread)
|
int srs_hijack_io_read_fully(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nread)
|
||||||
{
|
{
|
||||||
|
|
|
@ -129,7 +129,7 @@ struct Context
|
||||||
h264_sps_pps_sent = false;
|
h264_sps_pps_sent = false;
|
||||||
h264_sps_changed = false;
|
h264_sps_changed = false;
|
||||||
h264_pps_changed = false;
|
h264_pps_changed = false;
|
||||||
rtimeout = stimeout = SRS_CONSTS_NO_TMMS;
|
rtimeout = stimeout = SRS_UTIME_NO_TIMEOUT;
|
||||||
schema = srs_url_schema_normal;
|
schema = srs_url_schema_normal;
|
||||||
}
|
}
|
||||||
virtual ~Context() {
|
virtual ~Context() {
|
||||||
|
@ -635,11 +635,11 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp)
|
||||||
Context* context = (Context*)rtmp;
|
Context* context = (Context*)rtmp;
|
||||||
|
|
||||||
// set timeout if user not set.
|
// set timeout if user not set.
|
||||||
if (context->stimeout == SRS_CONSTS_NO_TMMS) {
|
if (context->stimeout == SRS_UTIME_NO_TIMEOUT) {
|
||||||
context->stimeout = SRS_SOCKET_DEFAULT_TMMS;
|
context->stimeout = SRS_SOCKET_DEFAULT_TMMS;
|
||||||
context->skt->set_send_timeout(context->stimeout);
|
context->skt->set_send_timeout(context->stimeout);
|
||||||
}
|
}
|
||||||
if (context->rtimeout == SRS_CONSTS_NO_TMMS) {
|
if (context->rtimeout == SRS_UTIME_NO_TIMEOUT) {
|
||||||
context->rtimeout = SRS_SOCKET_DEFAULT_TMMS;
|
context->rtimeout = SRS_SOCKET_DEFAULT_TMMS;
|
||||||
context->skt->set_recv_timeout(context->rtimeout);
|
context->skt->set_recv_timeout(context->rtimeout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public:
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Set the timeout tm in ms for recv bytes from peer.
|
* Set the timeout tm in ms for recv bytes from peer.
|
||||||
* @remark Use SRS_CONSTS_NO_TMMS to never timeout.
|
* @remark Use SRS_UTIME_NO_TIMEOUT to never timeout.
|
||||||
*/
|
*/
|
||||||
virtual void set_recv_timeout(int64_t tm) = 0;
|
virtual void set_recv_timeout(int64_t tm) = 0;
|
||||||
/**
|
/**
|
||||||
|
@ -118,7 +118,7 @@ public:
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Set the timeout tm in ms for send bytes to peer.
|
* Set the timeout tm in ms for send bytes to peer.
|
||||||
* @remark Use SRS_CONSTS_NO_TMMS to never timeout.
|
* @remark Use SRS_UTIME_NO_TIMEOUT to never timeout.
|
||||||
*/
|
*/
|
||||||
virtual void set_send_timeout(int64_t tm) = 0;
|
virtual void set_send_timeout(int64_t tm) = 0;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,7 @@ SrsHttpClient::SrsHttpClient()
|
||||||
clk = new SrsWallClock();
|
clk = new SrsWallClock();
|
||||||
kbps = new SrsKbps(clk);
|
kbps = new SrsKbps(clk);
|
||||||
parser = NULL;
|
parser = NULL;
|
||||||
timeout = SRS_CONSTS_NO_TMMS;
|
timeout = SRS_UTIME_NO_TIMEOUT;
|
||||||
port = 0;
|
port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ srs_thread_t srs_thread_self()
|
||||||
srs_error_t srs_socket_connect(string server, int port, int64_t tm, srs_netfd_t* pstfd)
|
srs_error_t srs_socket_connect(string server, int port, int64_t tm, srs_netfd_t* pstfd)
|
||||||
{
|
{
|
||||||
st_utime_t timeout = ST_UTIME_NO_TIMEOUT;
|
st_utime_t timeout = ST_UTIME_NO_TIMEOUT;
|
||||||
if (tm != SRS_CONSTS_NO_TMMS) {
|
if (tm != SRS_UTIME_NO_TIMEOUT) {
|
||||||
timeout = (st_utime_t)(tm * 1000);
|
timeout = (st_utime_t)(tm * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ ssize_t srs_read(srs_netfd_t stfd, void *buf, size_t nbyte, srs_utime_t timeout)
|
||||||
SrsStSocket::SrsStSocket()
|
SrsStSocket::SrsStSocket()
|
||||||
{
|
{
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
stm = rtm = SRS_CONSTS_NO_TMMS;
|
stm = rtm = SRS_UTIME_NO_TIMEOUT;
|
||||||
rbytes = sbytes = 0;
|
rbytes = sbytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ srs_error_t SrsStSocket::initialize(srs_netfd_t fd)
|
||||||
|
|
||||||
bool SrsStSocket::is_never_timeout(int64_t tm)
|
bool SrsStSocket::is_never_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
return tm == SRS_CONSTS_NO_TMMS;
|
return tm == SRS_UTIME_NO_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStSocket::set_recv_timeout(int64_t tm)
|
void SrsStSocket::set_recv_timeout(int64_t tm)
|
||||||
|
@ -287,7 +287,7 @@ srs_error_t SrsStSocket::read(void* buf, size_t size, ssize_t* nread)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
ssize_t nb_read;
|
ssize_t nb_read;
|
||||||
if (rtm == SRS_CONSTS_NO_TMMS) {
|
if (rtm == SRS_UTIME_NO_TIMEOUT) {
|
||||||
nb_read = st_read((st_netfd_t)stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
nb_read = st_read((st_netfd_t)stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
nb_read = st_read((st_netfd_t)stfd, buf, size, rtm * 1000);
|
nb_read = st_read((st_netfd_t)stfd, buf, size, rtm * 1000);
|
||||||
|
@ -323,7 +323,7 @@ srs_error_t SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
ssize_t nb_read;
|
ssize_t nb_read;
|
||||||
if (rtm == SRS_CONSTS_NO_TMMS) {
|
if (rtm == SRS_UTIME_NO_TIMEOUT) {
|
||||||
nb_read = st_read_fully((st_netfd_t)stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
nb_read = st_read_fully((st_netfd_t)stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
nb_read = st_read_fully((st_netfd_t)stfd, buf, size, rtm * 1000);
|
nb_read = st_read_fully((st_netfd_t)stfd, buf, size, rtm * 1000);
|
||||||
|
@ -359,7 +359,7 @@ srs_error_t SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
ssize_t nb_write;
|
ssize_t nb_write;
|
||||||
if (stm == SRS_CONSTS_NO_TMMS) {
|
if (stm == SRS_UTIME_NO_TIMEOUT) {
|
||||||
nb_write = st_write((st_netfd_t)stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
nb_write = st_write((st_netfd_t)stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
nb_write = st_write((st_netfd_t)stfd, buf, size, stm * 1000);
|
nb_write = st_write((st_netfd_t)stfd, buf, size, stm * 1000);
|
||||||
|
@ -390,7 +390,7 @@ srs_error_t SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
ssize_t nb_write;
|
ssize_t nb_write;
|
||||||
if (stm == SRS_CONSTS_NO_TMMS) {
|
if (stm == SRS_UTIME_NO_TIMEOUT) {
|
||||||
nb_write = st_writev((st_netfd_t)stfd, iov, iov_size, ST_UTIME_NO_TIMEOUT);
|
nb_write = st_writev((st_netfd_t)stfd, iov, iov_size, ST_UTIME_NO_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
nb_write = st_writev((st_netfd_t)stfd, iov, iov_size, stm * 1000);
|
nb_write = st_writev((st_netfd_t)stfd, iov, iov_size, stm * 1000);
|
||||||
|
|
|
@ -110,7 +110,7 @@ class SrsStSocket : public ISrsProtocolReadWriter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// The recv/send timeout in ms.
|
// The recv/send timeout in ms.
|
||||||
// @remark Use SRS_CONSTS_NO_TMMS for never timeout in ms.
|
// @remark Use SRS_UTIME_NO_TIMEOUT for never timeout in ms.
|
||||||
int64_t rtm;
|
int64_t rtm;
|
||||||
int64_t stm;
|
int64_t stm;
|
||||||
// The recv/send data in bytes
|
// The recv/send data in bytes
|
||||||
|
|
|
@ -98,7 +98,7 @@ srs_error_t MockEmptyIO::read(void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/
|
||||||
|
|
||||||
MockBufferIO::MockBufferIO()
|
MockBufferIO::MockBufferIO()
|
||||||
{
|
{
|
||||||
rtm = stm = SRS_CONSTS_NO_TMMS;
|
rtm = stm = SRS_UTIME_NO_TIMEOUT;
|
||||||
rbytes = sbytes = 0;
|
rbytes = sbytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ MockBufferIO* MockBufferIO::append(string data)
|
||||||
|
|
||||||
bool MockBufferIO::is_never_timeout(int64_t tm)
|
bool MockBufferIO::is_never_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
return tm == SRS_CONSTS_NO_TMMS;
|
return tm == SRS_UTIME_NO_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread)
|
srs_error_t MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread)
|
||||||
|
@ -690,8 +690,8 @@ VOID TEST(ProtocolStackTest, ProtocolTimeout)
|
||||||
MockBufferIO bio;
|
MockBufferIO bio;
|
||||||
SrsProtocol proto(&bio);
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
EXPECT_TRUE(SRS_CONSTS_NO_TMMS == proto.get_recv_timeout());
|
EXPECT_TRUE(SRS_UTIME_NO_TIMEOUT == proto.get_recv_timeout());
|
||||||
EXPECT_TRUE(SRS_CONSTS_NO_TMMS == proto.get_send_timeout());
|
EXPECT_TRUE(SRS_UTIME_NO_TIMEOUT == proto.get_send_timeout());
|
||||||
|
|
||||||
proto.set_recv_timeout(10);
|
proto.set_recv_timeout(10);
|
||||||
EXPECT_TRUE(10 == proto.get_recv_timeout());
|
EXPECT_TRUE(10 == proto.get_recv_timeout());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue