mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
Refine SrsTcpClient.timeout in time unit.
This commit is contained in:
parent
feb34ed225
commit
5505eceeac
3 changed files with 13 additions and 14 deletions
|
@ -46,7 +46,7 @@ using namespace std;
|
|||
#define SRS_HTTP_BODY_BUFFER (32 * 1024)
|
||||
|
||||
// the timeout for hls notify, in ms.
|
||||
#define SRS_HLS_NOTIFY_TMMS (10 * SRS_UTIME_SECONDS)
|
||||
#define SRS_HLS_NOTIFY_TIMEOUT (10 * SRS_UTIME_SECONDS)
|
||||
|
||||
SrsHttpHooks::SrsHttpHooks()
|
||||
{
|
||||
|
@ -371,7 +371,7 @@ srs_error_t SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* re
|
|||
}
|
||||
|
||||
SrsHttpClient http;
|
||||
if ((err = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TMMS)) != srs_success) {
|
||||
if ((err = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TIMEOUT)) != srs_success) {
|
||||
return srs_error_wrap(err, "http: init client for %s", url.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -54,8 +54,7 @@ SrsHttpClient::~SrsHttpClient()
|
|||
srs_freep(parser);
|
||||
}
|
||||
|
||||
// TODO: FIXME: use ms for timeout.
|
||||
srs_error_t SrsHttpClient::initialize(string h, int p, int64_t tm)
|
||||
srs_error_t SrsHttpClient::initialize(string h, int p, srs_utime_t tm)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
@ -220,15 +219,15 @@ srs_error_t SrsHttpClient::connect()
|
|||
return err;
|
||||
}
|
||||
|
||||
transport = new SrsTcpClient(host, port, srs_utime_t(timeout * SRS_UTIME_MILLISECONDS));
|
||||
transport = new SrsTcpClient(host, port, timeout);
|
||||
if ((err = transport->connect()) != srs_success) {
|
||||
disconnect();
|
||||
return srs_error_wrap(err, "http: tcp connect %s:%d to=%d", host.c_str(), port, (int)timeout);
|
||||
return srs_error_wrap(err, "http: tcp connect %s:%d to=%dms", host.c_str(), port, srsu2msi(timeout));
|
||||
}
|
||||
|
||||
// Set the recv/send timeout in ms.
|
||||
transport->set_recv_timeout(timeout * SRS_UTIME_MILLISECONDS);
|
||||
transport->set_send_timeout(timeout * SRS_UTIME_MILLISECONDS);
|
||||
// Set the recv/send timeout in srs_utime_t.
|
||||
transport->set_recv_timeout(timeout);
|
||||
transport->set_send_timeout(timeout);
|
||||
|
||||
kbps->set_io(transport, transport);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class SrsWallClock;
|
|||
class SrsTcpClient;
|
||||
|
||||
// the default timeout for http client.
|
||||
#define SRS_HTTP_CLIENT_TMMS (30*1000)
|
||||
#define SRS_HTTP_CLIENT_TIMEOUT (30 * SRS_UTIME_SECONDS)
|
||||
|
||||
/**
|
||||
* The client to GET/POST/PUT/DELETE over HTTP.
|
||||
|
@ -63,8 +63,8 @@ private:
|
|||
SrsKbps* kbps;
|
||||
SrsWallClock* clk;
|
||||
private:
|
||||
// The timeout in ms.
|
||||
int64_t timeout;
|
||||
// The timeout in srs_utime_t.
|
||||
srs_utime_t timeout;
|
||||
// The host name or ip.
|
||||
std::string host;
|
||||
int port;
|
||||
|
@ -74,10 +74,10 @@ public:
|
|||
public:
|
||||
/**
|
||||
* Initliaze the client, disconnect the transport, renew the HTTP parser.
|
||||
* @param tm The underlayer TCP transport timeout in ms.
|
||||
* @param tm The underlayer TCP transport timeout in srs_utime_t.
|
||||
* @remark we will set default values in headers, which can be override by set_header.
|
||||
*/
|
||||
virtual srs_error_t initialize(std::string h, int p, int64_t tm = SRS_HTTP_CLIENT_TMMS);
|
||||
virtual srs_error_t initialize(std::string h, int p, srs_utime_t tm = SRS_HTTP_CLIENT_TIMEOUT);
|
||||
/**
|
||||
* Set HTTP request header in header[k]=v.
|
||||
* @return the HTTP client itself.
|
||||
|
|
Loading…
Reference in a new issue