正在显示
4 个修改的文件
包含
19 行增加
和
10 行删除
| @@ -37,15 +37,13 @@ using namespace std; | @@ -37,15 +37,13 @@ using namespace std; | ||
| 37 | #include <srs_app_utility.hpp> | 37 | #include <srs_app_utility.hpp> |
| 38 | #include <srs_core_autofree.hpp> | 38 | #include <srs_core_autofree.hpp> |
| 39 | 39 | ||
| 40 | -// when error, http client sleep for a while and retry. | ||
| 41 | -#define SRS_HTTP_CLIENT_SLEEP_US (int64_t)(3*1000*1000LL) | ||
| 42 | - | ||
| 43 | SrsHttpClient::SrsHttpClient() | 40 | SrsHttpClient::SrsHttpClient() |
| 44 | { | 41 | { |
| 45 | connected = false; | 42 | connected = false; |
| 46 | stfd = NULL; | 43 | stfd = NULL; |
| 47 | skt = NULL; | 44 | skt = NULL; |
| 48 | parser = NULL; | 45 | parser = NULL; |
| 46 | + timeout_us = 0; | ||
| 49 | } | 47 | } |
| 50 | 48 | ||
| 51 | SrsHttpClient::~SrsHttpClient() | 49 | SrsHttpClient::~SrsHttpClient() |
| @@ -54,7 +52,7 @@ SrsHttpClient::~SrsHttpClient() | @@ -54,7 +52,7 @@ SrsHttpClient::~SrsHttpClient() | ||
| 54 | srs_freep(parser); | 52 | srs_freep(parser); |
| 55 | } | 53 | } |
| 56 | 54 | ||
| 57 | -int SrsHttpClient::initialize(string h, int p) | 55 | +int SrsHttpClient::initialize(string h, int p, int64_t t_us) |
| 58 | { | 56 | { |
| 59 | int ret = ERROR_SUCCESS; | 57 | int ret = ERROR_SUCCESS; |
| 60 | 58 | ||
| @@ -68,6 +66,7 @@ int SrsHttpClient::initialize(string h, int p) | @@ -68,6 +66,7 @@ int SrsHttpClient::initialize(string h, int p) | ||
| 68 | 66 | ||
| 69 | host = h; | 67 | host = h; |
| 70 | port = p; | 68 | port = p; |
| 69 | + timeout_us = t_us; | ||
| 71 | 70 | ||
| 72 | return ret; | 71 | return ret; |
| 73 | } | 72 | } |
| @@ -183,10 +182,9 @@ int SrsHttpClient::connect() | @@ -183,10 +182,9 @@ int SrsHttpClient::connect() | ||
| 183 | disconnect(); | 182 | disconnect(); |
| 184 | 183 | ||
| 185 | // open socket. | 184 | // open socket. |
| 186 | - int64_t timeout = SRS_HTTP_CLIENT_SLEEP_US; | ||
| 187 | - if ((ret = srs_socket_connect(host, port, timeout, &stfd)) != ERROR_SUCCESS) { | 185 | + if ((ret = srs_socket_connect(host, port, timeout_us, &stfd)) != ERROR_SUCCESS) { |
| 188 | srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d", | 186 | srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d", |
| 189 | - host.c_str(), port, timeout, ret); | 187 | + host.c_str(), port, timeout_us, ret); |
| 190 | return ret; | 188 | return ret; |
| 191 | } | 189 | } |
| 192 | srs_info("connect to server success. server=%s, port=%d", host, port); | 190 | srs_info("connect to server success. server=%s, port=%d", host, port); |
| @@ -195,6 +193,10 @@ int SrsHttpClient::connect() | @@ -195,6 +193,10 @@ int SrsHttpClient::connect() | ||
| 195 | skt = new SrsStSocket(stfd); | 193 | skt = new SrsStSocket(stfd); |
| 196 | connected = true; | 194 | connected = true; |
| 197 | 195 | ||
| 196 | + // set the recv/send timeout in us. | ||
| 197 | + skt->set_recv_timeout(timeout_us); | ||
| 198 | + skt->set_send_timeout(timeout_us); | ||
| 199 | + | ||
| 198 | return ret; | 200 | return ret; |
| 199 | } | 201 | } |
| 200 | 202 |
| @@ -40,6 +40,9 @@ class SrsHttpParser; | @@ -40,6 +40,9 @@ class SrsHttpParser; | ||
| 40 | class SrsHttpMessage; | 40 | class SrsHttpMessage; |
| 41 | class SrsStSocket; | 41 | class SrsStSocket; |
| 42 | 42 | ||
| 43 | +// the default timeout for http client. | ||
| 44 | +#define SRS_HTTP_CLIENT_TIMEOUT_US (int64_t)(30*1000*1000LL) | ||
| 45 | + | ||
| 43 | /** | 46 | /** |
| 44 | * http client to GET/POST/PUT/DELETE uri | 47 | * http client to GET/POST/PUT/DELETE uri |
| 45 | */ | 48 | */ |
| @@ -51,6 +54,7 @@ private: | @@ -51,6 +54,7 @@ private: | ||
| 51 | SrsStSocket* skt; | 54 | SrsStSocket* skt; |
| 52 | SrsHttpParser* parser; | 55 | SrsHttpParser* parser; |
| 53 | private: | 56 | private: |
| 57 | + int64_t timeout_us; | ||
| 54 | // host name or ip. | 58 | // host name or ip. |
| 55 | std::string host; | 59 | std::string host; |
| 56 | int port; | 60 | int port; |
| @@ -61,7 +65,7 @@ public: | @@ -61,7 +65,7 @@ public: | ||
| 61 | /** | 65 | /** |
| 62 | * initialize the client, connect to host and port. | 66 | * initialize the client, connect to host and port. |
| 63 | */ | 67 | */ |
| 64 | - virtual int initialize(std::string h, int p); | 68 | + virtual int initialize(std::string h, int p, int64_t t_us = SRS_HTTP_CLIENT_TIMEOUT_US); |
| 65 | public: | 69 | public: |
| 66 | /** | 70 | /** |
| 67 | * to post data to the uri. | 71 | * to post data to the uri. |
| @@ -44,6 +44,9 @@ using namespace std; | @@ -44,6 +44,9 @@ using namespace std; | ||
| 44 | #define SRS_HTTP_HEADER_BUFFER 1024 | 44 | #define SRS_HTTP_HEADER_BUFFER 1024 |
| 45 | #define SRS_HTTP_BODY_BUFFER 32 * 1024 | 45 | #define SRS_HTTP_BODY_BUFFER 32 * 1024 |
| 46 | 46 | ||
| 47 | +// the timeout for hls notify, in us. | ||
| 48 | +#define SRS_HLS_NOTIFY_TIMEOUT_US (int64_t)(10*1000*1000LL) | ||
| 49 | + | ||
| 47 | SrsHttpHooks::SrsHttpHooks() | 50 | SrsHttpHooks::SrsHttpHooks() |
| 48 | { | 51 | { |
| 49 | } | 52 | } |
| @@ -350,7 +353,7 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts | @@ -350,7 +353,7 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts | ||
| 350 | } | 353 | } |
| 351 | 354 | ||
| 352 | SrsHttpClient http; | 355 | SrsHttpClient http; |
| 353 | - if ((ret = http.initialize(uri.get_host(), uri.get_port())) != ERROR_SUCCESS) { | 356 | + if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TIMEOUT_US)) != ERROR_SUCCESS) { |
| 354 | return ret; | 357 | return ret; |
| 355 | } | 358 | } |
| 356 | 359 |
| @@ -390,7 +390,7 @@ bool srs_aac_startswith_adts(SrsStream* stream) | @@ -390,7 +390,7 @@ bool srs_aac_startswith_adts(SrsStream* stream) | ||
| 390 | char* bytes = stream->data() + stream->pos(); | 390 | char* bytes = stream->data() + stream->pos(); |
| 391 | char* p = bytes; | 391 | char* p = bytes; |
| 392 | 392 | ||
| 393 | - if (!stream->require(p - bytes + 2)) { | 393 | + if (!stream->require((int)(p - bytes) + 2)) { |
| 394 | return false; | 394 | return false; |
| 395 | } | 395 | } |
| 396 | 396 |
-
请 注册 或 登录 后发表评论