diff --git a/trunk/src/app/srs_app_rtc_network.cpp b/trunk/src/app/srs_app_rtc_network.cpp index 5babfbd529d..84792f2b876 100644 --- a/trunk/src/app/srs_app_rtc_network.cpp +++ b/trunk/src/app/srs_app_rtc_network.cpp @@ -103,27 +103,25 @@ ISrsKbpsDelta* SrsRtcNetworks::delta() ISrsRtcNetwork::ISrsRtcNetwork() { - establelished_ = false; } ISrsRtcNetwork::~ISrsRtcNetwork() { } -bool ISrsRtcNetwork::is_establelished() -{ - return establelished_; -} - SrsRtcDummyNetwork::SrsRtcDummyNetwork() { - establelished_ = true; } SrsRtcDummyNetwork::~SrsRtcDummyNetwork() { } +bool SrsRtcDummyNetwork::is_establelished() +{ + return true; +} + srs_error_t SrsRtcDummyNetwork::on_connection_established() { return srs_success; @@ -202,7 +200,6 @@ srs_error_t SrsRtcUdpNetwork::start_active_handshake() srs_error_t SrsRtcUdpNetwork::on_dtls(char* data, int nb_data) { - establelished_ = true; // Update stat when we received data. delta_->add_delta(nb_data, 0); @@ -219,7 +216,7 @@ srs_error_t SrsRtcUdpNetwork::on_connection_established() srs_error_t err = srs_success; // If DTLS done packet received many times, such as ARQ, ignore. - if(SrsRtcNetworkStateClosed == state_) { + if(SrsRtcNetworkStateEstablished == state_) { return err; } @@ -227,7 +224,7 @@ srs_error_t SrsRtcUdpNetwork::on_connection_established() return srs_error_wrap(err, "udp"); } - state_ = SrsRtcNetworkStateClosed; + state_ = SrsRtcNetworkStateEstablished; return err; } @@ -303,6 +300,11 @@ void SrsRtcUdpNetwork::set_state(SrsRtcNetworkState state) state_ = state; } +bool SrsRtcUdpNetwork::is_establelished() +{ + return state_ == SrsRtcNetworkStateEstablished; +} + string SrsRtcUdpNetwork::get_peer_ip() { srs_assert(sendonly_skt_); @@ -464,7 +466,7 @@ srs_error_t SrsRtcTcpNetwork::on_connection_established() srs_error_t err = srs_success; // If DTLS done packet received many times, such as ARQ, ignore. - if(SrsRtcNetworkStateClosed == state_) { + if(SrsRtcNetworkStateEstablished == state_) { return err; } @@ -472,7 +474,7 @@ srs_error_t SrsRtcTcpNetwork::on_connection_established() return srs_error_wrap(err, "udp"); } - state_ = SrsRtcNetworkStateClosed; + state_ = SrsRtcNetworkStateEstablished; return err; } @@ -585,7 +587,6 @@ srs_error_t SrsRtcTcpNetwork::start_active_handshake() srs_error_t SrsRtcTcpNetwork::on_dtls(char* data, int nb_data) { - establelished_ = true; // Update stat when we received data. delta_->add_delta(nb_data, 0); @@ -654,6 +655,11 @@ void SrsRtcTcpNetwork::set_state(SrsRtcNetworkState state) state_ = state; } +bool SrsRtcTcpNetwork::is_establelished() +{ + return state_ == SrsRtcNetworkStateEstablished; +} + std::string SrsRtcTcpNetwork::get_peer_ip() { return peer_ip_; @@ -701,6 +707,11 @@ void SrsRtcTcpNetwork::set_peer_id(const std::string& ip, int port) peer_port_ = port; } +void SrsRtcTcpNetwork::dispose() +{ + state_ = SrsRtcNetworkStateClosed; +} + SrsRtcTcpConn::SrsRtcTcpConn(ISrsProtocolReadWriter* skt, std::string cip, int port, ISrsResourceManager* cm) { manager_ = cm; @@ -761,6 +772,10 @@ srs_error_t SrsRtcTcpConn::cycle() // Because we use manager to manage this object, // not the http connection object, so we must remove it here. manager_->remove(this); + if(session_) { + session_->tcp()->set_state(SrsRtcNetworkStateClosed); + _srs_rtc_manager->remove(session_); + } // For HTTP-API timeout, we think it's done successfully, // because there may be no request or response for HTTP-API. diff --git a/trunk/src/app/srs_app_rtc_network.hpp b/trunk/src/app/srs_app_rtc_network.hpp index 9e786cd8733..c9878da6c11 100644 --- a/trunk/src/app/srs_app_rtc_network.hpp +++ b/trunk/src/app/srs_app_rtc_network.hpp @@ -80,9 +80,6 @@ class SrsRtcNetworks // For DTLS or Session to call network service. class ISrsRtcNetwork : public ISrsStreamWriter { -protected: - bool establelished_; - public: ISrsRtcNetwork(); virtual ~ISrsRtcNetwork(); @@ -97,7 +94,7 @@ class ISrsRtcNetwork : public ISrsStreamWriter // Protect RTCP packet by SRTP context. virtual srs_error_t protect_rtcp(void* packet, int* nb_cipher) = 0; public: - bool is_establelished(); + virtual bool is_establelished() = 0; }; // Dummy networks @@ -114,6 +111,7 @@ class SrsRtcDummyNetwork : public ISrsRtcNetwork public: virtual srs_error_t protect_rtp(void* packet, int* nb_cipher); virtual srs_error_t protect_rtcp(void* packet, int* nb_cipher); + virtual bool is_establelished(); // Interface ISrsStreamWriter. public: virtual srs_error_t write(void* buf, size_t size, ssize_t* nwrite); @@ -164,6 +162,7 @@ class SrsRtcUdpNetwork : public ISrsRtcNetwork public: // Connection level state machine, for ARQ of UDP packets. void set_state(SrsRtcNetworkState state); + virtual bool is_establelished(); // ICE reflexive address functions. std::string get_peer_ip(); int get_peer_port(); @@ -218,6 +217,7 @@ class SrsRtcTcpNetwork: public ISrsRtcNetwork public: // Connection level state machine, for ARQ of UDP packets. void set_state(SrsRtcNetworkState state); + virtual bool is_establelished(); // ICE reflexive address functions. std::string get_peer_ip(); int get_peer_port(); @@ -226,6 +226,7 @@ class SrsRtcTcpNetwork: public ISrsRtcNetwork virtual srs_error_t write(void* buf, size_t size, ssize_t* nwrite); public: void set_peer_id(const std::string& ip, int port); + void dispose(); }; // For WebRTC over TCP.