diff --git a/trunk/src/app/srs_app_http_client.cpp b/trunk/src/app/srs_app_http_client.cpp index 6eb0f663b..299ea180f 100644 --- a/trunk/src/app/srs_app_http_client.cpp +++ b/trunk/src/app/srs_app_http_client.cpp @@ -37,15 +37,13 @@ using namespace std; #include #include -// when error, http client sleep for a while and retry. -#define SRS_HTTP_CLIENT_SLEEP_US (int64_t)(3*1000*1000LL) - SrsHttpClient::SrsHttpClient() { connected = false; stfd = NULL; skt = NULL; parser = NULL; + timeout_us = 0; } SrsHttpClient::~SrsHttpClient() @@ -54,7 +52,7 @@ SrsHttpClient::~SrsHttpClient() srs_freep(parser); } -int SrsHttpClient::initialize(string h, int p) +int SrsHttpClient::initialize(string h, int p, int64_t t_us) { int ret = ERROR_SUCCESS; @@ -68,6 +66,7 @@ int SrsHttpClient::initialize(string h, int p) host = h; port = p; + timeout_us = t_us; return ret; } @@ -183,10 +182,9 @@ int SrsHttpClient::connect() disconnect(); // open socket. - int64_t timeout = SRS_HTTP_CLIENT_SLEEP_US; - if ((ret = srs_socket_connect(host, port, timeout, &stfd)) != ERROR_SUCCESS) { + if ((ret = srs_socket_connect(host, port, timeout_us, &stfd)) != ERROR_SUCCESS) { srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d", - host.c_str(), port, timeout, ret); + host.c_str(), port, timeout_us, ret); return ret; } srs_info("connect to server success. server=%s, port=%d", host, port); @@ -195,6 +193,10 @@ int SrsHttpClient::connect() skt = new SrsStSocket(stfd); connected = true; + // set the recv/send timeout in us. + skt->set_recv_timeout(timeout_us); + skt->set_send_timeout(timeout_us); + return ret; } diff --git a/trunk/src/app/srs_app_http_client.hpp b/trunk/src/app/srs_app_http_client.hpp index 451f336bf..67a3314c2 100644 --- a/trunk/src/app/srs_app_http_client.hpp +++ b/trunk/src/app/srs_app_http_client.hpp @@ -40,6 +40,9 @@ class SrsHttpParser; class SrsHttpMessage; class SrsStSocket; +// the default timeout for http client. +#define SRS_HTTP_CLIENT_TIMEOUT_US (int64_t)(30*1000*1000LL) + /** * http client to GET/POST/PUT/DELETE uri */ @@ -51,6 +54,7 @@ private: SrsStSocket* skt; SrsHttpParser* parser; private: + int64_t timeout_us; // host name or ip. std::string host; int port; @@ -61,7 +65,7 @@ public: /** * initialize the client, connect to host and port. */ - virtual int initialize(std::string h, int p); + virtual int initialize(std::string h, int p, int64_t t_us = SRS_HTTP_CLIENT_TIMEOUT_US); public: /** * to post data to the uri. diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index 59a83ccc6..7824a6978 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -44,6 +44,9 @@ using namespace std; #define SRS_HTTP_HEADER_BUFFER 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) + SrsHttpHooks::SrsHttpHooks() { } @@ -350,7 +353,7 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts } SrsHttpClient http; - if ((ret = http.initialize(uri.get_host(), uri.get_port())) != ERROR_SUCCESS) { + if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TIMEOUT_US)) != ERROR_SUCCESS) { return ret; } diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index af5d5d18c..d0daaef50 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -390,7 +390,7 @@ bool srs_aac_startswith_adts(SrsStream* stream) char* bytes = stream->data() + stream->pos(); char* p = bytes; - if (!stream->require(p - bytes + 2)) { + if (!stream->require((int)(p - bytes) + 2)) { return false; }