mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #742, use ms for application clock tbn.
This commit is contained in:
parent
dca9749f37
commit
3fe338d1c5
43 changed files with 437 additions and 435 deletions
|
@ -28,8 +28,8 @@ using namespace std;
|
||||||
#include <srs_kernel_error.hpp>
|
#include <srs_kernel_error.hpp>
|
||||||
#include <srs_kernel_log.hpp>
|
#include <srs_kernel_log.hpp>
|
||||||
|
|
||||||
// the sleep interval for http async callback.
|
// the sleep interval in ms for http async callback.
|
||||||
#define SRS_AUTO_ASYNC_CALLBACL_SLEEP_US 300000
|
#define SRS_AUTO_ASYNC_CALLBACL_CIMS 30
|
||||||
|
|
||||||
ISrsAsyncCallTask::ISrsAsyncCallTask()
|
ISrsAsyncCallTask::ISrsAsyncCallTask()
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ ISrsAsyncCallTask::~ISrsAsyncCallTask()
|
||||||
|
|
||||||
SrsAsyncCallWorker::SrsAsyncCallWorker()
|
SrsAsyncCallWorker::SrsAsyncCallWorker()
|
||||||
{
|
{
|
||||||
pthread = new SrsReusableThread("async", this, SRS_AUTO_ASYNC_CALLBACL_SLEEP_US);
|
pthread = new SrsReusableThread("async", this, SRS_AUTO_ASYNC_CALLBACL_CIMS);
|
||||||
wait = st_cond_new();
|
wait = st_cond_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,8 +190,8 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
|
||||||
SrsBandwidthSample publish_sample;
|
SrsBandwidthSample publish_sample;
|
||||||
|
|
||||||
// timeout for a packet.
|
// timeout for a packet.
|
||||||
_rtmp->set_send_timeout(play_sample.duration_ms * 1000 * 2);
|
_rtmp->set_send_timeout(play_sample.duration_ms * 2);
|
||||||
_rtmp->set_recv_timeout(publish_sample.duration_ms * 1000 * 2);
|
_rtmp->set_recv_timeout(publish_sample.duration_ms * 2);
|
||||||
|
|
||||||
// start test.
|
// start test.
|
||||||
srs_update_system_time_ms();
|
srs_update_system_time_ms();
|
||||||
|
|
|
@ -183,9 +183,9 @@ int SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec)
|
||||||
|
|
||||||
srs_freep(sdk);
|
srs_freep(sdk);
|
||||||
|
|
||||||
int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US;
|
int64_t cto = SRS_CONSTS_RTMP_TMMS;
|
||||||
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
|
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
|
||||||
sdk = new SrsSimpleRtmpClient(output, cto / 1000, sto / 1000);
|
sdk = new SrsSimpleRtmpClient(output, cto, sto);
|
||||||
|
|
||||||
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
||||||
srs_error("flv: connect %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", output.c_str(), cto, sto, ret);
|
srs_error("flv: connect %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", output.c_str(), cto, sto, ret);
|
||||||
|
|
|
@ -48,19 +48,16 @@ using namespace std;
|
||||||
#include <srs_app_rtmp_conn.hpp>
|
#include <srs_app_rtmp_conn.hpp>
|
||||||
|
|
||||||
// when error, edge ingester sleep for a while and retry.
|
// when error, edge ingester sleep for a while and retry.
|
||||||
#define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(3*1000*1000LL)
|
#define SRS_EDGE_INGESTER_CIMS (3*1000)
|
||||||
|
|
||||||
// when edge timeout, retry next.
|
// when edge timeout, retry next.
|
||||||
#define SRS_EDGE_INGESTER_TIMEOUT_US (int64_t)(5*1000*1000LL)
|
#define SRS_EDGE_INGESTER_TMMS (5*1000)
|
||||||
|
|
||||||
// when error, edge ingester sleep for a while and retry.
|
// when error, edge ingester sleep for a while and retry.
|
||||||
#define SRS_EDGE_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL)
|
#define SRS_EDGE_FORWARDER_CIMS (3*1000)
|
||||||
|
|
||||||
// when edge timeout, retry next.
|
|
||||||
#define SRS_EDGE_FORWARDER_TIMEOUT_US (int64_t)(5*1000*1000LL)
|
|
||||||
|
|
||||||
// when edge error, wait for quit
|
// when edge error, wait for quit
|
||||||
#define SRS_EDGE_FORWARDER_ERROR_US (int64_t)(50*1000LL)
|
#define SRS_EDGE_FORWARDER_TMMS (150)
|
||||||
|
|
||||||
SrsEdgeUpstream::SrsEdgeUpstream()
|
SrsEdgeUpstream::SrsEdgeUpstream()
|
||||||
{
|
{
|
||||||
|
@ -125,9 +122,9 @@ int SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_freep(sdk);
|
srs_freep(sdk);
|
||||||
int64_t cto = SRS_EDGE_INGESTER_TIMEOUT_US;
|
int64_t cto = SRS_EDGE_INGESTER_TMMS;
|
||||||
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
|
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
|
||||||
sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000);
|
sdk = new SrsSimpleRtmpClient(url, cto, sto);
|
||||||
|
|
||||||
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
||||||
srs_error("edge pull %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", url.c_str(), cto, sto, ret);
|
srs_error("edge pull %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", url.c_str(), cto, sto, ret);
|
||||||
|
@ -157,9 +154,9 @@ void SrsEdgeRtmpUpstream::close()
|
||||||
srs_freep(sdk);
|
srs_freep(sdk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsEdgeRtmpUpstream::set_recv_timeout(int64_t timeout)
|
void SrsEdgeRtmpUpstream::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
sdk->set_recv_timeout(timeout);
|
sdk->set_recv_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsEdgeRtmpUpstream::kbps_sample(const char* label, int64_t age)
|
void SrsEdgeRtmpUpstream::kbps_sample(const char* label, int64_t age)
|
||||||
|
@ -175,7 +172,7 @@ SrsEdgeIngester::SrsEdgeIngester()
|
||||||
|
|
||||||
upstream = new SrsEdgeRtmpUpstream(redirect);
|
upstream = new SrsEdgeRtmpUpstream(redirect);
|
||||||
lb = new SrsLbRoundRobin();
|
lb = new SrsLbRoundRobin();
|
||||||
pthread = new SrsReusableThread2("edge-igs", this, SRS_EDGE_INGESTER_SLEEP_US);
|
pthread = new SrsReusableThread2("edge-igs", this, SRS_EDGE_INGESTER_CIMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsEdgeIngester::~SrsEdgeIngester()
|
SrsEdgeIngester::~SrsEdgeIngester()
|
||||||
|
@ -274,7 +271,7 @@ int SrsEdgeIngester::ingest()
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
SrsAutoFree(SrsPithyPrint, pprint);
|
||||||
|
|
||||||
// set to larger timeout to read av data from origin.
|
// set to larger timeout to read av data from origin.
|
||||||
upstream->set_recv_timeout(SRS_EDGE_INGESTER_TIMEOUT_US);
|
upstream->set_recv_timeout(SRS_EDGE_INGESTER_TMMS);
|
||||||
|
|
||||||
while (!pthread->interrupted()) {
|
while (!pthread->interrupted()) {
|
||||||
pprint->elapse();
|
pprint->elapse();
|
||||||
|
@ -409,7 +406,7 @@ SrsEdgeForwarder::SrsEdgeForwarder()
|
||||||
|
|
||||||
sdk = NULL;
|
sdk = NULL;
|
||||||
lb = new SrsLbRoundRobin();
|
lb = new SrsLbRoundRobin();
|
||||||
pthread = new SrsReusableThread2("edge-fwr", this, SRS_EDGE_FORWARDER_SLEEP_US);
|
pthread = new SrsReusableThread2("edge-fwr", this, SRS_EDGE_FORWARDER_CIMS);
|
||||||
queue = new SrsMessageQueue();
|
queue = new SrsMessageQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,9 +462,9 @@ int SrsEdgeForwarder::start()
|
||||||
|
|
||||||
// open socket.
|
// open socket.
|
||||||
srs_freep(sdk);
|
srs_freep(sdk);
|
||||||
int64_t cto = SRS_EDGE_FORWARDER_TIMEOUT_US;
|
int64_t cto = SRS_EDGE_FORWARDER_TMMS;
|
||||||
int64_t sto = SRS_CONSTS_RTMP_TIMEOUT_US;
|
int64_t sto = SRS_CONSTS_RTMP_TMMS;
|
||||||
sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000);
|
sdk = new SrsSimpleRtmpClient(url, cto, sto);
|
||||||
|
|
||||||
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
||||||
srs_warn("edge push %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", url.c_str(), cto, sto, ret);
|
srs_warn("edge push %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", url.c_str(), cto, sto, ret);
|
||||||
|
@ -496,7 +493,7 @@ int SrsEdgeForwarder::cycle()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
|
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS);
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_edge();
|
SrsPithyPrint* pprint = SrsPithyPrint::create_edge();
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
SrsAutoFree(SrsPithyPrint, pprint);
|
||||||
|
@ -505,7 +502,7 @@ int SrsEdgeForwarder::cycle()
|
||||||
|
|
||||||
while (!pthread->interrupted()) {
|
while (!pthread->interrupted()) {
|
||||||
if (send_error_code != ERROR_SUCCESS) {
|
if (send_error_code != ERROR_SUCCESS) {
|
||||||
st_usleep(SRS_EDGE_FORWARDER_ERROR_US);
|
st_usleep(SRS_EDGE_FORWARDER_TMMS * 1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ public:
|
||||||
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0;
|
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0;
|
||||||
virtual void close() = 0;
|
virtual void close() = 0;
|
||||||
public:
|
public:
|
||||||
virtual void set_recv_timeout(int64_t timeout) = 0;
|
virtual void set_recv_timeout(int64_t tm) = 0;
|
||||||
virtual void kbps_sample(const char* label, int64_t age) = 0;
|
virtual void kbps_sample(const char* label, int64_t age) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ public:
|
||||||
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
|
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
|
||||||
virtual void close();
|
virtual void close();
|
||||||
public:
|
public:
|
||||||
virtual void set_recv_timeout(int64_t timeout);
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
virtual void kbps_sample(const char* label, int64_t age);
|
virtual void kbps_sample(const char* label, int64_t age);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,14 +37,14 @@ using namespace std;
|
||||||
#ifdef SRS_AUTO_TRANSCODE
|
#ifdef SRS_AUTO_TRANSCODE
|
||||||
|
|
||||||
// when error, encoder sleep for a while and retry.
|
// when error, encoder sleep for a while and retry.
|
||||||
#define SRS_RTMP_ENCODER_SLEEP_US (int64_t)(3*1000*1000LL)
|
#define SRS_RTMP_ENCODER_CIMS (3000)
|
||||||
|
|
||||||
// for encoder to detect the dead loop
|
// for encoder to detect the dead loop
|
||||||
static std::vector<std::string> _transcoded_url;
|
static std::vector<std::string> _transcoded_url;
|
||||||
|
|
||||||
SrsEncoder::SrsEncoder()
|
SrsEncoder::SrsEncoder()
|
||||||
{
|
{
|
||||||
pthread = new SrsReusableThread("encoder", this, SRS_RTMP_ENCODER_SLEEP_US);
|
pthread = new SrsReusableThread("encoder", this, SRS_RTMP_ENCODER_CIMS);
|
||||||
pprint = SrsPithyPrint::create_encoder();
|
pprint = SrsPithyPrint::create_encoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ using namespace std;
|
||||||
#include <srs_app_rtmp_conn.hpp>
|
#include <srs_app_rtmp_conn.hpp>
|
||||||
|
|
||||||
// when error, forwarder sleep for a while and retry.
|
// when error, forwarder sleep for a while and retry.
|
||||||
#define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL)
|
#define SRS_FORWARDER_CIMS (3000)
|
||||||
|
|
||||||
SrsForwarder::SrsForwarder(SrsSource* s)
|
SrsForwarder::SrsForwarder(SrsSource* s)
|
||||||
{
|
{
|
||||||
|
@ -58,7 +58,7 @@ SrsForwarder::SrsForwarder(SrsSource* s)
|
||||||
sh_video = sh_audio = NULL;
|
sh_video = sh_audio = NULL;
|
||||||
|
|
||||||
sdk = NULL;
|
sdk = NULL;
|
||||||
pthread = new SrsReusableThread2("forward", this, SRS_FORWARDER_SLEEP_US);
|
pthread = new SrsReusableThread2("forward", this, SRS_FORWARDER_CIMS);
|
||||||
queue = new SrsMessageQueue();
|
queue = new SrsMessageQueue();
|
||||||
jitter = new SrsRtmpJitter();
|
jitter = new SrsRtmpJitter();
|
||||||
}
|
}
|
||||||
|
@ -237,8 +237,8 @@ int SrsForwarder::cycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_freep(sdk);
|
srs_freep(sdk);
|
||||||
int64_t cto = SRS_FORWARDER_SLEEP_US;
|
int64_t cto = SRS_FORWARDER_CIMS;
|
||||||
int64_t sto = SRS_CONSTS_RTMP_TIMEOUT_US;
|
int64_t sto = SRS_CONSTS_RTMP_TMMS;
|
||||||
sdk = new SrsSimpleRtmpClient(url, cto, sto);
|
sdk = new SrsSimpleRtmpClient(url, cto, sto);
|
||||||
|
|
||||||
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
||||||
|
@ -267,7 +267,7 @@ int SrsForwarder::forward()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
|
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS);
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_forwarder();
|
SrsPithyPrint* pprint = SrsPithyPrint::create_forwarder();
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
SrsAutoFree(SrsPithyPrint, pprint);
|
||||||
|
|
|
@ -1365,7 +1365,7 @@ int SrsHttpApi::do_cycle()
|
||||||
|
|
||||||
// set the recv timeout, for some clients never disconnect the connection.
|
// set the recv timeout, for some clients never disconnect the connection.
|
||||||
// @see https://github.com/ossrs/srs/issues/398
|
// @see https://github.com/ossrs/srs/issues/398
|
||||||
skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US);
|
skt.set_recv_timeout(SRS_HTTP_RECV_TMMS);
|
||||||
|
|
||||||
// initialize the cors, which will proxy to mux.
|
// initialize the cors, which will proxy to mux.
|
||||||
bool crossdomain_enabled = _srs_config->get_http_api_crossdomain();
|
bool crossdomain_enabled = _srs_config->get_http_api_crossdomain();
|
||||||
|
|
|
@ -43,7 +43,7 @@ SrsHttpClient::SrsHttpClient()
|
||||||
transport = NULL;
|
transport = NULL;
|
||||||
kbps = new SrsKbps();
|
kbps = new SrsKbps();
|
||||||
parser = NULL;
|
parser = NULL;
|
||||||
timeout_us = 0;
|
timeout = SRS_CONSTS_NO_TMMS;
|
||||||
port = 0;
|
port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ SrsHttpClient::~SrsHttpClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: use ms for timeout.
|
// TODO: FIXME: use ms for timeout.
|
||||||
int SrsHttpClient::initialize(string h, int p, int64_t t_us)
|
int SrsHttpClient::initialize(string h, int p, int64_t tm)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us)
|
||||||
// Always disconnect the transport.
|
// Always disconnect the transport.
|
||||||
host = h;
|
host = h;
|
||||||
port = p;
|
port = p;
|
||||||
timeout_us = t_us;
|
timeout = tm;
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
// ep used for host in header.
|
// ep used for host in header.
|
||||||
|
@ -196,9 +196,9 @@ int SrsHttpClient::get(string path, string req, ISrsHttpMessage** ppmsg)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsHttpClient::set_recv_timeout(int64_t timeout)
|
void SrsHttpClient::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
transport->set_recv_timeout(timeout);
|
transport->set_recv_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsHttpClient::kbps_sample(const char* label, int64_t age)
|
void SrsHttpClient::kbps_sample(const char* label, int64_t age)
|
||||||
|
@ -232,17 +232,17 @@ int SrsHttpClient::connect()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
transport = new SrsTcpClient(host, port, timeout_us / 1000);
|
transport = new SrsTcpClient(host, port, timeout);
|
||||||
if ((ret = transport->connect()) != ERROR_SUCCESS) {
|
if ((ret = transport->connect()) != ERROR_SUCCESS) {
|
||||||
disconnect();
|
disconnect();
|
||||||
srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d", host.c_str(), port, timeout_us, ret);
|
srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d", host.c_str(), port, timeout, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_info("connect to server success. server=%s, port=%d", host.c_str(), port);
|
srs_info("connect to server success. server=%s, port=%d", host.c_str(), port);
|
||||||
|
|
||||||
// set the recv/send timeout in us.
|
// Set the recv/send timeout in ms.
|
||||||
transport->set_recv_timeout(timeout_us);
|
transport->set_recv_timeout(timeout);
|
||||||
transport->set_send_timeout(timeout_us);
|
transport->set_send_timeout(timeout);
|
||||||
|
|
||||||
kbps->set_io(transport, transport);
|
kbps->set_io(transport, transport);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ class SrsStSocket;
|
||||||
class SrsKbps;
|
class SrsKbps;
|
||||||
|
|
||||||
// the default timeout for http client.
|
// the default timeout for http client.
|
||||||
#define SRS_HTTP_CLIENT_TIMEOUT_US (int64_t)(30*1000*1000LL)
|
#define SRS_HTTP_CLIENT_TMMS (30*1000)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client to GET/POST/PUT/DELETE over HTTP.
|
* The client to GET/POST/PUT/DELETE over HTTP.
|
||||||
|
@ -64,8 +64,9 @@ private:
|
||||||
std::map<std::string, std::string> headers;
|
std::map<std::string, std::string> headers;
|
||||||
SrsKbps* kbps;
|
SrsKbps* kbps;
|
||||||
private:
|
private:
|
||||||
int64_t timeout_us;
|
// The timeout in ms.
|
||||||
// host name or ip.
|
int64_t timeout;
|
||||||
|
// The host name or ip.
|
||||||
std::string host;
|
std::string host;
|
||||||
int port;
|
int port;
|
||||||
public:
|
public:
|
||||||
|
@ -74,9 +75,10 @@ public:
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Initliaze the client, disconnect the transport, renew the HTTP parser.
|
* Initliaze the client, disconnect the transport, renew the HTTP parser.
|
||||||
|
* @param tm The underlayer TCP transport timeout in ms.
|
||||||
* @remark we will set default values in headers, which can be override by set_header.
|
* @remark we will set default values in headers, which can be override by set_header.
|
||||||
*/
|
*/
|
||||||
virtual int initialize(std::string h, int p, int64_t t_us = SRS_HTTP_CLIENT_TIMEOUT_US);
|
virtual int initialize(std::string h, int p, int64_t tm = SRS_HTTP_CLIENT_TMMS);
|
||||||
/**
|
/**
|
||||||
* Set HTTP request header in header[k]=v.
|
* Set HTTP request header in header[k]=v.
|
||||||
* @return the HTTP client itself.
|
* @return the HTTP client itself.
|
||||||
|
@ -99,8 +101,9 @@ public:
|
||||||
* @remark user must free the ppmsg if not NULL.
|
* @remark user must free the ppmsg if not NULL.
|
||||||
*/
|
*/
|
||||||
virtual int get(std::string path, std::string req, ISrsHttpMessage** ppmsg);
|
virtual int get(std::string path, std::string req, ISrsHttpMessage** ppmsg);
|
||||||
|
private:
|
||||||
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
public:
|
public:
|
||||||
virtual void set_recv_timeout(int64_t timeout);
|
|
||||||
virtual void kbps_sample(const char* label, int64_t age);
|
virtual void kbps_sample(const char* label, int64_t age);
|
||||||
private:
|
private:
|
||||||
virtual void disconnect();
|
virtual void disconnect();
|
||||||
|
|
|
@ -1137,7 +1137,7 @@ int SrsHttpConn::do_cycle()
|
||||||
|
|
||||||
// set the recv timeout, for some clients never disconnect the connection.
|
// set the recv timeout, for some clients never disconnect the connection.
|
||||||
// @see https://github.com/ossrs/srs/issues/398
|
// @see https://github.com/ossrs/srs/issues/398
|
||||||
skt->set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US);
|
skt->set_recv_timeout(SRS_HTTP_RECV_TMMS);
|
||||||
|
|
||||||
SrsRequest* last_req = NULL;
|
SrsRequest* last_req = NULL;
|
||||||
SrsAutoFree(SrsRequest, last_req);
|
SrsAutoFree(SrsRequest, last_req);
|
||||||
|
|
|
@ -43,12 +43,12 @@ using namespace std;
|
||||||
|
|
||||||
#define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS)
|
#define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS)
|
||||||
|
|
||||||
#define SRS_HTTP_HEADER_BUFFER 1024
|
#define SRS_HTTP_HEADER_BUFFER 1024
|
||||||
#define SRS_HTTP_READ_BUFFER 4096
|
#define SRS_HTTP_READ_BUFFER 4096
|
||||||
#define SRS_HTTP_BODY_BUFFER 32 * 1024
|
#define SRS_HTTP_BODY_BUFFER (32 * 1024)
|
||||||
|
|
||||||
// the timeout for hls notify, in us.
|
// the timeout for hls notify, in ms.
|
||||||
#define SRS_HLS_NOTIFY_TIMEOUT_US (int64_t)(10*1000*1000LL)
|
#define SRS_HLS_NOTIFY_TMMS (10 * 1000)
|
||||||
|
|
||||||
SrsHttpHooks::SrsHttpHooks()
|
SrsHttpHooks::SrsHttpHooks()
|
||||||
{
|
{
|
||||||
|
@ -383,7 +383,7 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHttpClient http;
|
SrsHttpClient http;
|
||||||
if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TIMEOUT_US)) != ERROR_SUCCESS) {
|
if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TMMS)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,9 +155,9 @@ int SrsBufferCache::cycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
|
srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TMMS);
|
||||||
// directly use sleep, donot use consumer wait.
|
// directly use sleep, donot use consumer wait.
|
||||||
st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
|
st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS * 1000);
|
||||||
|
|
||||||
// ignore when nothing got.
|
// ignore when nothing got.
|
||||||
continue;
|
continue;
|
||||||
|
@ -165,7 +165,7 @@ int SrsBufferCache::cycle()
|
||||||
|
|
||||||
if (pprint->can_print()) {
|
if (pprint->can_print()) {
|
||||||
srs_trace("-> "SRS_CONSTS_LOG_HTTP_STREAM_CACHE" http: got %d msgs, age=%d, min=%d, mw=%d",
|
srs_trace("-> "SRS_CONSTS_LOG_HTTP_STREAM_CACHE" http: got %d msgs, age=%d, min=%d, mw=%d",
|
||||||
count, pprint->age(), SRS_PERF_MW_MIN_MSGS, SRS_CONSTS_RTMP_PULSE_TIMEOUT_US / 1000);
|
count, pprint->age(), SRS_PERF_MW_MIN_MSGS, SRS_CONSTS_RTMP_PULSE_TMMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// free the messages.
|
// free the messages.
|
||||||
|
@ -557,9 +557,9 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
|
srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TMMS);
|
||||||
// directly use sleep, donot use consumer wait.
|
// directly use sleep, donot use consumer wait.
|
||||||
st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
|
st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS);
|
||||||
|
|
||||||
// ignore when nothing got.
|
// ignore when nothing got.
|
||||||
continue;
|
continue;
|
||||||
|
@ -567,7 +567,7 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
|
|
||||||
if (pprint->can_print()) {
|
if (pprint->can_print()) {
|
||||||
srs_info("-> "SRS_CONSTS_LOG_HTTP_STREAM" http: got %d msgs, age=%d, min=%d, mw=%d",
|
srs_info("-> "SRS_CONSTS_LOG_HTTP_STREAM" http: got %d msgs, age=%d, min=%d, mw=%d",
|
||||||
count, pprint->age(), SRS_PERF_MW_MIN_MSGS, SRS_CONSTS_RTMP_PULSE_TIMEOUT_US / 1000);
|
count, pprint->age(), SRS_PERF_MW_MIN_MSGS, SRS_CONSTS_RTMP_PULSE_TMMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendout all messages.
|
// sendout all messages.
|
||||||
|
|
|
@ -39,7 +39,7 @@ using namespace std;
|
||||||
|
|
||||||
// when error, ingester sleep for a while and retry.
|
// when error, ingester sleep for a while and retry.
|
||||||
// ingest never sleep a long time, for we must start the stream ASAP.
|
// ingest never sleep a long time, for we must start the stream ASAP.
|
||||||
#define SRS_AUTO_INGESTER_SLEEP_US (int64_t)(3*1000*1000LL)
|
#define SRS_AUTO_INGESTER_CIMS (3000)
|
||||||
|
|
||||||
SrsIngesterFFMPEG::SrsIngesterFFMPEG()
|
SrsIngesterFFMPEG::SrsIngesterFFMPEG()
|
||||||
{
|
{
|
||||||
|
@ -109,7 +109,7 @@ SrsIngester::SrsIngester()
|
||||||
|
|
||||||
expired = false;
|
expired = false;
|
||||||
|
|
||||||
pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US);
|
pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_CIMS);
|
||||||
pprint = SrsPithyPrint::create_ingester();
|
pprint = SrsPithyPrint::create_ingester();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ using namespace std;
|
||||||
|
|
||||||
#ifdef SRS_AUTO_KAFKA
|
#ifdef SRS_AUTO_KAFKA
|
||||||
|
|
||||||
#define SRS_KAKFA_CYCLE_INTERVAL_MS 3000
|
#define SRS_KAKFA_CIMS 3000
|
||||||
#define SRS_KAFKA_PRODUCER_TIMEOUT 30000
|
#define SRS_KAFKA_PRODUCER_TIMEOUT 30000
|
||||||
#define SRS_KAFKA_PRODUCER_AGGREGATE_SIZE 1
|
#define SRS_KAFKA_PRODUCER_AGGREGATE_SIZE 1
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ SrsKafkaProducer::SrsKafkaProducer()
|
||||||
metadata_expired = st_cond_new();
|
metadata_expired = st_cond_new();
|
||||||
|
|
||||||
lock = st_mutex_new();
|
lock = st_mutex_new();
|
||||||
pthread = new SrsReusableThread("kafka", this, SRS_KAKFA_CYCLE_INTERVAL_MS * 1000);
|
pthread = new SrsReusableThread("kafka", this, SRS_KAKFA_CIMS);
|
||||||
worker = new SrsAsyncCallWorker();
|
worker = new SrsAsyncCallWorker();
|
||||||
cache = new SrsKafkaCache();
|
cache = new SrsKafkaCache();
|
||||||
|
|
||||||
|
@ -585,7 +585,7 @@ int SrsKafkaProducer::request_metadata()
|
||||||
senabled.c_str(), sbrokers.c_str(), lb->current(), server.c_str(), port, topic.c_str());
|
senabled.c_str(), sbrokers.c_str(), lb->current(), server.c_str(), port, topic.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_CONSTS_KAFKA_TIMEOUT_US / 1000);
|
SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_CONSTS_KAFKA_TMMS);
|
||||||
SrsAutoFree(SrsTcpClient, transport);
|
SrsAutoFree(SrsTcpClient, transport);
|
||||||
|
|
||||||
SrsKafkaClient* kafka = new SrsKafkaClient(transport);
|
SrsKafkaClient* kafka = new SrsKafkaClient(transport);
|
||||||
|
|
|
@ -616,9 +616,9 @@ int SrsMpegtsOverUdp::connect()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US;
|
int64_t cto = SRS_CONSTS_RTMP_TMMS;
|
||||||
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
|
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
|
||||||
sdk = new SrsSimpleRtmpClient(output, cto/1000, sto/1000);
|
sdk = new SrsSimpleRtmpClient(output, cto, sto);
|
||||||
|
|
||||||
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -37,11 +37,11 @@ using namespace std;
|
||||||
#include <srs_protocol_utility.hpp>
|
#include <srs_protocol_utility.hpp>
|
||||||
|
|
||||||
// when error, ng-exec sleep for a while and retry.
|
// when error, ng-exec sleep for a while and retry.
|
||||||
#define SRS_RTMP_EXEC_SLEEP_US (int64_t)(3*1000*1000LL)
|
#define SRS_RTMP_EXEC_CIMS (3000)
|
||||||
|
|
||||||
SrsNgExec::SrsNgExec()
|
SrsNgExec::SrsNgExec()
|
||||||
{
|
{
|
||||||
pthread = new SrsReusableThread("encoder", this, SRS_RTMP_EXEC_SLEEP_US);
|
pthread = new SrsReusableThread("encoder", this, SRS_RTMP_EXEC_CIMS);
|
||||||
pprint = SrsPithyPrint::create_exec();
|
pprint = SrsPithyPrint::create_exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,9 @@ ISrsMessageHandler::~ISrsMessageHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRecvThread::SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk, int timeout_ms)
|
SrsRecvThread::SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk, int tm)
|
||||||
{
|
{
|
||||||
timeout = timeout_ms;
|
timeout = tm;
|
||||||
handler = msg_handler;
|
handler = msg_handler;
|
||||||
rtmp = rtmp_sdk;
|
rtmp = rtmp_sdk;
|
||||||
trd = new SrsReusableThread2("recv", this);
|
trd = new SrsReusableThread2("recv", this);
|
||||||
|
@ -126,7 +126,7 @@ void SrsRecvThread::on_thread_start()
|
||||||
// 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(ST_UTIME_NO_TIMEOUT);
|
rtmp->set_recv_timeout(SRS_CONSTS_NO_TMMS);
|
||||||
|
|
||||||
handler->on_thread_start();
|
handler->on_thread_start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,9 +86,12 @@ protected:
|
||||||
SrsReusableThread2* trd;
|
SrsReusableThread2* trd;
|
||||||
ISrsMessageHandler* handler;
|
ISrsMessageHandler* handler;
|
||||||
SrsRtmpServer* rtmp;
|
SrsRtmpServer* rtmp;
|
||||||
|
// The recv timeout in ms.
|
||||||
int timeout;
|
int timeout;
|
||||||
public:
|
public:
|
||||||
SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk, int timeout_ms);
|
// Constructor.
|
||||||
|
// @param tm The receive timeout in ms.
|
||||||
|
SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk, int tm);
|
||||||
virtual ~SrsRecvThread();
|
virtual ~SrsRecvThread();
|
||||||
public:
|
public:
|
||||||
virtual int cid();
|
virtual int cid();
|
||||||
|
|
|
@ -60,22 +60,22 @@ using namespace std;
|
||||||
// when stream is busy, for example, streaming is already
|
// when stream is busy, for example, streaming is already
|
||||||
// publishing, when a new client to request to publish,
|
// publishing, when a new client to request to publish,
|
||||||
// sleep a while and close the connection.
|
// sleep a while and close the connection.
|
||||||
#define SRS_STREAM_BUSY_SLEEP_US (int64_t)(3*1000*1000LL)
|
#define SRS_STREAM_BUSY_CIMS (3000)
|
||||||
|
|
||||||
// the timeout to wait encoder to republish
|
// the timeout in ms to wait encoder to republish
|
||||||
// if timeout, close the connection.
|
// if timeout, close the connection.
|
||||||
#define SRS_REPUBLISH_SEND_TIMEOUT_US (int64_t)(3*60*1000*1000LL)
|
#define SRS_REPUBLISH_SEND_TMMS (3 * 60 * 1000)
|
||||||
// if timeout, close the connection.
|
// if timeout, close the connection.
|
||||||
#define SRS_REPUBLISH_RECV_TIMEOUT_US (int64_t)(3*60*1000*1000LL)
|
#define SRS_REPUBLISH_RECV_TMMS (3 * 60 * 1000)
|
||||||
|
|
||||||
// the timeout to wait client data, when client paused
|
// the timeout in ms to wait client data, when client paused
|
||||||
// if timeout, close the connection.
|
// if timeout, close the connection.
|
||||||
#define SRS_PAUSED_SEND_TIMEOUT_US (int64_t)(30*60*1000*1000LL)
|
#define SRS_PAUSED_SEND_TMMS (3 * 60 * 1000)
|
||||||
// if timeout, close the connection.
|
// if timeout, close the connection.
|
||||||
#define SRS_PAUSED_RECV_TIMEOUT_US (int64_t)(30*60*1000*1000LL)
|
#define SRS_PAUSED_RECV_TMMS (3 * 60 * 1000)
|
||||||
|
|
||||||
// when edge timeout, retry next.
|
// when edge timeout, retry next.
|
||||||
#define SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT_US (int64_t)(3*1000*1000LL)
|
#define SRS_EDGE_TOKEN_TRAVERSE_TMMS (3000)
|
||||||
|
|
||||||
SrsSimpleRtmpClient::SrsSimpleRtmpClient(string u, int64_t ctm, int64_t stm)
|
SrsSimpleRtmpClient::SrsSimpleRtmpClient(string u, int64_t ctm, int64_t stm)
|
||||||
{
|
{
|
||||||
|
@ -348,8 +348,8 @@ int SrsRtmpConn::do_cycle()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
|
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TMMS);
|
||||||
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
|
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS);
|
||||||
|
|
||||||
if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {
|
if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {
|
||||||
srs_error("rtmp handshake failed. ret=%d", ret);
|
srs_error("rtmp handshake failed. ret=%d", ret);
|
||||||
|
@ -634,8 +634,8 @@ int SrsRtmpConn::service_cycle()
|
||||||
// for republish, continue service
|
// for republish, continue service
|
||||||
if (ret == ERROR_CONTROL_REPUBLISH) {
|
if (ret == ERROR_CONTROL_REPUBLISH) {
|
||||||
// set timeout to a larger value, wait for encoder to republish.
|
// set timeout to a larger value, wait for encoder to republish.
|
||||||
rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TIMEOUT_US);
|
rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TMMS);
|
||||||
rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TIMEOUT_US);
|
rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TMMS);
|
||||||
|
|
||||||
srs_trace("control message(unpublish) accept, retry stream service.");
|
srs_trace("control message(unpublish) accept, retry stream service.");
|
||||||
continue;
|
continue;
|
||||||
|
@ -647,8 +647,8 @@ int SrsRtmpConn::service_cycle()
|
||||||
// TODO: FIXME: use ping message to anti-death of socket.
|
// TODO: FIXME: use ping message to anti-death of socket.
|
||||||
// @see: https://github.com/ossrs/srs/issues/39
|
// @see: https://github.com/ossrs/srs/issues/39
|
||||||
// set timeout to a larger value, for user paused.
|
// set timeout to a larger value, for user paused.
|
||||||
rtmp->set_recv_timeout(SRS_PAUSED_RECV_TIMEOUT_US);
|
rtmp->set_recv_timeout(SRS_PAUSED_RECV_TMMS);
|
||||||
rtmp->set_send_timeout(SRS_PAUSED_SEND_TIMEOUT_US);
|
rtmp->set_send_timeout(SRS_PAUSED_SEND_TMMS);
|
||||||
|
|
||||||
srs_trace("control message(close) accept, retry stream service.");
|
srs_trace("control message(close) accept, retry stream service.");
|
||||||
continue;
|
continue;
|
||||||
|
@ -685,8 +685,8 @@ int SrsRtmpConn::stream_service_cycle()
|
||||||
srs_info("security check ok");
|
srs_info("security check ok");
|
||||||
|
|
||||||
// client is identified, set the timeout to service timeout.
|
// client is identified, set the timeout to service timeout.
|
||||||
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
|
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TMMS);
|
||||||
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
|
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS);
|
||||||
|
|
||||||
// find a source to serve.
|
// find a source to serve.
|
||||||
SrsSource* source = NULL;
|
SrsSource* source = NULL;
|
||||||
|
@ -1465,7 +1465,7 @@ int SrsRtmpConn::check_edge_token_traverse_auth()
|
||||||
int port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
int port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||||
srs_parse_hostport(hostport, server, port);
|
srs_parse_hostport(hostport, server, port);
|
||||||
|
|
||||||
SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT_US / 1000);
|
SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_EDGE_TOKEN_TRAVERSE_TMMS);
|
||||||
SrsAutoFree(SrsTcpClient, transport);
|
SrsAutoFree(SrsTcpClient, transport);
|
||||||
|
|
||||||
if ((ret = transport->connect()) != ERROR_SUCCESS) {
|
if ((ret = transport->connect()) != ERROR_SUCCESS) {
|
||||||
|
@ -1490,8 +1490,8 @@ int SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client)
|
||||||
|
|
||||||
srs_assert(client);
|
srs_assert(client);
|
||||||
|
|
||||||
client->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
|
client->set_recv_timeout(SRS_CONSTS_RTMP_TMMS);
|
||||||
client->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
|
client->set_send_timeout(SRS_CONSTS_RTMP_TMMS);
|
||||||
|
|
||||||
if ((ret = client->handshake()) != ERROR_SUCCESS) {
|
if ((ret = client->handshake()) != ERROR_SUCCESS) {
|
||||||
srs_error("handshake with server failed. ret=%d", ret);
|
srs_error("handshake with server failed. ret=%d", ret);
|
||||||
|
|
|
@ -669,9 +669,9 @@ int SrsRtspConn::connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect host.
|
// connect host.
|
||||||
int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US;
|
int64_t cto = SRS_CONSTS_RTMP_TMMS;
|
||||||
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
|
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
|
||||||
sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000);
|
sdk = new SrsSimpleRtmpClient(url, cto, sto);
|
||||||
|
|
||||||
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -62,7 +62,6 @@ using namespace std;
|
||||||
|
|
||||||
// update time interval:
|
// update time interval:
|
||||||
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES
|
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES
|
||||||
// @see SYS_TIME_RESOLUTION_US
|
|
||||||
#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 1
|
#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 1
|
||||||
|
|
||||||
// update rusage interval:
|
// update rusage interval:
|
||||||
|
|
|
@ -538,7 +538,7 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count)
|
||||||
void SrsConsumer::wait(int nb_msgs, int duration)
|
void SrsConsumer::wait(int nb_msgs, int duration)
|
||||||
{
|
{
|
||||||
if (paused) {
|
if (paused) {
|
||||||
st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
|
st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,11 +61,11 @@ namespace internal
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsThread::SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable)
|
SrsThread::SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t ims, bool joinable)
|
||||||
{
|
{
|
||||||
_name = name;
|
_name = name;
|
||||||
handler = thread_handler;
|
handler = thread_handler;
|
||||||
cycle_interval_us = interval_us;
|
cims = ims;
|
||||||
|
|
||||||
tid = NULL;
|
tid = NULL;
|
||||||
loop = false;
|
loop = false;
|
||||||
|
@ -231,10 +231,11 @@ namespace internal
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should never use no timeout, just ignore it.
|
||||||
// to improve performance, donot sleep when interval is zero.
|
// to improve performance, donot sleep when interval is zero.
|
||||||
// @see: https://github.com/ossrs/srs/issues/237
|
// @see: https://github.com/ossrs/srs/issues/237
|
||||||
if (cycle_interval_us != 0) {
|
if (cims != 0 && cims != SRS_CONSTS_NO_TMMS) {
|
||||||
st_usleep(cycle_interval_us);
|
st_usleep(cims * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,54 +269,60 @@ namespace internal
|
||||||
SrsStSocket::SrsStSocket(st_netfd_t client_stfd)
|
SrsStSocket::SrsStSocket(st_netfd_t client_stfd)
|
||||||
{
|
{
|
||||||
stfd = client_stfd;
|
stfd = client_stfd;
|
||||||
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
|
stm = rtm = SRS_CONSTS_NO_TMMS;
|
||||||
recv_bytes = send_bytes = 0;
|
rbytes = sbytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsStSocket::~SrsStSocket()
|
SrsStSocket::~SrsStSocket()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsStSocket::is_never_timeout(int64_t timeout_us)
|
bool SrsStSocket::is_never_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
return timeout_us == (int64_t)ST_UTIME_NO_TIMEOUT;
|
return tm == SRS_CONSTS_NO_TMMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStSocket::set_recv_timeout(int64_t timeout_us)
|
void SrsStSocket::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
recv_timeout = timeout_us;
|
rtm = tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsStSocket::get_recv_timeout()
|
int64_t SrsStSocket::get_recv_timeout()
|
||||||
{
|
{
|
||||||
return recv_timeout;
|
return rtm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStSocket::set_send_timeout(int64_t timeout_us)
|
void SrsStSocket::set_send_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
send_timeout = timeout_us;
|
stm = tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsStSocket::get_send_timeout()
|
int64_t SrsStSocket::get_send_timeout()
|
||||||
{
|
{
|
||||||
return send_timeout;
|
return stm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsStSocket::get_recv_bytes()
|
int64_t SrsStSocket::get_recv_bytes()
|
||||||
{
|
{
|
||||||
return recv_bytes;
|
return rbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsStSocket::get_send_bytes()
|
int64_t SrsStSocket::get_send_bytes()
|
||||||
{
|
{
|
||||||
return send_bytes;
|
return sbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsStSocket::read(void* buf, size_t size, ssize_t* nread)
|
int SrsStSocket::read(void* buf, size_t size, ssize_t* nread)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
ssize_t nb_read = st_read(stfd, buf, size, recv_timeout);
|
ssize_t nb_read;
|
||||||
|
if (rtm == SRS_CONSTS_NO_TMMS) {
|
||||||
|
nb_read = st_read(stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
||||||
|
} else {
|
||||||
|
nb_read = st_read(stfd, buf, size, rtm);
|
||||||
|
}
|
||||||
|
|
||||||
if (nread) {
|
if (nread) {
|
||||||
*nread = nb_read;
|
*nread = nb_read;
|
||||||
}
|
}
|
||||||
|
@ -336,7 +343,7 @@ int SrsStSocket::read(void* buf, size_t size, ssize_t* nread)
|
||||||
return ERROR_SOCKET_READ;
|
return ERROR_SOCKET_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv_bytes += nb_read;
|
rbytes += nb_read;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -345,7 +352,13 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
ssize_t nb_read = st_read_fully(stfd, buf, size, recv_timeout);
|
ssize_t nb_read;
|
||||||
|
if (rtm == SRS_CONSTS_NO_TMMS) {
|
||||||
|
nb_read = st_read_fully(stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
||||||
|
} else {
|
||||||
|
nb_read = st_read_fully(stfd, buf, size, rtm);
|
||||||
|
}
|
||||||
|
|
||||||
if (nread) {
|
if (nread) {
|
||||||
*nread = nb_read;
|
*nread = nb_read;
|
||||||
}
|
}
|
||||||
|
@ -366,7 +379,7 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread)
|
||||||
return ERROR_SOCKET_READ_FULLY;
|
return ERROR_SOCKET_READ_FULLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv_bytes += nb_read;
|
rbytes += nb_read;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -375,7 +388,13 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
ssize_t nb_write = st_write(stfd, buf, size, send_timeout);
|
ssize_t nb_write;
|
||||||
|
if (stm == SRS_CONSTS_NO_TMMS) {
|
||||||
|
nb_write = st_write(stfd, buf, size, ST_UTIME_NO_TIMEOUT);
|
||||||
|
} else {
|
||||||
|
nb_write = st_write(stfd, buf, size, stm);
|
||||||
|
}
|
||||||
|
|
||||||
if (nwrite) {
|
if (nwrite) {
|
||||||
*nwrite = nb_write;
|
*nwrite = nb_write;
|
||||||
}
|
}
|
||||||
|
@ -391,7 +410,7 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite)
|
||||||
return ERROR_SOCKET_WRITE;
|
return ERROR_SOCKET_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_bytes += nb_write;
|
sbytes += nb_write;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -400,7 +419,13 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
ssize_t nb_write = st_writev(stfd, iov, iov_size, send_timeout);
|
ssize_t nb_write;
|
||||||
|
if (stm == SRS_CONSTS_NO_TMMS) {
|
||||||
|
nb_write = st_writev(stfd, iov, iov_size, ST_UTIME_NO_TIMEOUT);
|
||||||
|
} else {
|
||||||
|
nb_write = st_writev(stfd, iov, iov_size, stm);
|
||||||
|
}
|
||||||
|
|
||||||
if (nwrite) {
|
if (nwrite) {
|
||||||
*nwrite = nb_write;
|
*nwrite = nb_write;
|
||||||
}
|
}
|
||||||
|
@ -416,7 +441,7 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||||
return ERROR_SOCKET_WRITE;
|
return ERROR_SOCKET_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_bytes += nb_write;
|
sbytes += nb_write;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -443,7 +468,7 @@ int SrsTcpClient::connect()
|
||||||
close();
|
close();
|
||||||
|
|
||||||
srs_assert(stfd == NULL);
|
srs_assert(stfd == NULL);
|
||||||
if ((ret = srs_socket_connect(host, port, timeout * 1000, &stfd)) != ERROR_SUCCESS) {
|
if ((ret = srs_socket_connect(host, port, timeout, &stfd)) != ERROR_SUCCESS) {
|
||||||
srs_error("connect tcp://%s:%d failed, to=%"PRId64"ms. ret=%d", host.c_str(), port, timeout, ret);
|
srs_error("connect tcp://%s:%d failed, to=%"PRId64"ms. ret=%d", host.c_str(), port, timeout, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -465,14 +490,14 @@ void SrsTcpClient::close()
|
||||||
srs_close_stfd(stfd);
|
srs_close_stfd(stfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsTcpClient::is_never_timeout(int64_t timeout_us)
|
bool SrsTcpClient::is_never_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
return io->is_never_timeout(timeout_us);
|
return io->is_never_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsTcpClient::set_recv_timeout(int64_t timeout_us)
|
void SrsTcpClient::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
io->set_recv_timeout(timeout_us);
|
io->set_recv_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsTcpClient::get_recv_timeout()
|
int64_t SrsTcpClient::get_recv_timeout()
|
||||||
|
@ -480,9 +505,9 @@ int64_t SrsTcpClient::get_recv_timeout()
|
||||||
return io->get_recv_timeout();
|
return io->get_recv_timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsTcpClient::set_send_timeout(int64_t timeout_us)
|
void SrsTcpClient::set_send_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
io->set_send_timeout(timeout_us);
|
io->set_send_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsTcpClient::get_send_timeout()
|
int64_t SrsTcpClient::get_send_timeout()
|
||||||
|
|
|
@ -110,13 +110,14 @@ namespace internal
|
||||||
bool disposed;
|
bool disposed;
|
||||||
private:
|
private:
|
||||||
ISrsThreadHandler* handler;
|
ISrsThreadHandler* handler;
|
||||||
int64_t cycle_interval_us;
|
// The cycle interval in ms.
|
||||||
|
int64_t cims;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* initialize the thread.
|
* initialize the thread.
|
||||||
* @param name, human readable name for st debug.
|
* @param name, human readable name for st debug.
|
||||||
* @param thread_handler, the cycle handler for the thread.
|
* @param thread_handler, the cycle handler for the thread.
|
||||||
* @param interval_us, the sleep interval when cycle finished.
|
* @param ims, the sleep interval in ms when cycle finished.
|
||||||
* @param joinable, if joinable, other thread must stop the thread.
|
* @param joinable, if joinable, other thread must stop the thread.
|
||||||
* @remark if joinable, thread never quit itself, or memory leak.
|
* @remark if joinable, thread never quit itself, or memory leak.
|
||||||
* @see: https://github.com/ossrs/srs/issues/78
|
* @see: https://github.com/ossrs/srs/issues/78
|
||||||
|
@ -126,7 +127,7 @@ namespace internal
|
||||||
* TODO: FIXME: maybe all thread must be reap by others threads,
|
* TODO: FIXME: maybe all thread must be reap by others threads,
|
||||||
* @see: https://github.com/ossrs/srs/issues/77
|
* @see: https://github.com/ossrs/srs/issues/77
|
||||||
*/
|
*/
|
||||||
SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable);
|
SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t ims, bool joinable);
|
||||||
virtual ~SrsThread();
|
virtual ~SrsThread();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -175,19 +176,23 @@ namespace internal
|
||||||
class SrsStSocket : public ISrsProtocolReaderWriter
|
class SrsStSocket : public ISrsProtocolReaderWriter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int64_t recv_timeout;
|
// The recv/send timeout in ms.
|
||||||
int64_t send_timeout;
|
// @remark Use SRS_CONSTS_NO_TMMS for never timeout in ms.
|
||||||
int64_t recv_bytes;
|
int64_t rtm;
|
||||||
int64_t send_bytes;
|
int64_t stm;
|
||||||
|
// The recv/send data in bytes
|
||||||
|
int64_t rbytes;
|
||||||
|
int64_t sbytes;
|
||||||
|
// The underlayer st fd.
|
||||||
st_netfd_t stfd;
|
st_netfd_t stfd;
|
||||||
public:
|
public:
|
||||||
SrsStSocket(st_netfd_t client_stfd);
|
SrsStSocket(st_netfd_t client_stfd);
|
||||||
virtual ~SrsStSocket();
|
virtual ~SrsStSocket();
|
||||||
public:
|
public:
|
||||||
virtual bool is_never_timeout(int64_t timeout_us);
|
virtual bool is_never_timeout(int64_t tm);
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t tm);
|
||||||
virtual int64_t get_send_timeout();
|
virtual int64_t get_send_timeout();
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
|
@ -221,6 +226,7 @@ private:
|
||||||
private:
|
private:
|
||||||
std::string host;
|
std::string host;
|
||||||
int port;
|
int port;
|
||||||
|
// The timeout in ms.
|
||||||
int64_t timeout;
|
int64_t timeout;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -244,10 +250,10 @@ public:
|
||||||
virtual void close();
|
virtual void close();
|
||||||
// interface ISrsProtocolReaderWriter
|
// interface ISrsProtocolReaderWriter
|
||||||
public:
|
public:
|
||||||
virtual bool is_never_timeout(int64_t timeout_us);
|
virtual bool is_never_timeout(int64_t tm);
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t tm);
|
||||||
virtual int64_t get_send_timeout();
|
virtual int64_t get_send_timeout();
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
|
|
|
@ -190,10 +190,10 @@ void ISrsReusableThreadHandler::on_thread_stop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsReusableThread::SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t interval_us)
|
SrsReusableThread::SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t cims)
|
||||||
{
|
{
|
||||||
handler = h;
|
handler = h;
|
||||||
pthread = new internal::SrsThread(n, this, interval_us, true);
|
pthread = new internal::SrsThread(n, this, cims, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsReusableThread::~SrsReusableThread()
|
SrsReusableThread::~SrsReusableThread()
|
||||||
|
@ -273,10 +273,10 @@ void ISrsReusableThread2Handler::on_thread_stop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsReusableThread2::SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t interval_us)
|
SrsReusableThread2::SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t cims)
|
||||||
{
|
{
|
||||||
handler = h;
|
handler = h;
|
||||||
pthread = new internal::SrsThread(n, this, interval_us, true);
|
pthread = new internal::SrsThread(n, this, cims, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsReusableThread2::~SrsReusableThread2()
|
SrsReusableThread2::~SrsReusableThread2()
|
||||||
|
|
|
@ -162,7 +162,7 @@ public:
|
||||||
* 2. must manually stop the thread when started it.
|
* 2. must manually stop the thread when started it.
|
||||||
* for example:
|
* for example:
|
||||||
* class SrsIngester : public ISrsReusableThreadHandler {
|
* class SrsIngester : public ISrsReusableThreadHandler {
|
||||||
* public: SrsIngester() { pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US); }
|
* public: SrsIngester() { pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_CIMS); }
|
||||||
* public: virtual int start() { return pthread->start(); }
|
* public: virtual int start() { return pthread->start(); }
|
||||||
* public: virtual void stop() { pthread->stop(); }
|
* public: virtual void stop() { pthread->stop(); }
|
||||||
* public: virtual int cycle() {
|
* public: virtual int cycle() {
|
||||||
|
@ -198,7 +198,7 @@ private:
|
||||||
internal::SrsThread* pthread;
|
internal::SrsThread* pthread;
|
||||||
ISrsReusableThreadHandler* handler;
|
ISrsReusableThreadHandler* handler;
|
||||||
public:
|
public:
|
||||||
SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t interval_us = 0);
|
SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t cims = 0);
|
||||||
virtual ~SrsReusableThread();
|
virtual ~SrsReusableThread();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -244,7 +244,7 @@ public:
|
||||||
* 2. must manually stop the thread when started it.
|
* 2. must manually stop the thread when started it.
|
||||||
* for example:
|
* for example:
|
||||||
* class SrsIngester : public ISrsReusableThreadHandler {
|
* class SrsIngester : public ISrsReusableThreadHandler {
|
||||||
* public: SrsIngester() { pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US); }
|
* public: SrsIngester() { pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_CIMS); }
|
||||||
* public: virtual int start() { return pthread->start(); }
|
* public: virtual int start() { return pthread->start(); }
|
||||||
* public: virtual void stop() { pthread->stop(); }
|
* public: virtual void stop() { pthread->stop(); }
|
||||||
* public: virtual int cycle() {
|
* public: virtual int cycle() {
|
||||||
|
@ -287,7 +287,7 @@ private:
|
||||||
internal::SrsThread* pthread;
|
internal::SrsThread* pthread;
|
||||||
ISrsReusableThread2Handler* handler;
|
ISrsReusableThread2Handler* handler;
|
||||||
public:
|
public:
|
||||||
SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t interval_us = 0);
|
SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t cims = 0);
|
||||||
virtual ~SrsReusableThread2();
|
virtual ~SrsReusableThread2();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,10 +53,15 @@ using namespace std;
|
||||||
// the longest time to wait for a process to quit.
|
// the longest time to wait for a process to quit.
|
||||||
#define SRS_PROCESS_QUIT_TIMEOUT_MS 1000
|
#define SRS_PROCESS_QUIT_TIMEOUT_MS 1000
|
||||||
|
|
||||||
int srs_socket_connect(string server, int port, int64_t timeout, st_netfd_t* pstfd)
|
int srs_socket_connect(string server, int port, int64_t tm, st_netfd_t* pstfd)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
st_utime_t timeout = ST_UTIME_NO_TIMEOUT;
|
||||||
|
if (tm != SRS_CONSTS_NO_TMMS) {
|
||||||
|
timeout = (st_utime_t)(tm * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
*pstfd = NULL;
|
*pstfd = NULL;
|
||||||
st_netfd_t stfd = NULL;
|
st_netfd_t stfd = NULL;
|
||||||
sockaddr_in addr;
|
sockaddr_in addr;
|
||||||
|
|
|
@ -44,7 +44,8 @@ class SrsBuffer;
|
||||||
class SrsJsonObject;
|
class SrsJsonObject;
|
||||||
|
|
||||||
// client open socket and connect to server.
|
// client open socket and connect to server.
|
||||||
extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_netfd_t* pstfd);
|
// @param tm The timeout in ms.
|
||||||
|
extern int srs_socket_connect(std::string server, int port, int64_t tm, st_netfd_t* pstfd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert level in string to log level in int.
|
* convert level in string to log level in int.
|
||||||
|
|
|
@ -68,15 +68,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// 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.
|
||||||
|
#define SRS_CONSTS_NO_TMMS ((int64_t) -1LL)
|
||||||
|
|
||||||
// the common io timeout, for both recv and send.
|
// the common io timeout, for both recv and send.
|
||||||
// TODO: FIXME: use ms for timeout.
|
// TODO: FIXME: use ms for timeout.
|
||||||
#define SRS_CONSTS_RTMP_TIMEOUT_US (int64_t)(30*1000*1000LL)
|
#define SRS_CONSTS_RTMP_TMMS (30*1000)
|
||||||
|
|
||||||
// the timeout to wait for client control message,
|
// the timeout to wait for client control message,
|
||||||
// if timeout, we generally ignore and send the data to client,
|
// if timeout, we generally ignore and send the data to client,
|
||||||
// generally, it's the pulse time for data seding.
|
// generally, it's the pulse time for data seding.
|
||||||
// @remark, recomment to 500ms.
|
// @remark, recomment to 500ms.
|
||||||
#define SRS_CONSTS_RTMP_PULSE_TIMEOUT_US (int64_t)(500*1000LL)
|
#define SRS_CONSTS_RTMP_PULSE_TMMS (500)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* max rtmp header size:
|
* max rtmp header size:
|
||||||
|
@ -225,7 +228,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#define SRS_CONSTS_HTTP_QUERY_SEP '?'
|
#define SRS_CONSTS_HTTP_QUERY_SEP '?'
|
||||||
|
|
||||||
// the default recv timeout.
|
// the default recv timeout.
|
||||||
#define SRS_HTTP_RECV_TIMEOUT_US 60 * 1000 * 1000
|
#define SRS_HTTP_RECV_TMMS (60 * 1000)
|
||||||
|
|
||||||
// 6.1.1 Status Code and Reason Phrase
|
// 6.1.1 Status Code and Reason Phrase
|
||||||
#define SRS_CONSTS_HTTP_Continue 100
|
#define SRS_CONSTS_HTTP_Continue 100
|
||||||
|
@ -410,8 +413,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#define SRS_CONSTS_KAFKA_DEFAULT_PORT 9092
|
#define SRS_CONSTS_KAFKA_DEFAULT_PORT 9092
|
||||||
|
|
||||||
// the common io timeout, for both recv and send.
|
// the common io timeout, for both recv and send.
|
||||||
// TODO: FIXME: use ms for timeout.
|
#define SRS_CONSTS_KAFKA_TMMS (30*1000)
|
||||||
#define SRS_CONSTS_KAFKA_TIMEOUT_US (int64_t)(30*1000*1000LL)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -135,8 +135,7 @@ int64_t srs_update_system_time_ms()
|
||||||
// use date +%s to get system time is 1403844851.
|
// use date +%s to get system time is 1403844851.
|
||||||
// so we use relative time.
|
// so we use relative time.
|
||||||
if (_srs_system_time_us_cache <= 0) {
|
if (_srs_system_time_us_cache <= 0) {
|
||||||
_srs_system_time_us_cache = now_us;
|
_srs_system_time_startup_time = _srs_system_time_us_cache = now_us;
|
||||||
_srs_system_time_startup_time = now_us;
|
|
||||||
return _srs_system_time_us_cache / 1000;
|
return _srs_system_time_us_cache / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,15 +143,13 @@ int64_t srs_update_system_time_ms()
|
||||||
int64_t diff = now_us - _srs_system_time_us_cache;
|
int64_t diff = now_us - _srs_system_time_us_cache;
|
||||||
diff = srs_max(0, diff);
|
diff = srs_max(0, diff);
|
||||||
if (diff < 0 || diff > 1000 * SYS_TIME_RESOLUTION_US) {
|
if (diff < 0 || diff > 1000 * SYS_TIME_RESOLUTION_US) {
|
||||||
srs_warn("system time jump, history=%"PRId64"us, now=%"PRId64"us, diff=%"PRId64"us",
|
srs_warn("clock jump, history=%"PRId64"us, now=%"PRId64"us, diff=%"PRId64"us", _srs_system_time_us_cache, now_us, diff);
|
||||||
_srs_system_time_us_cache, now_us, diff);
|
|
||||||
// @see: https://github.com/ossrs/srs/issues/109
|
// @see: https://github.com/ossrs/srs/issues/109
|
||||||
_srs_system_time_startup_time += diff;
|
_srs_system_time_startup_time += diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
_srs_system_time_us_cache = now_us;
|
_srs_system_time_us_cache = now_us;
|
||||||
srs_info("system time updated, startup=%"PRId64"us, now=%"PRId64"us",
|
srs_info("clock updated, startup=%"PRId64"us, now=%"PRId64"us", _srs_system_time_startup_time, _srs_system_time_us_cache);
|
||||||
_srs_system_time_startup_time, _srs_system_time_us_cache);
|
|
||||||
|
|
||||||
return _srs_system_time_us_cache / 1000;
|
return _srs_system_time_us_cache / 1000;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,24 +66,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <srs_kernel_utility.hpp>
|
#include <srs_kernel_utility.hpp>
|
||||||
|
#include <srs_kernel_consts.hpp>
|
||||||
#ifndef ST_UTIME_NO_TIMEOUT
|
|
||||||
#define ST_UTIME_NO_TIMEOUT -1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// when io not hijacked, use simple socket, the block sync stream.
|
// when io not hijacked, use simple socket, the block sync stream.
|
||||||
#ifndef SRS_HIJACK_IO
|
#ifndef SRS_HIJACK_IO
|
||||||
struct SrsBlockSyncSocket
|
struct SrsBlockSyncSocket
|
||||||
{
|
{
|
||||||
SOCKET fd;
|
SOCKET fd;
|
||||||
int64_t recv_timeout;
|
int64_t rbytes;
|
||||||
int64_t send_timeout;
|
int64_t sbytes;
|
||||||
int64_t recv_bytes;
|
// The send/recv timeout in ms.
|
||||||
int64_t send_bytes;
|
int64_t rtm;
|
||||||
|
int64_t stm;
|
||||||
|
|
||||||
SrsBlockSyncSocket() {
|
SrsBlockSyncSocket() {
|
||||||
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
|
stm = rtm = SRS_CONSTS_NO_TMMS;
|
||||||
recv_bytes = send_bytes = 0;
|
rbytes = sbytes = 0;
|
||||||
|
|
||||||
SOCKET_RESET(fd);
|
SOCKET_RESET(fd);
|
||||||
SOCKET_SETUP();
|
SOCKET_SETUP();
|
||||||
|
@ -156,66 +154,75 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
return ERROR_SOCKET_READ;
|
return ERROR_SOCKET_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
skt->recv_bytes += nb_read;
|
skt->rbytes += nb_read;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
|
int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t tm)
|
||||||
{
|
{
|
||||||
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
||||||
|
|
||||||
int sec = (int)(timeout_us / 1000000LL);
|
// The default for this option is zero,
|
||||||
int microsec = (int)(timeout_us % 1000000LL);
|
// which indicates that a receive operation shall not time out.
|
||||||
|
int32_t sec = 0;
|
||||||
|
int32_t usec = 0;
|
||||||
|
|
||||||
sec = srs_max(0, sec);
|
if (tm != SRS_CONSTS_NO_TMMS) {
|
||||||
microsec = srs_max(0, microsec);
|
sec = (int32_t)(tm / 1000);
|
||||||
|
usec = (int32_t)((tm % 1000)*1000);
|
||||||
|
}
|
||||||
|
|
||||||
struct timeval tv = { sec , microsec };
|
struct timeval tv = { sec , usec };
|
||||||
if (setsockopt(skt->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
|
if (setsockopt(skt->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
|
||||||
return SOCKET_ERRNO();
|
return SOCKET_ERRNO();
|
||||||
}
|
}
|
||||||
skt->recv_timeout = timeout_us;
|
|
||||||
|
skt->rtm = tm;
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
int64_t srs_hijack_io_get_recv_timeout(srs_hijack_io_t ctx)
|
int64_t srs_hijack_io_get_recv_timeout(srs_hijack_io_t ctx)
|
||||||
{
|
{
|
||||||
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
||||||
return skt->recv_timeout;
|
return skt->rtm;
|
||||||
}
|
}
|
||||||
int64_t srs_hijack_io_get_recv_bytes(srs_hijack_io_t ctx)
|
int64_t srs_hijack_io_get_recv_bytes(srs_hijack_io_t ctx)
|
||||||
{
|
{
|
||||||
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
||||||
return skt->recv_bytes;
|
return skt->rbytes;
|
||||||
}
|
}
|
||||||
int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
|
int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t tm)
|
||||||
{
|
{
|
||||||
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
||||||
|
|
||||||
int sec = (int)(timeout_us / 1000000LL);
|
// The default for this option is zero,
|
||||||
int microsec = (int)(timeout_us % 1000000LL);
|
// which indicates that a receive operation shall not time out.
|
||||||
|
int32_t sec = 0;
|
||||||
|
int32_t usec = 0;
|
||||||
|
|
||||||
sec = srs_max(0, sec);
|
if (tm != SRS_CONSTS_NO_TMMS) {
|
||||||
microsec = srs_max(0, microsec);
|
sec = (int32_t)(tm / 1000);
|
||||||
|
usec = (int32_t)((tm % 1000)*1000);
|
||||||
|
}
|
||||||
|
|
||||||
struct timeval tv = { sec , microsec };
|
struct timeval tv = { sec , usec };
|
||||||
if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) {
|
if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) {
|
||||||
return SOCKET_ERRNO();
|
return SOCKET_ERRNO();
|
||||||
}
|
}
|
||||||
|
|
||||||
skt->send_timeout = timeout_us;
|
skt->stm = tm;
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
int64_t srs_hijack_io_get_send_timeout(srs_hijack_io_t ctx)
|
int64_t srs_hijack_io_get_send_timeout(srs_hijack_io_t ctx)
|
||||||
{
|
{
|
||||||
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
||||||
return skt->send_timeout;
|
return skt->stm;
|
||||||
}
|
}
|
||||||
int64_t srs_hijack_io_get_send_bytes(srs_hijack_io_t ctx)
|
int64_t srs_hijack_io_get_send_bytes(srs_hijack_io_t ctx)
|
||||||
{
|
{
|
||||||
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
|
||||||
return skt->send_bytes;
|
return skt->sbytes;
|
||||||
}
|
}
|
||||||
int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ssize_t* nwrite)
|
int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||||
{
|
{
|
||||||
|
@ -241,13 +248,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
return ERROR_SOCKET_WRITE;
|
return ERROR_SOCKET_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
skt->send_bytes += nb_write;
|
skt->sbytes += nb_write;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
|
bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm)
|
||||||
{
|
{
|
||||||
return timeout_us == (int64_t)ST_UTIME_NO_TIMEOUT;
|
return tm == SRS_CONSTS_NO_TMMS;
|
||||||
}
|
}
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -273,7 +280,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
if (nread) {
|
if (nread) {
|
||||||
*nread = nb_read;
|
*nread = nb_read;
|
||||||
}
|
}
|
||||||
skt->recv_bytes += nb_read;
|
skt->rbytes += nb_read;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -298,7 +305,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
return ERROR_SOCKET_WRITE;
|
return ERROR_SOCKET_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
skt->send_bytes += nb_write;
|
skt->sbytes += nb_write;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -342,10 +349,10 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ISrsProtocolReader
|
// ISrsProtocolReader
|
||||||
void SimpleSocketStream::set_recv_timeout(int64_t timeout_us)
|
void SimpleSocketStream::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
srs_assert(io);
|
srs_assert(io);
|
||||||
srs_hijack_io_set_recv_timeout(io, timeout_us);
|
srs_hijack_io_set_recv_timeout(io, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SimpleSocketStream::get_recv_timeout()
|
int64_t SimpleSocketStream::get_recv_timeout()
|
||||||
|
@ -361,10 +368,10 @@ int64_t SimpleSocketStream::get_recv_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ISrsProtocolWriter
|
// ISrsProtocolWriter
|
||||||
void SimpleSocketStream::set_send_timeout(int64_t timeout_us)
|
void SimpleSocketStream::set_send_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
srs_assert(io);
|
srs_assert(io);
|
||||||
srs_hijack_io_set_send_timeout(io, timeout_us);
|
srs_hijack_io_set_send_timeout(io, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SimpleSocketStream::get_send_timeout()
|
int64_t SimpleSocketStream::get_send_timeout()
|
||||||
|
@ -386,10 +393,10 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ISrsProtocolReaderWriter
|
// ISrsProtocolReaderWriter
|
||||||
bool SimpleSocketStream::is_never_timeout(int64_t timeout_us)
|
bool SimpleSocketStream::is_never_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
srs_assert(io);
|
srs_assert(io);
|
||||||
return srs_hijack_io_is_never_timeout(io, timeout_us);
|
return srs_hijack_io_is_never_timeout(io, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread)
|
int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread)
|
||||||
|
|
|
@ -58,18 +58,18 @@ public:
|
||||||
virtual int read(void* buf, size_t size, ssize_t* nread);
|
virtual int read(void* buf, size_t size, ssize_t* nread);
|
||||||
// ISrsProtocolReader
|
// ISrsProtocolReader
|
||||||
public:
|
public:
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
// ISrsProtocolWriter
|
// ISrsProtocolWriter
|
||||||
public:
|
public:
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t tm);
|
||||||
virtual int64_t get_send_timeout();
|
virtual int64_t get_send_timeout();
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
||||||
// ISrsProtocolReaderWriter
|
// ISrsProtocolReaderWriter
|
||||||
public:
|
public:
|
||||||
virtual bool is_never_timeout(int64_t timeout_us);
|
virtual bool is_never_timeout(int64_t tm);
|
||||||
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
|
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
|
||||||
virtual int write(void* buf, size_t size, ssize_t* nwrite);
|
virtual int write(void* buf, size_t size, ssize_t* nwrite);
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,8 +54,8 @@ using namespace std;
|
||||||
ISrsLog* _srs_log = new ISrsLog();
|
ISrsLog* _srs_log = new ISrsLog();
|
||||||
ISrsThreadContext* _srs_context = new ISrsThreadContext();
|
ISrsThreadContext* _srs_context = new ISrsThreadContext();
|
||||||
|
|
||||||
// use this default timeout in us, if user not set.
|
// The default socket timeout in ms.
|
||||||
#define SRS_SOCKET_DEFAULT_TIMEOUT 30 * 1000 * 1000LL
|
#define SRS_SOCKET_DEFAULT_TMMS (30 * 1000)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* export runtime context.
|
* export runtime context.
|
||||||
|
@ -108,7 +108,7 @@ struct Context
|
||||||
// the aac sequence header.
|
// the aac sequence header.
|
||||||
std::string aac_specific_config;
|
std::string aac_specific_config;
|
||||||
|
|
||||||
// user set timeout, in us.
|
// user set timeout, in ms.
|
||||||
int64_t stimeout;
|
int64_t stimeout;
|
||||||
int64_t rtimeout;
|
int64_t rtimeout;
|
||||||
|
|
||||||
|
@ -120,7 +120,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 = -1;
|
rtimeout = stimeout = SRS_CONSTS_NO_TMMS;
|
||||||
}
|
}
|
||||||
virtual ~Context() {
|
virtual ~Context() {
|
||||||
srs_freep(req);
|
srs_freep(req);
|
||||||
|
@ -580,8 +580,8 @@ int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_
|
||||||
|
|
||||||
Context* context = (Context*)rtmp;
|
Context* context = (Context*)rtmp;
|
||||||
|
|
||||||
context->stimeout = send_timeout_ms * 1000;
|
context->stimeout = send_timeout_ms;
|
||||||
context->rtimeout = recv_timeout_ms * 1000;
|
context->rtimeout = recv_timeout_ms;
|
||||||
|
|
||||||
context->skt->set_recv_timeout(context->rtimeout);
|
context->skt->set_recv_timeout(context->rtimeout);
|
||||||
context->skt->set_send_timeout(context->stimeout);
|
context->skt->set_send_timeout(context->stimeout);
|
||||||
|
@ -646,12 +646,12 @@ 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 == -1) {
|
if (context->stimeout == SRS_CONSTS_NO_TMMS) {
|
||||||
context->stimeout = SRS_SOCKET_DEFAULT_TIMEOUT;
|
context->stimeout = SRS_SOCKET_DEFAULT_TMMS;
|
||||||
context->skt->set_send_timeout(context->stimeout);
|
context->skt->set_send_timeout(context->stimeout);
|
||||||
}
|
}
|
||||||
if (context->rtimeout == -1) {
|
if (context->rtimeout == SRS_CONSTS_NO_TMMS) {
|
||||||
context->rtimeout = SRS_SOCKET_DEFAULT_TIMEOUT;
|
context->rtimeout = SRS_SOCKET_DEFAULT_TMMS;
|
||||||
context->skt->set_recv_timeout(context->rtimeout);
|
context->skt->set_recv_timeout(context->rtimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1020,10 +1020,10 @@ typedef void* srs_hijack_io_t;
|
||||||
*/
|
*/
|
||||||
extern int srs_hijack_io_read(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nread);
|
extern int srs_hijack_io_read(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nread);
|
||||||
/**
|
/**
|
||||||
* set the socket recv timeout.
|
* set the socket recv timeout in ms.
|
||||||
* @return 0, success; otherswise, failed.
|
* @return 0, success; otherswise, failed.
|
||||||
*/
|
*/
|
||||||
extern int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
|
extern int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t tm);
|
||||||
/**
|
/**
|
||||||
* get the socket recv timeout.
|
* get the socket recv timeout.
|
||||||
* @return 0, success; otherswise, failed.
|
* @return 0, success; otherswise, failed.
|
||||||
|
@ -1035,10 +1035,10 @@ typedef void* srs_hijack_io_t;
|
||||||
*/
|
*/
|
||||||
extern int64_t srs_hijack_io_get_recv_bytes(srs_hijack_io_t ctx);
|
extern int64_t srs_hijack_io_get_recv_bytes(srs_hijack_io_t ctx);
|
||||||
/**
|
/**
|
||||||
* set the socket send timeout.
|
* set the socket send timeout in ms.
|
||||||
* @return 0, success; otherswise, failed.
|
* @return 0, success; otherswise, failed.
|
||||||
*/
|
*/
|
||||||
extern int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
|
extern int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t tm);
|
||||||
/**
|
/**
|
||||||
* get the socket send timeout.
|
* get the socket send timeout.
|
||||||
* @return 0, success; otherswise, failed.
|
* @return 0, success; otherswise, failed.
|
||||||
|
@ -1055,10 +1055,11 @@ typedef void* srs_hijack_io_t;
|
||||||
*/
|
*/
|
||||||
extern int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ssize_t* nwrite);
|
extern int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ssize_t* nwrite);
|
||||||
/**
|
/**
|
||||||
* whether the timeout is never timeout.
|
* whether the timeout is never timeout in ms.
|
||||||
* @return 0, success; otherswise, failed.
|
* @return 0, success; otherswise, failed.
|
||||||
*/
|
*/
|
||||||
extern bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
|
// TODO: FIXME: Upgrade srs-bench and change the us to ms for timeout.
|
||||||
|
extern bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm);
|
||||||
/**
|
/**
|
||||||
* read fully, fill the buf exactly size bytes.
|
* read fully, fill the buf exactly size bytes.
|
||||||
* @return 0, success; otherswise, failed.
|
* @return 0, success; otherswise, failed.
|
||||||
|
|
|
@ -1226,9 +1226,9 @@ int SrsIngestSrsOutput::connect()
|
||||||
srs_trace("connect output=%s", url.c_str());
|
srs_trace("connect output=%s", url.c_str());
|
||||||
|
|
||||||
// connect host.
|
// connect host.
|
||||||
int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US;
|
int64_t cto = SRS_CONSTS_RTMP_TMMS;
|
||||||
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
|
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
|
||||||
sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000);
|
sdk = new SrsSimpleRtmpClient(url, cto, sto);
|
||||||
|
|
||||||
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -43,46 +43,46 @@ string srs_generate_http_status_text(int status)
|
||||||
{
|
{
|
||||||
static std::map<int, std::string> _status_map;
|
static std::map<int, std::string> _status_map;
|
||||||
if (_status_map.empty()) {
|
if (_status_map.empty()) {
|
||||||
_status_map[SRS_CONSTS_HTTP_Continue ] = SRS_CONSTS_HTTP_Continue_str ;
|
_status_map[SRS_CONSTS_HTTP_Continue] = SRS_CONSTS_HTTP_Continue_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_SwitchingProtocols ] = SRS_CONSTS_HTTP_SwitchingProtocols_str ;
|
_status_map[SRS_CONSTS_HTTP_SwitchingProtocols] = SRS_CONSTS_HTTP_SwitchingProtocols_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_OK ] = SRS_CONSTS_HTTP_OK_str ;
|
_status_map[SRS_CONSTS_HTTP_OK] = SRS_CONSTS_HTTP_OK_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_Created ] = SRS_CONSTS_HTTP_Created_str ;
|
_status_map[SRS_CONSTS_HTTP_Created] = SRS_CONSTS_HTTP_Created_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_Accepted ] = SRS_CONSTS_HTTP_Accepted_str ;
|
_status_map[SRS_CONSTS_HTTP_Accepted] = SRS_CONSTS_HTTP_Accepted_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_NonAuthoritativeInformation ] = SRS_CONSTS_HTTP_NonAuthoritativeInformation_str ;
|
_status_map[SRS_CONSTS_HTTP_NonAuthoritativeInformation] = SRS_CONSTS_HTTP_NonAuthoritativeInformation_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_NoContent ] = SRS_CONSTS_HTTP_NoContent_str ;
|
_status_map[SRS_CONSTS_HTTP_NoContent] = SRS_CONSTS_HTTP_NoContent_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_ResetContent ] = SRS_CONSTS_HTTP_ResetContent_str ;
|
_status_map[SRS_CONSTS_HTTP_ResetContent] = SRS_CONSTS_HTTP_ResetContent_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_PartialContent ] = SRS_CONSTS_HTTP_PartialContent_str ;
|
_status_map[SRS_CONSTS_HTTP_PartialContent] = SRS_CONSTS_HTTP_PartialContent_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_MultipleChoices ] = SRS_CONSTS_HTTP_MultipleChoices_str ;
|
_status_map[SRS_CONSTS_HTTP_MultipleChoices] = SRS_CONSTS_HTTP_MultipleChoices_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_MovedPermanently ] = SRS_CONSTS_HTTP_MovedPermanently_str ;
|
_status_map[SRS_CONSTS_HTTP_MovedPermanently] = SRS_CONSTS_HTTP_MovedPermanently_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_Found ] = SRS_CONSTS_HTTP_Found_str ;
|
_status_map[SRS_CONSTS_HTTP_Found] = SRS_CONSTS_HTTP_Found_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_SeeOther ] = SRS_CONSTS_HTTP_SeeOther_str ;
|
_status_map[SRS_CONSTS_HTTP_SeeOther] = SRS_CONSTS_HTTP_SeeOther_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_NotModified ] = SRS_CONSTS_HTTP_NotModified_str ;
|
_status_map[SRS_CONSTS_HTTP_NotModified] = SRS_CONSTS_HTTP_NotModified_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_UseProxy ] = SRS_CONSTS_HTTP_UseProxy_str ;
|
_status_map[SRS_CONSTS_HTTP_UseProxy] = SRS_CONSTS_HTTP_UseProxy_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_TemporaryRedirect ] = SRS_CONSTS_HTTP_TemporaryRedirect_str ;
|
_status_map[SRS_CONSTS_HTTP_TemporaryRedirect] = SRS_CONSTS_HTTP_TemporaryRedirect_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_BadRequest ] = SRS_CONSTS_HTTP_BadRequest_str ;
|
_status_map[SRS_CONSTS_HTTP_BadRequest] = SRS_CONSTS_HTTP_BadRequest_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_Unauthorized ] = SRS_CONSTS_HTTP_Unauthorized_str ;
|
_status_map[SRS_CONSTS_HTTP_Unauthorized] = SRS_CONSTS_HTTP_Unauthorized_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_PaymentRequired ] = SRS_CONSTS_HTTP_PaymentRequired_str ;
|
_status_map[SRS_CONSTS_HTTP_PaymentRequired] = SRS_CONSTS_HTTP_PaymentRequired_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_Forbidden ] = SRS_CONSTS_HTTP_Forbidden_str ;
|
_status_map[SRS_CONSTS_HTTP_Forbidden] = SRS_CONSTS_HTTP_Forbidden_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_NotFound ] = SRS_CONSTS_HTTP_NotFound_str ;
|
_status_map[SRS_CONSTS_HTTP_NotFound] = SRS_CONSTS_HTTP_NotFound_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_MethodNotAllowed ] = SRS_CONSTS_HTTP_MethodNotAllowed_str ;
|
_status_map[SRS_CONSTS_HTTP_MethodNotAllowed] = SRS_CONSTS_HTTP_MethodNotAllowed_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_NotAcceptable ] = SRS_CONSTS_HTTP_NotAcceptable_str ;
|
_status_map[SRS_CONSTS_HTTP_NotAcceptable] = SRS_CONSTS_HTTP_NotAcceptable_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_ProxyAuthenticationRequired ] = SRS_CONSTS_HTTP_ProxyAuthenticationRequired_str ;
|
_status_map[SRS_CONSTS_HTTP_ProxyAuthenticationRequired] = SRS_CONSTS_HTTP_ProxyAuthenticationRequired_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_RequestTimeout ] = SRS_CONSTS_HTTP_RequestTimeout_str ;
|
_status_map[SRS_CONSTS_HTTP_RequestTimeout] = SRS_CONSTS_HTTP_RequestTimeout_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_Conflict ] = SRS_CONSTS_HTTP_Conflict_str ;
|
_status_map[SRS_CONSTS_HTTP_Conflict] = SRS_CONSTS_HTTP_Conflict_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_Gone ] = SRS_CONSTS_HTTP_Gone_str ;
|
_status_map[SRS_CONSTS_HTTP_Gone] = SRS_CONSTS_HTTP_Gone_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_LengthRequired ] = SRS_CONSTS_HTTP_LengthRequired_str ;
|
_status_map[SRS_CONSTS_HTTP_LengthRequired] = SRS_CONSTS_HTTP_LengthRequired_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_PreconditionFailed ] = SRS_CONSTS_HTTP_PreconditionFailed_str ;
|
_status_map[SRS_CONSTS_HTTP_PreconditionFailed] = SRS_CONSTS_HTTP_PreconditionFailed_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_RequestEntityTooLarge ] = SRS_CONSTS_HTTP_RequestEntityTooLarge_str ;
|
_status_map[SRS_CONSTS_HTTP_RequestEntityTooLarge] = SRS_CONSTS_HTTP_RequestEntityTooLarge_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_RequestURITooLarge ] = SRS_CONSTS_HTTP_RequestURITooLarge_str ;
|
_status_map[SRS_CONSTS_HTTP_RequestURITooLarge] = SRS_CONSTS_HTTP_RequestURITooLarge_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_UnsupportedMediaType ] = SRS_CONSTS_HTTP_UnsupportedMediaType_str ;
|
_status_map[SRS_CONSTS_HTTP_UnsupportedMediaType] = SRS_CONSTS_HTTP_UnsupportedMediaType_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable ] = SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable_str ;
|
_status_map[SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable] = SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_ExpectationFailed ] = SRS_CONSTS_HTTP_ExpectationFailed_str ;
|
_status_map[SRS_CONSTS_HTTP_ExpectationFailed] = SRS_CONSTS_HTTP_ExpectationFailed_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_InternalServerError ] = SRS_CONSTS_HTTP_InternalServerError_str ;
|
_status_map[SRS_CONSTS_HTTP_InternalServerError] = SRS_CONSTS_HTTP_InternalServerError_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_NotImplemented ] = SRS_CONSTS_HTTP_NotImplemented_str ;
|
_status_map[SRS_CONSTS_HTTP_NotImplemented] = SRS_CONSTS_HTTP_NotImplemented_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_BadGateway ] = SRS_CONSTS_HTTP_BadGateway_str ;
|
_status_map[SRS_CONSTS_HTTP_BadGateway] = SRS_CONSTS_HTTP_BadGateway_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_ServiceUnavailable ] = SRS_CONSTS_HTTP_ServiceUnavailable_str ;
|
_status_map[SRS_CONSTS_HTTP_ServiceUnavailable] = SRS_CONSTS_HTTP_ServiceUnavailable_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_GatewayTimeout ] = SRS_CONSTS_HTTP_GatewayTimeout_str ;
|
_status_map[SRS_CONSTS_HTTP_GatewayTimeout] = SRS_CONSTS_HTTP_GatewayTimeout_str;
|
||||||
_status_map[SRS_CONSTS_HTTP_HTTPVersionNotSupported ] = SRS_CONSTS_HTTP_HTTPVersionNotSupported_str ;
|
_status_map[SRS_CONSTS_HTTP_HTTPVersionNotSupported] = SRS_CONSTS_HTTP_HTTPVersionNotSupported_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string status_text;
|
std::string status_text;
|
||||||
|
@ -2855,7 +2855,7 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
|
||||||
|
|
||||||
case s_http_userinfo:
|
case s_http_userinfo:
|
||||||
if (s != s_http_userinfo) {
|
if (s != s_http_userinfo) {
|
||||||
u->field_data[UF_USERINFO].off = p - buf ;
|
u->field_data[UF_USERINFO].off = p - buf;
|
||||||
u->field_data[UF_USERINFO].len = 0;
|
u->field_data[UF_USERINFO].len = 0;
|
||||||
u->field_set |= (1 << UF_USERINFO);
|
u->field_set |= (1 << UF_USERINFO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,12 +126,12 @@ public:
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* set the recv timeout in us, recv will error when timeout.
|
* Set the timeout tm in ms for recv bytes from peer.
|
||||||
* @remark, if not set, use ST_UTIME_NO_TIMEOUT, never timeout.
|
* @remark Use SRS_CONSTS_NO_TIMEOUT to never timeout.
|
||||||
*/
|
*/
|
||||||
virtual void set_recv_timeout(int64_t timeout_us) = 0;
|
virtual void set_recv_timeout(int64_t tm) = 0;
|
||||||
/**
|
/**
|
||||||
* get the recv timeout in us.
|
* Get the timeout in ms for recv bytes from peer.
|
||||||
*/
|
*/
|
||||||
virtual int64_t get_recv_timeout() = 0;
|
virtual int64_t get_recv_timeout() = 0;
|
||||||
// for handshake.
|
// for handshake.
|
||||||
|
@ -154,13 +154,13 @@ public:
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* set the send timeout in us, send will error when timeout.
|
* Set the timeout tm in ms for send bytes to peer.
|
||||||
* @remark, if not set, use ST_UTIME_NO_TIMEOUT, never timeout.
|
* @remark Use SRS_CONSTS_NO_TIMEOUT to never timeout.
|
||||||
*/
|
*/
|
||||||
virtual void set_send_timeout(int64_t timeout_us) = 0;
|
virtual void set_send_timeout(int64_t tm) = 0;
|
||||||
/**
|
/**
|
||||||
* get the send timeout in us.
|
* Get the timeout in ms for send bytes to peer.
|
||||||
*/
|
*/
|
||||||
virtual int64_t get_send_timeout() = 0;
|
virtual int64_t get_send_timeout() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -175,9 +175,9 @@ public:
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* whether the specified timeout_us is never timeout.
|
* Whether the specified tm in ms is never timeout.
|
||||||
*/
|
*/
|
||||||
virtual bool is_never_timeout(int64_t timeout_us) = 0;
|
virtual bool is_never_timeout(int64_t tm) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -325,9 +325,9 @@ void SrsProtocol::set_recv_buffer(int buffer_size)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void SrsProtocol::set_recv_timeout(int64_t timeout_us)
|
void SrsProtocol::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
return skt->set_recv_timeout(timeout_us);
|
return skt->set_recv_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsProtocol::get_recv_timeout()
|
int64_t SrsProtocol::get_recv_timeout()
|
||||||
|
@ -335,9 +335,9 @@ int64_t SrsProtocol::get_recv_timeout()
|
||||||
return skt->get_recv_timeout();
|
return skt->get_recv_timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsProtocol::set_send_timeout(int64_t timeout_us)
|
void SrsProtocol::set_send_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
return skt->set_send_timeout(timeout_us);
|
return skt->set_send_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsProtocol::get_send_timeout()
|
int64_t SrsProtocol::get_send_timeout()
|
||||||
|
@ -1982,14 +1982,14 @@ SrsRtmpClient::~SrsRtmpClient()
|
||||||
srs_freep(hs_bytes);
|
srs_freep(hs_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtmpClient::set_recv_timeout(int64_t timeout_us)
|
void SrsRtmpClient::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
protocol->set_recv_timeout(timeout_us);
|
protocol->set_recv_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtmpClient::set_send_timeout(int64_t timeout_us)
|
void SrsRtmpClient::set_send_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
protocol->set_send_timeout(timeout_us);
|
protocol->set_send_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsRtmpClient::get_recv_bytes()
|
int64_t SrsRtmpClient::get_recv_bytes()
|
||||||
|
@ -2410,9 +2410,9 @@ void SrsRtmpServer::set_recv_buffer(int buffer_size)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void SrsRtmpServer::set_recv_timeout(int64_t timeout_us)
|
void SrsRtmpServer::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
protocol->set_recv_timeout(timeout_us);
|
protocol->set_recv_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsRtmpServer::get_recv_timeout()
|
int64_t SrsRtmpServer::get_recv_timeout()
|
||||||
|
@ -2420,9 +2420,9 @@ int64_t SrsRtmpServer::get_recv_timeout()
|
||||||
return protocol->get_recv_timeout();
|
return protocol->get_recv_timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtmpServer::set_send_timeout(int64_t timeout_us)
|
void SrsRtmpServer::set_send_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
protocol->set_send_timeout(timeout_us);
|
protocol->set_send_timeout(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsRtmpServer::get_send_timeout()
|
int64_t SrsRtmpServer::get_send_timeout()
|
||||||
|
@ -2621,7 +2621,7 @@ int SrsRtmpServer::response_connect_app(SrsRequest *req, const char* server_ip)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SRS_RTMP_REDIRECT_TIMEOUT 3000
|
#define SRS_RTMP_REDIRECT_TMMS 3000
|
||||||
int SrsRtmpServer::redirect(SrsRequest* r, string host, int port, bool& accepted)
|
int SrsRtmpServer::redirect(SrsRequest* r, string host, int port, bool& accepted)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
@ -2649,7 +2649,7 @@ int SrsRtmpServer::redirect(SrsRequest* r, string host, int port, bool& accepted
|
||||||
|
|
||||||
// client must response a call message.
|
// client must response a call message.
|
||||||
// or we never know whether the client is ok to redirect.
|
// or we never know whether the client is ok to redirect.
|
||||||
protocol->set_recv_timeout(SRS_RTMP_REDIRECT_TIMEOUT * 1000);
|
protocol->set_recv_timeout(SRS_RTMP_REDIRECT_TMMS);
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
SrsCallPacket* pkt = NULL;
|
SrsCallPacket* pkt = NULL;
|
||||||
|
|
|
@ -313,16 +313,16 @@ public:
|
||||||
#endif
|
#endif
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* set/get the recv timeout in us.
|
* set/get the recv timeout in ms.
|
||||||
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
||||||
*/
|
*/
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
/**
|
/**
|
||||||
* set/get the send timeout in us.
|
* set/get the send timeout in ms.
|
||||||
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
||||||
*/
|
*/
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t tm);
|
||||||
virtual int64_t get_send_timeout();
|
virtual int64_t get_send_timeout();
|
||||||
/**
|
/**
|
||||||
* get recv/send bytes.
|
* get recv/send bytes.
|
||||||
|
@ -681,64 +681,16 @@ protected:
|
||||||
public:
|
public:
|
||||||
SrsRtmpClient(ISrsProtocolReaderWriter* skt);
|
SrsRtmpClient(ISrsProtocolReaderWriter* skt);
|
||||||
virtual ~SrsRtmpClient();
|
virtual ~SrsRtmpClient();
|
||||||
// protocol methods proxy
|
// protocol methods proxy
|
||||||
public:
|
public:
|
||||||
/**
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
* set the recv timeout in us.
|
virtual void set_send_timeout(int64_t tm);
|
||||||
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
|
||||||
*/
|
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
|
||||||
/**
|
|
||||||
* set the send timeout in us.
|
|
||||||
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
|
||||||
*/
|
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
|
||||||
/**
|
|
||||||
* get recv/send bytes.
|
|
||||||
*/
|
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
/**
|
|
||||||
* recv a RTMP message, which is bytes oriented.
|
|
||||||
* user can use decode_message to get the decoded RTMP packet.
|
|
||||||
* @param pmsg, set the received message,
|
|
||||||
* always NULL if error,
|
|
||||||
* NULL for unknown packet but return success.
|
|
||||||
* never NULL if decode success.
|
|
||||||
* @remark, drop message when msg is empty or payload length is empty.
|
|
||||||
*/
|
|
||||||
virtual int recv_message(SrsCommonMessage** pmsg);
|
virtual int recv_message(SrsCommonMessage** pmsg);
|
||||||
/**
|
|
||||||
* decode bytes oriented RTMP message to RTMP packet,
|
|
||||||
* @param ppacket, output decoded packet,
|
|
||||||
* always NULL if error, never NULL if success.
|
|
||||||
* @return error when unknown packet, error when decode failed.
|
|
||||||
*/
|
|
||||||
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
|
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
|
||||||
/**
|
|
||||||
* send the RTMP message and always free it.
|
|
||||||
* user must never free or use the msg after this method,
|
|
||||||
* for it will always free the msg.
|
|
||||||
* @param msg, the msg to send out, never be NULL.
|
|
||||||
* @param stream_id, the stream id of packet to send over, 0 for control message.
|
|
||||||
*/
|
|
||||||
virtual int send_and_free_message(SrsSharedPtrMessage* msg, int stream_id);
|
virtual int send_and_free_message(SrsSharedPtrMessage* msg, int stream_id);
|
||||||
/**
|
|
||||||
* send the RTMP message and always free it.
|
|
||||||
* user must never free or use the msg after this method,
|
|
||||||
* for it will always free the msg.
|
|
||||||
* @param msgs, the msgs to send out, never be NULL.
|
|
||||||
* @param nb_msgs, the size of msgs to send out.
|
|
||||||
* @param stream_id, the stream id of packet to send over, 0 for control message.
|
|
||||||
*/
|
|
||||||
virtual int send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id);
|
virtual int send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id);
|
||||||
/**
|
|
||||||
* send the RTMP packet and always free it.
|
|
||||||
* user must never free or use the packet after this method,
|
|
||||||
* for it will always free the packet.
|
|
||||||
* @param packet, the packet to send out, never be NULL.
|
|
||||||
* @param stream_id, the stream id of packet to send over, 0 for control message.
|
|
||||||
*/
|
|
||||||
virtual int send_and_free_packet(SrsPacket* packet, int stream_id);
|
virtual int send_and_free_packet(SrsPacket* packet, int stream_id);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -865,16 +817,16 @@ public:
|
||||||
virtual void set_recv_buffer(int buffer_size);
|
virtual void set_recv_buffer(int buffer_size);
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* set/get the recv timeout in us.
|
* set/get the recv timeout in ms.
|
||||||
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
||||||
*/
|
*/
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
/**
|
/**
|
||||||
* set/get the send timeout in us.
|
* set/get the send timeout in ms.
|
||||||
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
||||||
*/
|
*/
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t tm);
|
||||||
virtual int64_t get_send_timeout();
|
virtual int64_t get_send_timeout();
|
||||||
/**
|
/**
|
||||||
* get recv/send bytes.
|
* get recv/send bytes.
|
||||||
|
|
|
@ -48,50 +48,50 @@ string srs_generate_rtsp_status_text(int status)
|
||||||
{
|
{
|
||||||
static std::map<int, std::string> _status_map;
|
static std::map<int, std::string> _status_map;
|
||||||
if (_status_map.empty()) {
|
if (_status_map.empty()) {
|
||||||
_status_map[SRS_CONSTS_RTSP_Continue ] = SRS_CONSTS_RTSP_Continue_str ;
|
_status_map[SRS_CONSTS_RTSP_Continue] = SRS_CONSTS_RTSP_Continue_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_OK ] = SRS_CONSTS_RTSP_OK_str ;
|
_status_map[SRS_CONSTS_RTSP_OK] = SRS_CONSTS_RTSP_OK_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_Created ] = SRS_CONSTS_RTSP_Created_str ;
|
_status_map[SRS_CONSTS_RTSP_Created] = SRS_CONSTS_RTSP_Created_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_LowOnStorageSpace ] = SRS_CONSTS_RTSP_LowOnStorageSpace_str ;
|
_status_map[SRS_CONSTS_RTSP_LowOnStorageSpace] = SRS_CONSTS_RTSP_LowOnStorageSpace_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_MultipleChoices ] = SRS_CONSTS_RTSP_MultipleChoices_str ;
|
_status_map[SRS_CONSTS_RTSP_MultipleChoices] = SRS_CONSTS_RTSP_MultipleChoices_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_MovedPermanently ] = SRS_CONSTS_RTSP_MovedPermanently_str ;
|
_status_map[SRS_CONSTS_RTSP_MovedPermanently] = SRS_CONSTS_RTSP_MovedPermanently_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_MovedTemporarily ] = SRS_CONSTS_RTSP_MovedTemporarily_str ;
|
_status_map[SRS_CONSTS_RTSP_MovedTemporarily] = SRS_CONSTS_RTSP_MovedTemporarily_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_SeeOther ] = SRS_CONSTS_RTSP_SeeOther_str ;
|
_status_map[SRS_CONSTS_RTSP_SeeOther] = SRS_CONSTS_RTSP_SeeOther_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_NotModified ] = SRS_CONSTS_RTSP_NotModified_str ;
|
_status_map[SRS_CONSTS_RTSP_NotModified] = SRS_CONSTS_RTSP_NotModified_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_UseProxy ] = SRS_CONSTS_RTSP_UseProxy_str ;
|
_status_map[SRS_CONSTS_RTSP_UseProxy] = SRS_CONSTS_RTSP_UseProxy_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_BadRequest ] = SRS_CONSTS_RTSP_BadRequest_str ;
|
_status_map[SRS_CONSTS_RTSP_BadRequest] = SRS_CONSTS_RTSP_BadRequest_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_Unauthorized ] = SRS_CONSTS_RTSP_Unauthorized_str ;
|
_status_map[SRS_CONSTS_RTSP_Unauthorized] = SRS_CONSTS_RTSP_Unauthorized_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_PaymentRequired ] = SRS_CONSTS_RTSP_PaymentRequired_str ;
|
_status_map[SRS_CONSTS_RTSP_PaymentRequired] = SRS_CONSTS_RTSP_PaymentRequired_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_Forbidden ] = SRS_CONSTS_RTSP_Forbidden_str ;
|
_status_map[SRS_CONSTS_RTSP_Forbidden] = SRS_CONSTS_RTSP_Forbidden_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_NotFound ] = SRS_CONSTS_RTSP_NotFound_str ;
|
_status_map[SRS_CONSTS_RTSP_NotFound] = SRS_CONSTS_RTSP_NotFound_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_MethodNotAllowed ] = SRS_CONSTS_RTSP_MethodNotAllowed_str ;
|
_status_map[SRS_CONSTS_RTSP_MethodNotAllowed] = SRS_CONSTS_RTSP_MethodNotAllowed_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_NotAcceptable ] = SRS_CONSTS_RTSP_NotAcceptable_str ;
|
_status_map[SRS_CONSTS_RTSP_NotAcceptable] = SRS_CONSTS_RTSP_NotAcceptable_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_ProxyAuthenticationRequired ] = SRS_CONSTS_RTSP_ProxyAuthenticationRequired_str ;
|
_status_map[SRS_CONSTS_RTSP_ProxyAuthenticationRequired] = SRS_CONSTS_RTSP_ProxyAuthenticationRequired_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_RequestTimeout ] = SRS_CONSTS_RTSP_RequestTimeout_str ;
|
_status_map[SRS_CONSTS_RTSP_RequestTimeout] = SRS_CONSTS_RTSP_RequestTimeout_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_Gone ] = SRS_CONSTS_RTSP_Gone_str ;
|
_status_map[SRS_CONSTS_RTSP_Gone] = SRS_CONSTS_RTSP_Gone_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_LengthRequired ] = SRS_CONSTS_RTSP_LengthRequired_str ;
|
_status_map[SRS_CONSTS_RTSP_LengthRequired] = SRS_CONSTS_RTSP_LengthRequired_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_PreconditionFailed ] = SRS_CONSTS_RTSP_PreconditionFailed_str ;
|
_status_map[SRS_CONSTS_RTSP_PreconditionFailed] = SRS_CONSTS_RTSP_PreconditionFailed_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_RequestEntityTooLarge ] = SRS_CONSTS_RTSP_RequestEntityTooLarge_str ;
|
_status_map[SRS_CONSTS_RTSP_RequestEntityTooLarge] = SRS_CONSTS_RTSP_RequestEntityTooLarge_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_RequestURITooLarge ] = SRS_CONSTS_RTSP_RequestURITooLarge_str ;
|
_status_map[SRS_CONSTS_RTSP_RequestURITooLarge] = SRS_CONSTS_RTSP_RequestURITooLarge_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_UnsupportedMediaType ] = SRS_CONSTS_RTSP_UnsupportedMediaType_str ;
|
_status_map[SRS_CONSTS_RTSP_UnsupportedMediaType] = SRS_CONSTS_RTSP_UnsupportedMediaType_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_ParameterNotUnderstood ] = SRS_CONSTS_RTSP_ParameterNotUnderstood_str ;
|
_status_map[SRS_CONSTS_RTSP_ParameterNotUnderstood] = SRS_CONSTS_RTSP_ParameterNotUnderstood_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_ConferenceNotFound ] = SRS_CONSTS_RTSP_ConferenceNotFound_str ;
|
_status_map[SRS_CONSTS_RTSP_ConferenceNotFound] = SRS_CONSTS_RTSP_ConferenceNotFound_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_NotEnoughBandwidth ] = SRS_CONSTS_RTSP_NotEnoughBandwidth_str ;
|
_status_map[SRS_CONSTS_RTSP_NotEnoughBandwidth] = SRS_CONSTS_RTSP_NotEnoughBandwidth_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_SessionNotFound ] = SRS_CONSTS_RTSP_SessionNotFound_str ;
|
_status_map[SRS_CONSTS_RTSP_SessionNotFound] = SRS_CONSTS_RTSP_SessionNotFound_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_MethodNotValidInThisState ] = SRS_CONSTS_RTSP_MethodNotValidInThisState_str ;
|
_status_map[SRS_CONSTS_RTSP_MethodNotValidInThisState] = SRS_CONSTS_RTSP_MethodNotValidInThisState_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_HeaderFieldNotValidForResource ] = SRS_CONSTS_RTSP_HeaderFieldNotValidForResource_str ;
|
_status_map[SRS_CONSTS_RTSP_HeaderFieldNotValidForResource] = SRS_CONSTS_RTSP_HeaderFieldNotValidForResource_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_InvalidRange ] = SRS_CONSTS_RTSP_InvalidRange_str ;
|
_status_map[SRS_CONSTS_RTSP_InvalidRange] = SRS_CONSTS_RTSP_InvalidRange_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_ParameterIsReadOnly ] = SRS_CONSTS_RTSP_ParameterIsReadOnly_str ;
|
_status_map[SRS_CONSTS_RTSP_ParameterIsReadOnly] = SRS_CONSTS_RTSP_ParameterIsReadOnly_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_AggregateOperationNotAllowed ] = SRS_CONSTS_RTSP_AggregateOperationNotAllowed_str ;
|
_status_map[SRS_CONSTS_RTSP_AggregateOperationNotAllowed] = SRS_CONSTS_RTSP_AggregateOperationNotAllowed_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed ] = SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed_str ;
|
_status_map[SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed] = SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_UnsupportedTransport ] = SRS_CONSTS_RTSP_UnsupportedTransport_str ;
|
_status_map[SRS_CONSTS_RTSP_UnsupportedTransport] = SRS_CONSTS_RTSP_UnsupportedTransport_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_DestinationUnreachable ] = SRS_CONSTS_RTSP_DestinationUnreachable_str ;
|
_status_map[SRS_CONSTS_RTSP_DestinationUnreachable] = SRS_CONSTS_RTSP_DestinationUnreachable_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_InternalServerError ] = SRS_CONSTS_RTSP_InternalServerError_str ;
|
_status_map[SRS_CONSTS_RTSP_InternalServerError] = SRS_CONSTS_RTSP_InternalServerError_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_NotImplemented ] = SRS_CONSTS_RTSP_NotImplemented_str ;
|
_status_map[SRS_CONSTS_RTSP_NotImplemented] = SRS_CONSTS_RTSP_NotImplemented_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_BadGateway ] = SRS_CONSTS_RTSP_BadGateway_str ;
|
_status_map[SRS_CONSTS_RTSP_BadGateway] = SRS_CONSTS_RTSP_BadGateway_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_ServiceUnavailable ] = SRS_CONSTS_RTSP_ServiceUnavailable_str ;
|
_status_map[SRS_CONSTS_RTSP_ServiceUnavailable] = SRS_CONSTS_RTSP_ServiceUnavailable_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_GatewayTimeout ] = SRS_CONSTS_RTSP_GatewayTimeout_str ;
|
_status_map[SRS_CONSTS_RTSP_GatewayTimeout] = SRS_CONSTS_RTSP_GatewayTimeout_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_RTSPVersionNotSupported ] = SRS_CONSTS_RTSP_RTSPVersionNotSupported_str ;
|
_status_map[SRS_CONSTS_RTSP_RTSPVersionNotSupported] = SRS_CONSTS_RTSP_RTSPVersionNotSupported_str;
|
||||||
_status_map[SRS_CONSTS_RTSP_OptionNotSupported ] = SRS_CONSTS_RTSP_OptionNotSupported_str ;
|
_status_map[SRS_CONSTS_RTSP_OptionNotSupported] = SRS_CONSTS_RTSP_OptionNotSupported_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string status_text;
|
std::string status_text;
|
||||||
|
|
|
@ -42,7 +42,7 @@ MockEmptyIO::~MockEmptyIO()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MockEmptyIO::is_never_timeout(int64_t /*timeout_us*/)
|
bool MockEmptyIO::is_never_timeout(int64_t /*tm*/)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ int MockEmptyIO::write(void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/)
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MockEmptyIO::set_recv_timeout(int64_t /*timeout_us*/)
|
void MockEmptyIO::set_recv_timeout(int64_t /*tm*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ int64_t MockEmptyIO::get_recv_bytes()
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MockEmptyIO::set_send_timeout(int64_t /*timeout_us*/)
|
void MockEmptyIO::set_send_timeout(int64_t /*tm*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,17 +97,17 @@ int MockEmptyIO::read(void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/)
|
||||||
|
|
||||||
MockBufferIO::MockBufferIO()
|
MockBufferIO::MockBufferIO()
|
||||||
{
|
{
|
||||||
recv_timeout = send_timeout = ST_UTIME_NO_TIMEOUT;
|
rtm = stm = SRS_CONSTS_NO_TMMS;
|
||||||
recv_bytes = send_bytes = 0;
|
rbytes = sbytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MockBufferIO::~MockBufferIO()
|
MockBufferIO::~MockBufferIO()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MockBufferIO::is_never_timeout(int64_t timeout_us)
|
bool MockBufferIO::is_never_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
return (int64_t)ST_UTIME_NO_TIMEOUT == timeout_us;
|
return tm == SRS_CONSTS_NO_TMMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread)
|
int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread)
|
||||||
|
@ -117,7 +117,7 @@ int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread)
|
||||||
}
|
}
|
||||||
memcpy(buf, in_buffer.bytes(), size);
|
memcpy(buf, in_buffer.bytes(), size);
|
||||||
|
|
||||||
recv_bytes += size;
|
rbytes += size;
|
||||||
if (nread) {
|
if (nread) {
|
||||||
*nread = size;
|
*nread = size;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread)
|
||||||
|
|
||||||
int MockBufferIO::write(void* buf, size_t size, ssize_t* nwrite)
|
int MockBufferIO::write(void* buf, size_t size, ssize_t* nwrite)
|
||||||
{
|
{
|
||||||
send_bytes += size;
|
sbytes += size;
|
||||||
if (nwrite) {
|
if (nwrite) {
|
||||||
*nwrite = size;
|
*nwrite = size;
|
||||||
}
|
}
|
||||||
|
@ -135,34 +135,34 @@ int MockBufferIO::write(void* buf, size_t size, ssize_t* nwrite)
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MockBufferIO::set_recv_timeout(int64_t timeout_us)
|
void MockBufferIO::set_recv_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
recv_timeout = timeout_us;
|
rtm = tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t MockBufferIO::get_recv_timeout()
|
int64_t MockBufferIO::get_recv_timeout()
|
||||||
{
|
{
|
||||||
return recv_timeout;
|
return rtm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t MockBufferIO::get_recv_bytes()
|
int64_t MockBufferIO::get_recv_bytes()
|
||||||
{
|
{
|
||||||
return recv_bytes;
|
return rbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MockBufferIO::set_send_timeout(int64_t timeout_us)
|
void MockBufferIO::set_send_timeout(int64_t tm)
|
||||||
{
|
{
|
||||||
send_timeout = timeout_us;
|
stm = tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t MockBufferIO::get_send_timeout()
|
int64_t MockBufferIO::get_send_timeout()
|
||||||
{
|
{
|
||||||
return send_timeout;
|
return stm;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t MockBufferIO::get_send_bytes()
|
int64_t MockBufferIO::get_send_bytes()
|
||||||
{
|
{
|
||||||
return send_bytes;
|
return sbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MockBufferIO::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
int MockBufferIO::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||||
|
@ -180,6 +180,8 @@ int MockBufferIO::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||||
total += writen;
|
total += writen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sbytes += total;
|
||||||
|
|
||||||
if (nwrite) {
|
if (nwrite) {
|
||||||
*nwrite = total;
|
*nwrite = total;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +197,7 @@ int MockBufferIO::read(void* buf, size_t size, ssize_t* nread)
|
||||||
size_t available = srs_min(in_buffer.length(), (int)size);
|
size_t available = srs_min(in_buffer.length(), (int)size);
|
||||||
memcpy(buf, in_buffer.bytes(), available);
|
memcpy(buf, in_buffer.bytes(), available);
|
||||||
|
|
||||||
recv_bytes += available;
|
rbytes += available;
|
||||||
if (nread) {
|
if (nread) {
|
||||||
*nread = available;
|
*nread = available;
|
||||||
}
|
}
|
||||||
|
@ -530,8 +532,8 @@ VOID TEST(ProtocolStackTest, ProtocolTimeout)
|
||||||
MockBufferIO bio;
|
MockBufferIO bio;
|
||||||
SrsProtocol proto(&bio);
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
EXPECT_TRUE((int64_t)ST_UTIME_NO_TIMEOUT == proto.get_recv_timeout());
|
EXPECT_TRUE(SRS_CONSTS_NO_TMMS == proto.get_recv_timeout());
|
||||||
EXPECT_TRUE((int64_t)ST_UTIME_NO_TIMEOUT == proto.get_send_timeout());
|
EXPECT_TRUE(SRS_CONSTS_NO_TMMS == 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());
|
||||||
|
|
|
@ -49,19 +49,19 @@ public:
|
||||||
virtual ~MockEmptyIO();
|
virtual ~MockEmptyIO();
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
virtual bool is_never_timeout(int64_t timeout_us);
|
virtual bool is_never_timeout(int64_t tm);
|
||||||
// for handshake.
|
// for handshake.
|
||||||
public:
|
public:
|
||||||
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
|
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
|
||||||
virtual int write(void* buf, size_t size, ssize_t* nwrite);
|
virtual int write(void* buf, size_t size, ssize_t* nwrite);
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t tm);
|
||||||
virtual int64_t get_send_timeout();
|
virtual int64_t get_send_timeout();
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
||||||
|
@ -73,10 +73,12 @@ public:
|
||||||
class MockBufferIO : public ISrsProtocolReaderWriter
|
class MockBufferIO : public ISrsProtocolReaderWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int64_t recv_timeout;
|
// The send/recv timeout in ms.
|
||||||
int64_t send_timeout;
|
int64_t rtm;
|
||||||
int64_t recv_bytes;
|
int64_t stm;
|
||||||
int64_t send_bytes;
|
// The send/recv data in bytes.
|
||||||
|
int64_t rbytes;
|
||||||
|
int64_t sbytes;
|
||||||
// data source for socket read.
|
// data source for socket read.
|
||||||
SrsSimpleStream in_buffer;
|
SrsSimpleStream in_buffer;
|
||||||
// data buffer for socket send.
|
// data buffer for socket send.
|
||||||
|
@ -86,19 +88,19 @@ public:
|
||||||
virtual ~MockBufferIO();
|
virtual ~MockBufferIO();
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
virtual bool is_never_timeout(int64_t timeout_us);
|
virtual bool is_never_timeout(int64_t tm);
|
||||||
// for handshake.
|
// for handshake.
|
||||||
public:
|
public:
|
||||||
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
|
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
|
||||||
virtual int write(void* buf, size_t size, ssize_t* nwrite);
|
virtual int write(void* buf, size_t size, ssize_t* nwrite);
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t tm);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
// for protocol
|
// for protocol
|
||||||
public:
|
public:
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t tm);
|
||||||
virtual int64_t get_send_timeout();
|
virtual int64_t get_send_timeout();
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue