diff --git a/trunk/src/app/srs_app_bandwidth.cpp b/trunk/src/app/srs_app_bandwidth.cpp index 941efc571..55b474c5a 100644 --- a/trunk/src/app/srs_app_bandwidth.cpp +++ b/trunk/src/app/srs_app_bandwidth.cpp @@ -181,7 +181,7 @@ srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) // timeout for a packet. _rtmp->set_send_timeout(play_sample.duration_ms * 2 * SRS_UTIME_MILLISECONDS); - _rtmp->set_recv_timeout(publish_sample.duration_ms * 2); + _rtmp->set_recv_timeout(publish_sample.duration_ms * 2 * SRS_UTIME_MILLISECONDS); // start test. srs_utime_t start_time = srs_update_system_time(); diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 3911b84bf..1e16dc67e 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -144,7 +144,7 @@ void SrsEdgeRtmpUpstream::close() srs_freep(sdk); } -void SrsEdgeRtmpUpstream::set_recv_timeout(int64_t tm) +void SrsEdgeRtmpUpstream::set_recv_timeout(srs_utime_t tm) { sdk->set_recv_timeout(tm); } @@ -294,7 +294,7 @@ srs_error_t SrsEdgeIngester::ingest() SrsAutoFree(SrsPithyPrint, pprint); // set to larger timeout to read av data from origin. - upstream->set_recv_timeout(srsu2ms(SRS_EDGE_INGESTER_TMMS)); + upstream->set_recv_timeout(SRS_EDGE_INGESTER_TMMS); while (true) { srs_error_t err = srs_success; @@ -533,7 +533,7 @@ srs_error_t SrsEdgeForwarder::do_cycle() { srs_error_t err = srs_success; - sdk->set_recv_timeout(srsu2ms(SRS_CONSTS_RTMP_PULSE)); + sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE); SrsPithyPrint* pprint = SrsPithyPrint::create_edge(); SrsAutoFree(SrsPithyPrint, pprint); diff --git a/trunk/src/app/srs_app_edge.hpp b/trunk/src/app/srs_app_edge.hpp index 03d6b70fc..ab3f2f5c5 100644 --- a/trunk/src/app/srs_app_edge.hpp +++ b/trunk/src/app/srs_app_edge.hpp @@ -86,7 +86,7 @@ public: virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0; virtual void close() = 0; public: - virtual void set_recv_timeout(int64_t tm) = 0; + virtual void set_recv_timeout(srs_utime_t tm) = 0; virtual void kbps_sample(const char* label, int64_t age) = 0; }; @@ -107,7 +107,7 @@ public: virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket); virtual void close(); public: - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual void kbps_sample(const char* label, int64_t age); }; diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index 7b54d6080..3bcb78e27 100755 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -242,7 +242,7 @@ srs_error_t SrsForwarder::forward() { srs_error_t err = srs_success; - sdk->set_recv_timeout(srsu2ms(SRS_CONSTS_RTMP_PULSE)); + sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE); SrsPithyPrint* pprint = SrsPithyPrint::create_forwarder(); SrsAutoFree(SrsPithyPrint, pprint); diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 0d1821bae..e9b5f5f52 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -116,7 +116,7 @@ srs_error_t SrsRecvThread::cycle() } // reset the timeout to pulse mode. - rtmp->set_recv_timeout(timeout * 1000); + rtmp->set_recv_timeout(timeout * SRS_UTIME_MILLISECONDS); pumper->on_stop(); diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index de6ce2087..61c0f2c40 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -166,7 +166,7 @@ srs_error_t SrsRtmpConn::do_cycle() } #endif - rtmp->set_recv_timeout(srsu2ms(SRS_CONSTS_RTMP_TIMEOUT)); + rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT); rtmp->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT); if ((err = rtmp->handshake()) != srs_success) { @@ -411,7 +411,7 @@ srs_error_t SrsRtmpConn::service_cycle() if (srs_error_code(err) == ERROR_CONTROL_REPUBLISH) { // set timeout to a larger value, wait for encoder to republish. rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TMMS); - rtmp->set_recv_timeout(srsu2ms(SRS_REPUBLISH_SEND_TMMS)); + rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TMMS); srs_trace("rtmp: retry for republish"); srs_freep(err); @@ -425,7 +425,7 @@ srs_error_t SrsRtmpConn::service_cycle() // @see: https://github.com/ossrs/srs/issues/39 // set timeout to a larger value, for user paused. rtmp->set_recv_timeout(SRS_PAUSED_RECV_TMMS); - rtmp->set_send_timeout(srsu2ms(SRS_PAUSED_SEND_TMMS)); + rtmp->set_send_timeout(SRS_PAUSED_SEND_TMMS); srs_trace("rtmp: retry for close"); srs_freep(err); @@ -498,7 +498,7 @@ srs_error_t SrsRtmpConn::stream_service_cycle() } // client is identified, set the timeout to service timeout. - rtmp->set_recv_timeout(srsu2ms(SRS_CONSTS_RTMP_TIMEOUT)); + rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT); rtmp->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT); // find a source to serve. @@ -1183,7 +1183,7 @@ srs_error_t SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client) SrsRequest* req = info->req; srs_assert(client); - client->set_recv_timeout(srsu2ms(SRS_CONSTS_RTMP_TIMEOUT)); + client->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT); client->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT); if ((err = client->handshake()) != srs_success) { diff --git a/trunk/src/libs/srs_lib_simple_socket.cpp b/trunk/src/libs/srs_lib_simple_socket.cpp index a810629be..fb4b0449b 100644 --- a/trunk/src/libs/srs_lib_simple_socket.cpp +++ b/trunk/src/libs/srs_lib_simple_socket.cpp @@ -377,10 +377,10 @@ srs_error_t SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) } // ISrsProtocolReader -void SimpleSocketStream::set_recv_timeout(int64_t tm) +void SimpleSocketStream::set_recv_timeout(SrsQueueRecvThread tm) { srs_assert(io); - srs_hijack_io_set_recv_timeout(io, tm); + srs_hijack_io_set_recv_timeout(io, srsu2ms(tm)); } int64_t SimpleSocketStream::get_recv_timeout() diff --git a/trunk/src/libs/srs_lib_simple_socket.hpp b/trunk/src/libs/srs_lib_simple_socket.hpp index c5a63bedf..c86daeada 100644 --- a/trunk/src/libs/srs_lib_simple_socket.hpp +++ b/trunk/src/libs/srs_lib_simple_socket.hpp @@ -54,7 +54,7 @@ public: virtual srs_error_t read(void* buf, size_t size, ssize_t* nread); // ISrsProtocolReader public: - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual int64_t get_recv_timeout(); virtual int64_t get_recv_bytes(); // ISrsProtocolWriter diff --git a/trunk/src/libs/srs_librtmp.cpp b/trunk/src/libs/srs_librtmp.cpp index 285808873..012c2637d 100644 --- a/trunk/src/libs/srs_librtmp.cpp +++ b/trunk/src/libs/srs_librtmp.cpp @@ -572,7 +572,7 @@ int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_ context->stimeout = send_timeout_ms; context->rtimeout = recv_timeout_ms; - context->skt->set_recv_timeout(context->rtimeout); + context->skt->set_recv_timeout(context->rtimeout * SRS_UTIME_MILLISECONDS); context->skt->set_send_timeout(context->stimeout * SRS_UTIME_MILLISECONDS); return ret; @@ -641,7 +641,7 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp) } if (context->rtimeout == SRS_UTIME_NO_TIMEOUT) { context->rtimeout = SRS_SOCKET_DEFAULT_TMMS; - context->skt->set_recv_timeout(context->rtimeout); + context->skt->set_recv_timeout(context->rtimeout * SRS_UTIME_MILLISECONDS); } if ((ret = srs_librtmp_context_connect(context)) != ERROR_SUCCESS) { diff --git a/trunk/src/protocol/srs_protocol_io.hpp b/trunk/src/protocol/srs_protocol_io.hpp index 50a85dc6e..97c33a756 100644 --- a/trunk/src/protocol/srs_protocol_io.hpp +++ b/trunk/src/protocol/srs_protocol_io.hpp @@ -84,9 +84,9 @@ public: virtual ~ISrsProtocolReader(); // for protocol public: - // Set the timeout tm in ms for recv bytes from peer. + // Set the timeout tm in srs_utime_t for recv bytes from peer. // @remark Use SRS_UTIME_NO_TIMEOUT to never timeout. - virtual void set_recv_timeout(int64_t tm) = 0; + virtual void set_recv_timeout(srs_utime_t tm) = 0; // Get the timeout in ms for recv bytes from peer. virtual int64_t get_recv_timeout() = 0; // For handshake. diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp index 928b3afa5..b9ca8d32a 100644 --- a/trunk/src/protocol/srs_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_rtmp_stack.cpp @@ -304,7 +304,7 @@ void SrsProtocol::set_recv_buffer(int buffer_size) } #endif -void SrsProtocol::set_recv_timeout(int64_t tm) +void SrsProtocol::set_recv_timeout(srs_utime_t tm) { return skt->set_recv_timeout(tm); } @@ -1815,7 +1815,7 @@ SrsRtmpClient::~SrsRtmpClient() srs_freep(hs_bytes); } -void SrsRtmpClient::set_recv_timeout(int64_t tm) +void SrsRtmpClient::set_recv_timeout(srs_utime_t tm) { protocol->set_recv_timeout(tm); } @@ -2210,7 +2210,7 @@ void SrsRtmpServer::set_recv_buffer(int buffer_size) } #endif -void SrsRtmpServer::set_recv_timeout(int64_t tm) +void SrsRtmpServer::set_recv_timeout(srs_utime_t tm) { protocol->set_recv_timeout(tm); } @@ -2408,7 +2408,7 @@ srs_error_t SrsRtmpServer::response_connect_app(SrsRequest *req, const char* ser return err; } -#define SRS_RTMP_REDIRECT_TMMS 3000 +#define SRS_RTMP_REDIRECT_TMMS (3 * SRS_UTIME_SECONDS) srs_error_t SrsRtmpServer::redirect(SrsRequest* r, string host, int port, bool& accepted) { srs_error_t err = srs_success; diff --git a/trunk/src/protocol/srs_rtmp_stack.hpp b/trunk/src/protocol/srs_rtmp_stack.hpp index ec00bf9df..67ba4cdd9 100644 --- a/trunk/src/protocol/srs_rtmp_stack.hpp +++ b/trunk/src/protocol/srs_rtmp_stack.hpp @@ -304,11 +304,10 @@ public: #endif public: /** - * set/get the recv timeout in ms. + * set/get the recv timeout in srs_utime_t. * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. */ - // TODO: FIXME: Refine tm in time unit. - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual int64_t get_recv_timeout(); /** * set/get the send timeout in srs_utime_t. @@ -688,7 +687,7 @@ public: virtual ~SrsRtmpClient(); // protocol methods proxy public: - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual void set_send_timeout(srs_utime_t tm); virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); @@ -805,10 +804,10 @@ public: virtual void set_recv_buffer(int buffer_size); #endif /** - * set/get the recv timeout in ms. + * set/get the recv timeout in srs_utime_t. * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. */ - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual int64_t get_recv_timeout(); /** * set/get the send timeout in srs_utime_t. diff --git a/trunk/src/service/srs_service_http_client.cpp b/trunk/src/service/srs_service_http_client.cpp index e46c6b600..b03dd2baf 100644 --- a/trunk/src/service/srs_service_http_client.cpp +++ b/trunk/src/service/srs_service_http_client.cpp @@ -186,7 +186,7 @@ srs_error_t SrsHttpClient::get(string path, string req, ISrsHttpMessage** ppmsg) return err; } -void SrsHttpClient::set_recv_timeout(int64_t tm) +void SrsHttpClient::set_recv_timeout(srs_utime_t tm) { transport->set_recv_timeout(tm); } @@ -227,7 +227,7 @@ srs_error_t SrsHttpClient::connect() } // Set the recv/send timeout in ms. - transport->set_recv_timeout(timeout); + transport->set_recv_timeout(timeout * SRS_UTIME_MILLISECONDS); transport->set_send_timeout(timeout * SRS_UTIME_MILLISECONDS); kbps->set_io(transport, transport); diff --git a/trunk/src/service/srs_service_http_client.hpp b/trunk/src/service/srs_service_http_client.hpp index e0a06a84c..59c53e9b3 100644 --- a/trunk/src/service/srs_service_http_client.hpp +++ b/trunk/src/service/srs_service_http_client.hpp @@ -101,7 +101,7 @@ public: */ virtual srs_error_t get(std::string path, std::string req, ISrsHttpMessage** ppmsg); private: - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); public: virtual void kbps_sample(const char* label, int64_t age); private: diff --git a/trunk/src/service/srs_service_rtmp_conn.cpp b/trunk/src/service/srs_service_rtmp_conn.cpp index 0ca01540f..e7cc2b58c 100644 --- a/trunk/src/service/srs_service_rtmp_conn.cpp +++ b/trunk/src/service/srs_service_rtmp_conn.cpp @@ -74,7 +74,7 @@ srs_error_t SrsBasicRtmpClient::connect() return srs_error_wrap(err, "connect"); } - client->set_recv_timeout(stream_timeout); + client->set_recv_timeout(stream_timeout * SRS_UTIME_MILLISECONDS); client->set_send_timeout(stream_timeout * SRS_UTIME_MILLISECONDS); // connect to vhost/app @@ -234,7 +234,7 @@ srs_error_t SrsBasicRtmpClient::send_and_free_message(SrsSharedPtrMessage* msg) return client->send_and_free_message(msg, stream_id); } -void SrsBasicRtmpClient::set_recv_timeout(int64_t timeout) +void SrsBasicRtmpClient::set_recv_timeout(srs_utime_t timeout) { transport->set_recv_timeout(timeout); } diff --git a/trunk/src/service/srs_service_rtmp_conn.hpp b/trunk/src/service/srs_service_rtmp_conn.hpp index 275e45dcb..59bbb878a 100644 --- a/trunk/src/service/srs_service_rtmp_conn.hpp +++ b/trunk/src/service/srs_service_rtmp_conn.hpp @@ -87,7 +87,7 @@ public: virtual srs_error_t send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs); virtual srs_error_t send_and_free_message(SrsSharedPtrMessage* msg); public: - virtual void set_recv_timeout(int64_t timeout); + virtual void set_recv_timeout(srs_utime_t timeout); }; #endif diff --git a/trunk/src/service/srs_service_st.cpp b/trunk/src/service/srs_service_st.cpp index 717bf7803..6f5c8e6d1 100644 --- a/trunk/src/service/srs_service_st.cpp +++ b/trunk/src/service/srs_service_st.cpp @@ -251,7 +251,7 @@ bool SrsStSocket::is_never_timeout(int64_t tm) return tm == SRS_UTIME_NO_TIMEOUT; } -void SrsStSocket::set_recv_timeout(int64_t tm) +void SrsStSocket::set_recv_timeout(srs_utime_t tm) { rtm = tm; } @@ -465,7 +465,7 @@ bool SrsTcpClient::is_never_timeout(int64_t tm) return io->is_never_timeout(tm); } -void SrsTcpClient::set_recv_timeout(int64_t tm) +void SrsTcpClient::set_recv_timeout(srs_utime_t tm) { io->set_recv_timeout(tm); } diff --git a/trunk/src/service/srs_service_st.hpp b/trunk/src/service/srs_service_st.hpp index f1174bdc9..2a4b4e788 100644 --- a/trunk/src/service/srs_service_st.hpp +++ b/trunk/src/service/srs_service_st.hpp @@ -126,7 +126,7 @@ public: virtual srs_error_t initialize(srs_netfd_t fd); public: virtual bool is_never_timeout(int64_t tm); - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual int64_t get_recv_timeout(); virtual void set_send_timeout(srs_utime_t tm); virtual srs_utime_t get_send_timeout(); @@ -189,7 +189,7 @@ private: // interface ISrsProtocolReadWriter public: virtual bool is_never_timeout(int64_t tm); - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual int64_t get_recv_timeout(); virtual void set_send_timeout(srs_utime_t tm); virtual srs_utime_t get_send_timeout(); diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index ad6187b3e..59f26ebcc 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -58,7 +58,7 @@ srs_error_t MockEmptyIO::write(void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite return srs_success; } -void MockEmptyIO::set_recv_timeout(int64_t /*tm*/) +void MockEmptyIO::set_recv_timeout(srs_utime_t /*tm*/) { } @@ -142,7 +142,7 @@ srs_error_t MockBufferIO::write(void* buf, size_t size, ssize_t* nwrite) return srs_success; } -void MockBufferIO::set_recv_timeout(int64_t tm) +void MockBufferIO::set_recv_timeout(srs_utime_t tm) { rtm = tm; } @@ -693,8 +693,8 @@ VOID TEST(ProtocolStackTest, ProtocolTimeout) EXPECT_TRUE(SRS_UTIME_NO_TIMEOUT == proto.get_recv_timeout()); EXPECT_TRUE(SRS_UTIME_NO_TIMEOUT == proto.get_send_timeout()); - proto.set_recv_timeout(10); - EXPECT_TRUE(10 == proto.get_recv_timeout()); + proto.set_recv_timeout(10 * SRS_UTIME_MILLISECONDS); + EXPECT_TRUE(10 * SRS_UTIME_MILLISECONDS == proto.get_recv_timeout()); proto.set_send_timeout(10 * SRS_UTIME_MILLISECONDS); EXPECT_TRUE(10 * SRS_UTIME_MILLISECONDS == proto.get_send_timeout()); diff --git a/trunk/src/utest/srs_utest_protocol.hpp b/trunk/src/utest/srs_utest_protocol.hpp index 13f731624..3dc980ca6 100644 --- a/trunk/src/utest/srs_utest_protocol.hpp +++ b/trunk/src/utest/srs_utest_protocol.hpp @@ -55,7 +55,7 @@ public: virtual srs_error_t write(void* buf, size_t size, ssize_t* nwrite); // for protocol public: - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual int64_t get_recv_timeout(); virtual int64_t get_recv_bytes(); // for protocol @@ -96,7 +96,7 @@ public: virtual srs_error_t write(void* buf, size_t size, ssize_t* nwrite); // for protocol public: - virtual void set_recv_timeout(int64_t tm); + virtual void set_recv_timeout(srs_utime_t tm); virtual int64_t get_recv_timeout(); virtual int64_t get_recv_bytes(); // for protocol