1
0
Fork 0
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:
winlin 2017-01-17 12:25:30 +08:00
parent dca9749f37
commit 3fe338d1c5
43 changed files with 437 additions and 435 deletions

View file

@ -28,8 +28,8 @@ using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
// the sleep interval for http async callback.
#define SRS_AUTO_ASYNC_CALLBACL_SLEEP_US 300000
// the sleep interval in ms for http async callback.
#define SRS_AUTO_ASYNC_CALLBACL_CIMS 30
ISrsAsyncCallTask::ISrsAsyncCallTask()
{
@ -41,7 +41,7 @@ ISrsAsyncCallTask::~ISrsAsyncCallTask()
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();
}

View file

@ -190,8 +190,8 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
SrsBandwidthSample publish_sample;
// timeout for a packet.
_rtmp->set_send_timeout(play_sample.duration_ms * 1000 * 2);
_rtmp->set_recv_timeout(publish_sample.duration_ms * 1000 * 2);
_rtmp->set_send_timeout(play_sample.duration_ms * 2);
_rtmp->set_recv_timeout(publish_sample.duration_ms * 2);
// start test.
srs_update_system_time_ms();

View file

@ -183,9 +183,9 @@ int SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec)
srs_freep(sdk);
int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
sdk = new SrsSimpleRtmpClient(output, cto / 1000, sto / 1000);
int64_t cto = SRS_CONSTS_RTMP_TMMS;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
sdk = new SrsSimpleRtmpClient(output, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
srs_error("flv: connect %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", output.c_str(), cto, sto, ret);

View file

@ -48,19 +48,16 @@ using namespace std;
#include <srs_app_rtmp_conn.hpp>
// 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.
#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.
#define SRS_EDGE_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL)
// when edge timeout, retry next.
#define SRS_EDGE_FORWARDER_TIMEOUT_US (int64_t)(5*1000*1000LL)
#define SRS_EDGE_FORWARDER_CIMS (3*1000)
// when edge error, wait for quit
#define SRS_EDGE_FORWARDER_ERROR_US (int64_t)(50*1000LL)
#define SRS_EDGE_FORWARDER_TMMS (150)
SrsEdgeUpstream::SrsEdgeUpstream()
{
@ -125,9 +122,9 @@ int SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
}
srs_freep(sdk);
int64_t cto = SRS_EDGE_INGESTER_TIMEOUT_US;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000);
int64_t cto = SRS_EDGE_INGESTER_TMMS;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
sdk = new SrsSimpleRtmpClient(url, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
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);
}
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)
@ -175,7 +172,7 @@ SrsEdgeIngester::SrsEdgeIngester()
upstream = new SrsEdgeRtmpUpstream(redirect);
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()
@ -274,7 +271,7 @@ int SrsEdgeIngester::ingest()
SrsAutoFree(SrsPithyPrint, pprint);
// 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()) {
pprint->elapse();
@ -409,7 +406,7 @@ SrsEdgeForwarder::SrsEdgeForwarder()
sdk = NULL;
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();
}
@ -465,9 +462,9 @@ int SrsEdgeForwarder::start()
// open socket.
srs_freep(sdk);
int64_t cto = SRS_EDGE_FORWARDER_TIMEOUT_US;
int64_t sto = SRS_CONSTS_RTMP_TIMEOUT_US;
sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000);
int64_t cto = SRS_EDGE_FORWARDER_TMMS;
int64_t sto = SRS_CONSTS_RTMP_TMMS;
sdk = new SrsSimpleRtmpClient(url, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
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;
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS);
SrsPithyPrint* pprint = SrsPithyPrint::create_edge();
SrsAutoFree(SrsPithyPrint, pprint);
@ -505,7 +502,7 @@ int SrsEdgeForwarder::cycle()
while (!pthread->interrupted()) {
if (send_error_code != ERROR_SUCCESS) {
st_usleep(SRS_EDGE_FORWARDER_ERROR_US);
st_usleep(SRS_EDGE_FORWARDER_TMMS * 1000);
continue;
}

View file

@ -90,7 +90,7 @@ public:
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0;
virtual void close() = 0;
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;
};
@ -111,7 +111,7 @@ public:
virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
virtual void close();
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);
};

View file

@ -37,14 +37,14 @@ using namespace std;
#ifdef SRS_AUTO_TRANSCODE
// 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
static std::vector<std::string> _transcoded_url;
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();
}

View file

@ -48,7 +48,7 @@ using namespace std;
#include <srs_app_rtmp_conn.hpp>
// 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)
{
@ -58,7 +58,7 @@ SrsForwarder::SrsForwarder(SrsSource* s)
sh_video = sh_audio = NULL;
sdk = NULL;
pthread = new SrsReusableThread2("forward", this, SRS_FORWARDER_SLEEP_US);
pthread = new SrsReusableThread2("forward", this, SRS_FORWARDER_CIMS);
queue = new SrsMessageQueue();
jitter = new SrsRtmpJitter();
}
@ -237,8 +237,8 @@ int SrsForwarder::cycle()
}
srs_freep(sdk);
int64_t cto = SRS_FORWARDER_SLEEP_US;
int64_t sto = SRS_CONSTS_RTMP_TIMEOUT_US;
int64_t cto = SRS_FORWARDER_CIMS;
int64_t sto = SRS_CONSTS_RTMP_TMMS;
sdk = new SrsSimpleRtmpClient(url, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
@ -267,7 +267,7 @@ int SrsForwarder::forward()
{
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();
SrsAutoFree(SrsPithyPrint, pprint);

View file

@ -1365,7 +1365,7 @@ int SrsHttpApi::do_cycle()
// set the recv timeout, for some clients never disconnect the connection.
// @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.
bool crossdomain_enabled = _srs_config->get_http_api_crossdomain();

View file

@ -43,7 +43,7 @@ SrsHttpClient::SrsHttpClient()
transport = NULL;
kbps = new SrsKbps();
parser = NULL;
timeout_us = 0;
timeout = SRS_CONSTS_NO_TMMS;
port = 0;
}
@ -56,7 +56,7 @@ SrsHttpClient::~SrsHttpClient()
}
// 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;
@ -71,7 +71,7 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us)
// Always disconnect the transport.
host = h;
port = p;
timeout_us = t_us;
timeout = tm;
disconnect();
// ep used for host in header.
@ -196,9 +196,9 @@ int SrsHttpClient::get(string path, string req, ISrsHttpMessage** ppmsg)
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)
@ -232,17 +232,17 @@ int SrsHttpClient::connect()
return ret;
}
transport = new SrsTcpClient(host, port, timeout_us / 1000);
transport = new SrsTcpClient(host, port, timeout);
if ((ret = transport->connect()) != ERROR_SUCCESS) {
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;
}
srs_info("connect to server success. server=%s, port=%d", host.c_str(), port);
// set the recv/send timeout in us.
transport->set_recv_timeout(timeout_us);
transport->set_send_timeout(timeout_us);
// Set the recv/send timeout in ms.
transport->set_recv_timeout(timeout);
transport->set_send_timeout(timeout);
kbps->set_io(transport, transport);

View file

@ -43,7 +43,7 @@ class SrsStSocket;
class SrsKbps;
// 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.
@ -64,8 +64,9 @@ private:
std::map<std::string, std::string> headers;
SrsKbps* kbps;
private:
int64_t timeout_us;
// host name or ip.
// The timeout in ms.
int64_t timeout;
// The host name or ip.
std::string host;
int port;
public:
@ -74,9 +75,10 @@ public:
public:
/**
* 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.
*/
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.
* @return the HTTP client itself.
@ -99,8 +101,9 @@ public:
* @remark user must free the ppmsg if not NULL.
*/
virtual int get(std::string path, std::string req, ISrsHttpMessage** ppmsg);
private:
virtual void set_recv_timeout(int64_t tm);
public:
virtual void set_recv_timeout(int64_t timeout);
virtual void kbps_sample(const char* label, int64_t age);
private:
virtual void disconnect();

View file

@ -1137,7 +1137,7 @@ int SrsHttpConn::do_cycle()
// set the recv timeout, for some clients never disconnect the connection.
// @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;
SrsAutoFree(SrsRequest, last_req);

View file

@ -45,10 +45,10 @@ using namespace std;
#define SRS_HTTP_HEADER_BUFFER 1024
#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.
#define SRS_HLS_NOTIFY_TIMEOUT_US (int64_t)(10*1000*1000LL)
// the timeout for hls notify, in ms.
#define SRS_HLS_NOTIFY_TMMS (10 * 1000)
SrsHttpHooks::SrsHttpHooks()
{
@ -383,7 +383,7 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::
}
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;
}

View file

@ -155,9 +155,9 @@ int SrsBufferCache::cycle()
}
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.
st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS * 1000);
// ignore when nothing got.
continue;
@ -165,7 +165,7 @@ int SrsBufferCache::cycle()
if (pprint->can_print()) {
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.
@ -557,9 +557,9 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
}
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.
st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS);
// ignore when nothing got.
continue;
@ -567,7 +567,7 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
if (pprint->can_print()) {
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.

View file

@ -39,7 +39,7 @@ using namespace std;
// when error, ingester sleep for a while and retry.
// 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()
{
@ -109,7 +109,7 @@ SrsIngester::SrsIngester()
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();
}

View file

@ -40,7 +40,7 @@ using namespace std;
#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_AGGREGATE_SIZE 1
@ -366,7 +366,7 @@ SrsKafkaProducer::SrsKafkaProducer()
metadata_expired = st_cond_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();
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());
}
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);
SrsKafkaClient* kafka = new SrsKafkaClient(transport);

View file

@ -616,9 +616,9 @@ int SrsMpegtsOverUdp::connect()
return ret;
}
int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
sdk = new SrsSimpleRtmpClient(output, cto/1000, sto/1000);
int64_t cto = SRS_CONSTS_RTMP_TMMS;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
sdk = new SrsSimpleRtmpClient(output, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
close();

View file

@ -37,11 +37,11 @@ using namespace std;
#include <srs_protocol_utility.hpp>
// 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()
{
pthread = new SrsReusableThread("encoder", this, SRS_RTMP_EXEC_SLEEP_US);
pthread = new SrsReusableThread("encoder", this, SRS_RTMP_EXEC_CIMS);
pprint = SrsPithyPrint::create_exec();
}

View file

@ -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;
rtmp = rtmp_sdk;
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.
// @see https://github.com/ossrs/srs/issues/194
// @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();
}

View file

@ -86,9 +86,12 @@ protected:
SrsReusableThread2* trd;
ISrsMessageHandler* handler;
SrsRtmpServer* rtmp;
// The recv timeout in ms.
int timeout;
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();
public:
virtual int cid();

View file

@ -60,22 +60,22 @@ using namespace std;
// when stream is busy, for example, streaming is already
// publishing, when a new client to request to publish,
// 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.
#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.
#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.
#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.
#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.
#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)
{
@ -348,8 +348,8 @@ int SrsRtmpConn::do_cycle()
}
#endif
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TMMS);
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS);
if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {
srs_error("rtmp handshake failed. ret=%d", ret);
@ -634,8 +634,8 @@ int SrsRtmpConn::service_cycle()
// for republish, continue service
if (ret == ERROR_CONTROL_REPUBLISH) {
// set timeout to a larger value, wait for encoder to republish.
rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TIMEOUT_US);
rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TIMEOUT_US);
rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TMMS);
rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TMMS);
srs_trace("control message(unpublish) accept, retry stream service.");
continue;
@ -647,8 +647,8 @@ int SrsRtmpConn::service_cycle()
// TODO: FIXME: use ping message to anti-death of socket.
// @see: https://github.com/ossrs/srs/issues/39
// set timeout to a larger value, for user paused.
rtmp->set_recv_timeout(SRS_PAUSED_RECV_TIMEOUT_US);
rtmp->set_send_timeout(SRS_PAUSED_SEND_TIMEOUT_US);
rtmp->set_recv_timeout(SRS_PAUSED_RECV_TMMS);
rtmp->set_send_timeout(SRS_PAUSED_SEND_TMMS);
srs_trace("control message(close) accept, retry stream service.");
continue;
@ -685,8 +685,8 @@ int SrsRtmpConn::stream_service_cycle()
srs_info("security check ok");
// client is identified, set the timeout to service timeout.
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TMMS);
rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS);
// find a source to serve.
SrsSource* source = NULL;
@ -1465,7 +1465,7 @@ int SrsRtmpConn::check_edge_token_traverse_auth()
int port = SRS_CONSTS_RTMP_DEFAULT_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);
if ((ret = transport->connect()) != ERROR_SUCCESS) {
@ -1490,8 +1490,8 @@ int SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client)
srs_assert(client);
client->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
client->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US);
client->set_recv_timeout(SRS_CONSTS_RTMP_TMMS);
client->set_send_timeout(SRS_CONSTS_RTMP_TMMS);
if ((ret = client->handshake()) != ERROR_SUCCESS) {
srs_error("handshake with server failed. ret=%d", ret);

View file

@ -669,9 +669,9 @@ int SrsRtspConn::connect()
}
// connect host.
int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000);
int64_t cto = SRS_CONSTS_RTMP_TMMS;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
sdk = new SrsSimpleRtmpClient(url, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
close();

View file

@ -62,7 +62,6 @@ using namespace std;
// update time interval:
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES
// @see SYS_TIME_RESOLUTION_US
#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 1
// update rusage interval:

View file

@ -538,7 +538,7 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count)
void SrsConsumer::wait(int nb_msgs, int duration)
{
if (paused) {
st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS);
return;
}

View file

@ -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;
handler = thread_handler;
cycle_interval_us = interval_us;
cims = ims;
tid = NULL;
loop = false;
@ -231,10 +231,11 @@ namespace internal
break;
}
// Should never use no timeout, just ignore it.
// to improve performance, donot sleep when interval is zero.
// @see: https://github.com/ossrs/srs/issues/237
if (cycle_interval_us != 0) {
st_usleep(cycle_interval_us);
if (cims != 0 && cims != SRS_CONSTS_NO_TMMS) {
st_usleep(cims * 1000);
}
}
@ -268,54 +269,60 @@ namespace internal
SrsStSocket::SrsStSocket(st_netfd_t client_stfd)
{
stfd = client_stfd;
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
recv_bytes = send_bytes = 0;
stm = rtm = SRS_CONSTS_NO_TMMS;
rbytes = sbytes = 0;
}
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()
{
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()
{
return send_timeout;
return stm;
}
int64_t SrsStSocket::get_recv_bytes()
{
return recv_bytes;
return rbytes;
}
int64_t SrsStSocket::get_send_bytes()
{
return send_bytes;
return sbytes;
}
int SrsStSocket::read(void* buf, size_t size, ssize_t* nread)
{
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) {
*nread = nb_read;
}
@ -336,7 +343,7 @@ int SrsStSocket::read(void* buf, size_t size, ssize_t* nread)
return ERROR_SOCKET_READ;
}
recv_bytes += nb_read;
rbytes += nb_read;
return ret;
}
@ -345,7 +352,13 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread)
{
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) {
*nread = nb_read;
}
@ -366,7 +379,7 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread)
return ERROR_SOCKET_READ_FULLY;
}
recv_bytes += nb_read;
rbytes += nb_read;
return ret;
}
@ -375,7 +388,13 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite)
{
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) {
*nwrite = nb_write;
}
@ -391,7 +410,7 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite)
return ERROR_SOCKET_WRITE;
}
send_bytes += nb_write;
sbytes += nb_write;
return ret;
}
@ -400,7 +419,13 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
{
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) {
*nwrite = nb_write;
}
@ -416,7 +441,7 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
return ERROR_SOCKET_WRITE;
}
send_bytes += nb_write;
sbytes += nb_write;
return ret;
}
@ -443,7 +468,7 @@ int SrsTcpClient::connect()
close();
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);
return ret;
}
@ -465,14 +490,14 @@ void SrsTcpClient::close()
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()
@ -480,9 +505,9 @@ int64_t SrsTcpClient::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()

View file

@ -110,13 +110,14 @@ namespace internal
bool disposed;
private:
ISrsThreadHandler* handler;
int64_t cycle_interval_us;
// The cycle interval in ms.
int64_t cims;
public:
/**
* initialize the thread.
* @param name, human readable name for st debug.
* @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.
* @remark if joinable, thread never quit itself, or memory leak.
* @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,
* @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();
public:
/**
@ -175,19 +176,23 @@ namespace internal
class SrsStSocket : public ISrsProtocolReaderWriter
{
private:
int64_t recv_timeout;
int64_t send_timeout;
int64_t recv_bytes;
int64_t send_bytes;
// The recv/send timeout in ms.
// @remark Use SRS_CONSTS_NO_TMMS for never timeout in ms.
int64_t rtm;
int64_t stm;
// The recv/send data in bytes
int64_t rbytes;
int64_t sbytes;
// The underlayer st fd.
st_netfd_t stfd;
public:
SrsStSocket(st_netfd_t client_stfd);
virtual ~SrsStSocket();
public:
virtual bool is_never_timeout(int64_t timeout_us);
virtual void set_recv_timeout(int64_t timeout_us);
virtual bool is_never_timeout(int64_t tm);
virtual void set_recv_timeout(int64_t tm);
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_recv_bytes();
virtual int64_t get_send_bytes();
@ -221,6 +226,7 @@ private:
private:
std::string host;
int port;
// The timeout in ms.
int64_t timeout;
public:
/**
@ -244,10 +250,10 @@ public:
virtual void close();
// interface ISrsProtocolReaderWriter
public:
virtual bool is_never_timeout(int64_t timeout_us);
virtual void set_recv_timeout(int64_t timeout_us);
virtual bool is_never_timeout(int64_t tm);
virtual void set_recv_timeout(int64_t tm);
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_recv_bytes();
virtual int64_t get_send_bytes();

View file

@ -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;
pthread = new internal::SrsThread(n, this, interval_us, true);
pthread = new internal::SrsThread(n, this, cims, true);
}
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;
pthread = new internal::SrsThread(n, this, interval_us, true);
pthread = new internal::SrsThread(n, this, cims, true);
}
SrsReusableThread2::~SrsReusableThread2()

View file

@ -162,7 +162,7 @@ public:
* 2. must manually stop the thread when started it.
* for example:
* 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 void stop() { pthread->stop(); }
* public: virtual int cycle() {
@ -198,7 +198,7 @@ private:
internal::SrsThread* pthread;
ISrsReusableThreadHandler* handler;
public:
SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t interval_us = 0);
SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t cims = 0);
virtual ~SrsReusableThread();
public:
/**
@ -244,7 +244,7 @@ public:
* 2. must manually stop the thread when started it.
* for example:
* 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 void stop() { pthread->stop(); }
* public: virtual int cycle() {
@ -287,7 +287,7 @@ private:
internal::SrsThread* pthread;
ISrsReusableThread2Handler* handler;
public:
SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t interval_us = 0);
SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t cims = 0);
virtual ~SrsReusableThread2();
public:
/**

View file

@ -53,10 +53,15 @@ using namespace std;
// the longest time to wait for a process to quit.
#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;
st_utime_t timeout = ST_UTIME_NO_TIMEOUT;
if (tm != SRS_CONSTS_NO_TMMS) {
timeout = (st_utime_t)(tm * 1000);
}
*pstfd = NULL;
st_netfd_t stfd = NULL;
sockaddr_in addr;

View file

@ -44,7 +44,8 @@ class SrsBuffer;
class SrsJsonObject;
// 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.

View file

@ -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,
// 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.
// 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,
// if timeout, we generally ignore and send the data to client,
// generally, it's the pulse time for data seding.
// @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:
@ -225,7 +228,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_CONSTS_HTTP_QUERY_SEP '?'
// 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
#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
// the common io timeout, for both recv and send.
// TODO: FIXME: use ms for timeout.
#define SRS_CONSTS_KAFKA_TIMEOUT_US (int64_t)(30*1000*1000LL)
#define SRS_CONSTS_KAFKA_TMMS (30*1000)
#endif

View file

@ -135,8 +135,7 @@ int64_t srs_update_system_time_ms()
// use date +%s to get system time is 1403844851.
// so we use relative time.
if (_srs_system_time_us_cache <= 0) {
_srs_system_time_us_cache = now_us;
_srs_system_time_startup_time = now_us;
_srs_system_time_startup_time = _srs_system_time_us_cache = now_us;
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;
diff = srs_max(0, diff);
if (diff < 0 || diff > 1000 * SYS_TIME_RESOLUTION_US) {
srs_warn("system time jump, history=%"PRId64"us, now=%"PRId64"us, diff=%"PRId64"us",
_srs_system_time_us_cache, now_us, diff);
srs_warn("clock jump, history=%"PRId64"us, now=%"PRId64"us, diff=%"PRId64"us", _srs_system_time_us_cache, now_us, diff);
// @see: https://github.com/ossrs/srs/issues/109
_srs_system_time_startup_time += diff;
}
_srs_system_time_us_cache = now_us;
srs_info("system time updated, startup=%"PRId64"us, now=%"PRId64"us",
_srs_system_time_startup_time, _srs_system_time_us_cache);
srs_info("clock updated, startup=%"PRId64"us, now=%"PRId64"us", _srs_system_time_startup_time, _srs_system_time_us_cache);
return _srs_system_time_us_cache / 1000;
}

View file

@ -66,24 +66,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <errno.h>
#include <srs_kernel_utility.hpp>
#ifndef ST_UTIME_NO_TIMEOUT
#define ST_UTIME_NO_TIMEOUT -1
#endif
#include <srs_kernel_consts.hpp>
// when io not hijacked, use simple socket, the block sync stream.
#ifndef SRS_HIJACK_IO
struct SrsBlockSyncSocket
{
SOCKET fd;
int64_t recv_timeout;
int64_t send_timeout;
int64_t recv_bytes;
int64_t send_bytes;
int64_t rbytes;
int64_t sbytes;
// The send/recv timeout in ms.
int64_t rtm;
int64_t stm;
SrsBlockSyncSocket() {
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
recv_bytes = send_bytes = 0;
stm = rtm = SRS_CONSTS_NO_TMMS;
rbytes = sbytes = 0;
SOCKET_RESET(fd);
SOCKET_SETUP();
@ -156,66 +154,75 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return ERROR_SOCKET_READ;
}
skt->recv_bytes += nb_read;
skt->rbytes += nb_read;
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;
int sec = (int)(timeout_us / 1000000LL);
int microsec = (int)(timeout_us % 1000000LL);
// The default for this option is zero,
// which indicates that a receive operation shall not time out.
int32_t sec = 0;
int32_t usec = 0;
sec = srs_max(0, sec);
microsec = srs_max(0, microsec);
if (tm != SRS_CONSTS_NO_TMMS) {
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) {
return SOCKET_ERRNO();
}
skt->recv_timeout = timeout_us;
skt->rtm = tm;
return ERROR_SUCCESS;
}
int64_t srs_hijack_io_get_recv_timeout(srs_hijack_io_t 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)
{
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;
int sec = (int)(timeout_us / 1000000LL);
int microsec = (int)(timeout_us % 1000000LL);
// The default for this option is zero,
// which indicates that a receive operation shall not time out.
int32_t sec = 0;
int32_t usec = 0;
sec = srs_max(0, sec);
microsec = srs_max(0, microsec);
if (tm != SRS_CONSTS_NO_TMMS) {
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) {
return SOCKET_ERRNO();
}
skt->send_timeout = timeout_us;
skt->stm = tm;
return ERROR_SUCCESS;
}
int64_t srs_hijack_io_get_send_timeout(srs_hijack_io_t 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)
{
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)
{
@ -241,13 +248,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return ERROR_SOCKET_WRITE;
}
skt->send_bytes += nb_write;
skt->sbytes += nb_write;
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)
{
@ -273,7 +280,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if (nread) {
*nread = nb_read;
}
skt->recv_bytes += nb_read;
skt->rbytes += nb_read;
return ret;
}
@ -298,7 +305,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return ERROR_SOCKET_WRITE;
}
skt->send_bytes += nb_write;
skt->sbytes += nb_write;
return ret;
}
@ -342,10 +349,10 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread)
}
// ISrsProtocolReader
void SimpleSocketStream::set_recv_timeout(int64_t timeout_us)
void SimpleSocketStream::set_recv_timeout(int64_t tm)
{
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()
@ -361,10 +368,10 @@ int64_t SimpleSocketStream::get_recv_bytes()
}
// ISrsProtocolWriter
void SimpleSocketStream::set_send_timeout(int64_t timeout_us)
void SimpleSocketStream::set_send_timeout(int64_t tm)
{
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()
@ -386,10 +393,10 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
}
// ISrsProtocolReaderWriter
bool SimpleSocketStream::is_never_timeout(int64_t timeout_us)
bool SimpleSocketStream::is_never_timeout(int64_t tm)
{
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)

View file

@ -58,18 +58,18 @@ public:
virtual int read(void* buf, size_t size, ssize_t* nread);
// ISrsProtocolReader
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_bytes();
// ISrsProtocolWriter
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_bytes();
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
// ISrsProtocolReaderWriter
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 write(void* buf, size_t size, ssize_t* nwrite);
};

View file

@ -54,8 +54,8 @@ using namespace std;
ISrsLog* _srs_log = new ISrsLog();
ISrsThreadContext* _srs_context = new ISrsThreadContext();
// use this default timeout in us, if user not set.
#define SRS_SOCKET_DEFAULT_TIMEOUT 30 * 1000 * 1000LL
// The default socket timeout in ms.
#define SRS_SOCKET_DEFAULT_TMMS (30 * 1000)
/**
* export runtime context.
@ -108,7 +108,7 @@ struct Context
// the aac sequence header.
std::string aac_specific_config;
// user set timeout, in us.
// user set timeout, in ms.
int64_t stimeout;
int64_t rtimeout;
@ -120,7 +120,7 @@ struct Context
h264_sps_pps_sent = false;
h264_sps_changed = false;
h264_pps_changed = false;
rtimeout = stimeout = -1;
rtimeout = stimeout = SRS_CONSTS_NO_TMMS;
}
virtual ~Context() {
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->stimeout = send_timeout_ms * 1000;
context->rtimeout = recv_timeout_ms * 1000;
context->stimeout = send_timeout_ms;
context->rtimeout = recv_timeout_ms;
context->skt->set_recv_timeout(context->rtimeout);
context->skt->set_send_timeout(context->stimeout);
@ -646,12 +646,12 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp)
Context* context = (Context*)rtmp;
// set timeout if user not set.
if (context->stimeout == -1) {
context->stimeout = SRS_SOCKET_DEFAULT_TIMEOUT;
if (context->stimeout == SRS_CONSTS_NO_TMMS) {
context->stimeout = SRS_SOCKET_DEFAULT_TMMS;
context->skt->set_send_timeout(context->stimeout);
}
if (context->rtimeout == -1) {
context->rtimeout = SRS_SOCKET_DEFAULT_TIMEOUT;
if (context->rtimeout == SRS_CONSTS_NO_TMMS) {
context->rtimeout = SRS_SOCKET_DEFAULT_TMMS;
context->skt->set_recv_timeout(context->rtimeout);
}

View file

@ -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);
/**
* set the socket recv timeout.
* set the socket recv timeout in ms.
* @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.
* @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);
/**
* set the socket send timeout.
* set the socket send timeout in ms.
* @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.
* @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);
/**
* whether the timeout is never timeout.
* whether the timeout is never timeout in ms.
* @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.
* @return 0, success; otherswise, failed.

View file

@ -1226,9 +1226,9 @@ int SrsIngestSrsOutput::connect()
srs_trace("connect output=%s", url.c_str());
// connect host.
int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US;
sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000);
int64_t cto = SRS_CONSTS_RTMP_TMMS;
int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS;
sdk = new SrsSimpleRtmpClient(url, cto, sto);
if ((ret = sdk->connect()) != ERROR_SUCCESS) {
close();

View file

@ -126,12 +126,12 @@ public:
// for protocol
public:
/**
* set the recv timeout in us, recv will error when timeout.
* @remark, if not set, use ST_UTIME_NO_TIMEOUT, never timeout.
* Set the timeout tm in ms for recv bytes from peer.
* @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;
// for handshake.
@ -154,12 +154,12 @@ public:
// for protocol
public:
/**
* set the send timeout in us, send will error when timeout.
* @remark, if not set, use ST_UTIME_NO_TIMEOUT, never timeout.
* Set the timeout tm in ms for send bytes to peer.
* @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;
};
@ -175,9 +175,9 @@ public:
// for protocol
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

View file

@ -325,9 +325,9 @@ void SrsProtocol::set_recv_buffer(int buffer_size)
}
#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()
@ -335,9 +335,9 @@ int64_t SrsProtocol::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()
@ -1982,14 +1982,14 @@ SrsRtmpClient::~SrsRtmpClient()
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()
@ -2410,9 +2410,9 @@ void SrsRtmpServer::set_recv_buffer(int buffer_size)
}
#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()
@ -2420,9 +2420,9 @@ int64_t SrsRtmpServer::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()
@ -2621,7 +2621,7 @@ int SrsRtmpServer::response_connect_app(SrsRequest *req, const char* server_ip)
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 ret = ERROR_SUCCESS;
@ -2649,7 +2649,7 @@ int SrsRtmpServer::redirect(SrsRequest* r, string host, int port, bool& accepted
// client must response a call message.
// 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) {
SrsCommonMessage* msg = NULL;
SrsCallPacket* pkt = NULL;

View file

@ -313,16 +313,16 @@ public:
#endif
public:
/**
* set/get the recv timeout in us.
* set/get the recv timeout in ms.
* 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();
/**
* set/get the send timeout in us.
* set/get the send timeout in ms.
* 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();
/**
* get recv/send bytes.
@ -683,62 +683,14 @@ public:
virtual ~SrsRtmpClient();
// protocol methods proxy
public:
/**
* set the recv timeout in us.
* 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 void set_recv_timeout(int64_t tm);
virtual void set_send_timeout(int64_t tm);
virtual int64_t get_recv_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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
public:
/**
@ -865,16 +817,16 @@ public:
virtual void set_recv_buffer(int buffer_size);
#endif
/**
* set/get the recv timeout in us.
* set/get the recv timeout in ms.
* 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();
/**
* set/get the send timeout in us.
* set/get the send timeout in ms.
* 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();
/**
* get recv/send bytes.

View file

@ -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;
}
@ -57,7 +57,7 @@ int MockEmptyIO::write(void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/)
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;
}
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()
{
recv_timeout = send_timeout = ST_UTIME_NO_TIMEOUT;
recv_bytes = send_bytes = 0;
rtm = stm = SRS_CONSTS_NO_TMMS;
rbytes = sbytes = 0;
}
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)
@ -117,7 +117,7 @@ int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread)
}
memcpy(buf, in_buffer.bytes(), size);
recv_bytes += size;
rbytes += size;
if (nread) {
*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)
{
send_bytes += size;
sbytes += size;
if (nwrite) {
*nwrite = size;
}
@ -135,34 +135,34 @@ int MockBufferIO::write(void* buf, size_t size, ssize_t* nwrite)
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()
{
return recv_timeout;
return rtm;
}
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()
{
return send_timeout;
return stm;
}
int64_t MockBufferIO::get_send_bytes()
{
return send_bytes;
return sbytes;
}
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;
}
sbytes += total;
if (nwrite) {
*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);
memcpy(buf, in_buffer.bytes(), available);
recv_bytes += available;
rbytes += available;
if (nread) {
*nread = available;
}
@ -530,8 +532,8 @@ VOID TEST(ProtocolStackTest, ProtocolTimeout)
MockBufferIO bio;
SrsProtocol proto(&bio);
EXPECT_TRUE((int64_t)ST_UTIME_NO_TIMEOUT == proto.get_recv_timeout());
EXPECT_TRUE((int64_t)ST_UTIME_NO_TIMEOUT == proto.get_send_timeout());
EXPECT_TRUE(SRS_CONSTS_NO_TMMS == proto.get_recv_timeout());
EXPECT_TRUE(SRS_CONSTS_NO_TMMS == proto.get_send_timeout());
proto.set_recv_timeout(10);
EXPECT_TRUE(10 == proto.get_recv_timeout());

View file

@ -49,19 +49,19 @@ public:
virtual ~MockEmptyIO();
// for protocol
public:
virtual bool is_never_timeout(int64_t timeout_us);
virtual bool is_never_timeout(int64_t tm);
// for handshake.
public:
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
virtual int write(void* buf, size_t size, ssize_t* nwrite);
// for protocol
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_bytes();
// for protocol
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_bytes();
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
@ -73,10 +73,12 @@ public:
class MockBufferIO : public ISrsProtocolReaderWriter
{
public:
int64_t recv_timeout;
int64_t send_timeout;
int64_t recv_bytes;
int64_t send_bytes;
// The send/recv timeout in ms.
int64_t rtm;
int64_t stm;
// The send/recv data in bytes.
int64_t rbytes;
int64_t sbytes;
// data source for socket read.
SrsSimpleStream in_buffer;
// data buffer for socket send.
@ -86,19 +88,19 @@ public:
virtual ~MockBufferIO();
// for protocol
public:
virtual bool is_never_timeout(int64_t timeout_us);
virtual bool is_never_timeout(int64_t tm);
// for handshake.
public:
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
virtual int write(void* buf, size_t size, ssize_t* nwrite);
// for protocol
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_bytes();
// for protocol
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_bytes();
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);