1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

Rename SrsConnection to SrsTcpConnection

This commit is contained in:
winlin 2020-09-11 16:59:22 +08:00
parent 2135b638b1
commit 88826aae8f
16 changed files with 49 additions and 47 deletions

View file

@ -97,7 +97,7 @@ srs_error_t SrsAppCasterFlv::on_tcp_client(srs_netfd_t stfd)
void SrsAppCasterFlv::remove(ISrsConnection* c) void SrsAppCasterFlv::remove(ISrsConnection* c)
{ {
SrsConnection* conn = dynamic_cast<SrsConnection*>(c); SrsTcpConnection* conn = dynamic_cast<SrsTcpConnection*>(c);
std::vector<SrsHttpConn*>::iterator it; std::vector<SrsHttpConn*>::iterator it;
if ((it = std::find(conns.begin(), conns.end(), conn)) != conns.end()) { if ((it = std::find(conns.begin(), conns.end(), conn)) != conns.end()) {

View file

@ -94,7 +94,7 @@ void SrsCoroutineManager::clear()
} }
} }
SrsConnection::SrsConnection(IConnectionManager* cm, srs_netfd_t c, string cip, int cport) SrsTcpConnection::SrsTcpConnection(IConnectionManager* cm, srs_netfd_t c, string cip, int cport)
{ {
manager = cm; manager = cm;
stfd = c; stfd = c;
@ -110,7 +110,7 @@ SrsConnection::SrsConnection(IConnectionManager* cm, srs_netfd_t c, string cip,
trd = new SrsSTCoroutine("conn", this); trd = new SrsSTCoroutine("conn", this);
} }
SrsConnection::~SrsConnection() SrsTcpConnection::~SrsTcpConnection()
{ {
dispose(); dispose();
@ -122,17 +122,17 @@ SrsConnection::~SrsConnection()
srs_close_stfd(stfd); srs_close_stfd(stfd);
} }
void SrsConnection::remark(int64_t* in, int64_t* out) void SrsTcpConnection::remark(int64_t* in, int64_t* out)
{ {
kbps->remark(in, out); kbps->remark(in, out);
} }
void SrsConnection::dispose() void SrsTcpConnection::dispose()
{ {
trd->interrupt(); trd->interrupt();
} }
srs_error_t SrsConnection::start() srs_error_t SrsTcpConnection::start()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -147,7 +147,7 @@ srs_error_t SrsConnection::start()
return err; return err;
} }
srs_error_t SrsConnection::set_tcp_nodelay(bool v) srs_error_t SrsTcpConnection::set_tcp_nodelay(bool v)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -178,7 +178,7 @@ srs_error_t SrsConnection::set_tcp_nodelay(bool v)
return err; return err;
} }
srs_error_t SrsConnection::set_socket_buffer(srs_utime_t buffer_v) srs_error_t SrsTcpConnection::set_socket_buffer(srs_utime_t buffer_v)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -230,7 +230,7 @@ srs_error_t SrsConnection::set_socket_buffer(srs_utime_t buffer_v)
return err; return err;
} }
srs_error_t SrsConnection::cycle() srs_error_t SrsTcpConnection::cycle()
{ {
srs_error_t err = do_cycle(); srs_error_t err = do_cycle();
@ -264,17 +264,17 @@ srs_error_t SrsConnection::cycle()
return srs_success; return srs_success;
} }
SrsContextId SrsConnection::srs_id() SrsContextId SrsTcpConnection::srs_id()
{ {
return trd->cid(); return trd->cid();
} }
string SrsConnection::remote_ip() string SrsTcpConnection::remote_ip()
{ {
return ip; return ip;
} }
void SrsConnection::expire() void SrsTcpConnection::expire()
{ {
trd->interrupt(); trd->interrupt();
} }

View file

@ -61,10 +61,10 @@ private:
void clear(); void clear();
}; };
// The basic connection of SRS, // The basic connection of SRS, for TCP based protocols,
// all connections accept from listener must extends from this base class, // all connections accept from listener must extends from this base class,
// server will add the connection to manager, and delete it when remove. // server will add the connection to manager, and delete it when remove.
class SrsConnection : virtual public ISrsConnection, virtual public ISrsCoroutineHandler class SrsTcpConnection : virtual public ISrsConnection, virtual public ISrsCoroutineHandler
, virtual public ISrsKbpsDelta, virtual public ISrsReloadHandler , virtual public ISrsKbpsDelta, virtual public ISrsReloadHandler
{ {
protected: protected:
@ -90,8 +90,8 @@ protected:
// for current connection to log self create time and calculate the living time. // for current connection to log self create time and calculate the living time.
int64_t create_time; int64_t create_time;
public: public:
SrsConnection(IConnectionManager* cm, srs_netfd_t c, std::string cip, int cport); SrsTcpConnection(IConnectionManager* cm, srs_netfd_t c, std::string cip, int cport);
virtual ~SrsConnection(); virtual ~SrsTcpConnection();
// Interface ISrsKbpsDelta // Interface ISrsKbpsDelta
public: public:
virtual void remark(int64_t* in, int64_t* out); virtual void remark(int64_t* in, int64_t* out);

View file

@ -1674,7 +1674,8 @@ srs_error_t SrsGoApiTcmalloc::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
} }
#endif #endif
SrsHttpApi::SrsHttpApi(IConnectionManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, string cip, int port) : SrsConnection(cm, fd, cip, port) SrsHttpApi::SrsHttpApi(IConnectionManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, string cip, int port)
: SrsTcpConnection(cm, fd, cip, port)
{ {
mux = m; mux = m;
cors = new SrsHttpCorsMux(); cors = new SrsHttpCorsMux();

View file

@ -254,7 +254,7 @@ public:
}; };
#endif #endif
class SrsHttpApi : virtual public SrsConnection, virtual public ISrsReloadHandler class SrsHttpApi : virtual public SrsTcpConnection, virtual public ISrsReloadHandler
{ {
private: private:
SrsHttpParser* parser; SrsHttpParser* parser;

View file

@ -59,7 +59,8 @@ using namespace std;
#include <srs_app_utility.hpp> #include <srs_app_utility.hpp>
#include <srs_app_st.hpp> #include <srs_app_st.hpp>
SrsHttpConn::SrsHttpConn(IConnectionManager* cm, srs_netfd_t fd, ISrsHttpServeMux* m, string cip, int port) : SrsConnection(cm, fd, cip, port) SrsHttpConn::SrsHttpConn(IConnectionManager* cm, srs_netfd_t fd, ISrsHttpServeMux* m, string cip, int port)
: SrsTcpConnection(cm, fd, cip, port)
{ {
parser = new SrsHttpParser(); parser = new SrsHttpParser();
cors = new SrsHttpCorsMux(); cors = new SrsHttpCorsMux();

View file

@ -50,13 +50,12 @@ class SrsSharedPtrMessage;
class SrsRequest; class SrsRequest;
class SrsFastStream; class SrsFastStream;
class SrsHttpUri; class SrsHttpUri;
class SrsConnection;
class SrsHttpMessage; class SrsHttpMessage;
class SrsHttpStreamServer; class SrsHttpStreamServer;
class SrsHttpStaticServer; class SrsHttpStaticServer;
// The http connection which request the static or stream content. // The http connection which request the static or stream content.
class SrsHttpConn : public SrsConnection class SrsHttpConn : public SrsTcpConnection
{ {
protected: protected:
SrsHttpParser* parser; SrsHttpParser* parser;

View file

@ -38,7 +38,7 @@
#include <srs_app_source.hpp> #include <srs_app_source.hpp>
class SrsRequest; class SrsRequest;
class SrsConnection; class SrsTcpConnection;
class SrsMetaCache; class SrsMetaCache;
class SrsSharedPtrMessage; class SrsSharedPtrMessage;
class SrsCommonMessage; class SrsCommonMessage;

View file

@ -104,7 +104,8 @@ SrsClientInfo::~SrsClientInfo()
srs_freep(res); srs_freep(res);
} }
SrsRtmpConn::SrsRtmpConn(SrsServer* svr, srs_netfd_t c, string cip, int port) : SrsConnection(svr, c, cip, port) SrsRtmpConn::SrsRtmpConn(SrsServer* svr, srs_netfd_t c, string cip, int port)
: SrsTcpConnection(svr, c, cip, port)
{ {
server = svr; server = svr;
@ -141,7 +142,7 @@ SrsRtmpConn::~SrsRtmpConn()
void SrsRtmpConn::dispose() void SrsRtmpConn::dispose()
{ {
SrsConnection::dispose(); SrsTcpConnection::dispose();
// wakeup the handler which need to notice. // wakeup the handler which need to notice.
if (wakable) { if (wakable) {

View file

@ -83,7 +83,7 @@ public:
}; };
// The client provides the main logic control for RTMP clients. // The client provides the main logic control for RTMP clients.
class SrsRtmpConn : virtual public SrsConnection, virtual public ISrsReloadHandler class SrsRtmpConn : virtual public SrsTcpConnection, virtual public ISrsReloadHandler
{ {
// For the thread to directly access any field of connection. // For the thread to directly access any field of connection.
friend class SrsPublishRecvThread; friend class SrsPublishRecvThread;

View file

@ -1473,8 +1473,8 @@ void SrsServer::resample_kbps()
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
// collect delta from all clients. // collect delta from all clients.
for (std::vector<SrsConnection*>::iterator it = conns.begin(); it != conns.end(); ++it) { for (std::vector<SrsTcpConnection*>::iterator it = conns.begin(); it != conns.end(); ++it) {
SrsConnection* conn = *it; SrsTcpConnection* conn = *it;
// add delta of connection to server kbps., // add delta of connection to server kbps.,
// for next sample() of server kbps can get the stat. // for next sample() of server kbps can get the stat.
@ -1493,7 +1493,7 @@ srs_error_t SrsServer::accept_client(SrsListenerType type, srs_netfd_t stfd)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsConnection* conn = NULL; SrsTcpConnection* conn = NULL;
if ((err = fd2conn(type, stfd, &conn)) != srs_success) { if ((err = fd2conn(type, stfd, &conn)) != srs_success) {
if (srs_error_code(err) == ERROR_SOCKET_GET_PEER_IP && _srs_config->empty_ip_ok()) { if (srs_error_code(err) == ERROR_SOCKET_GET_PEER_IP && _srs_config->empty_ip_ok()) {
@ -1521,7 +1521,7 @@ SrsHttpServeMux* SrsServer::api_server()
return http_api_mux; return http_api_mux;
} }
srs_error_t SrsServer::fd2conn(SrsListenerType type, srs_netfd_t stfd, SrsConnection** pconn) srs_error_t SrsServer::fd2conn(SrsListenerType type, srs_netfd_t stfd, SrsTcpConnection** pconn)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -1577,8 +1577,8 @@ srs_error_t SrsServer::fd2conn(SrsListenerType type, srs_netfd_t stfd, SrsConnec
void SrsServer::remove(ISrsConnection* c) void SrsServer::remove(ISrsConnection* c)
{ {
SrsConnection* conn = dynamic_cast<SrsConnection*>(c); SrsTcpConnection* conn = dynamic_cast<SrsTcpConnection*>(c);
std::vector<SrsConnection*>::iterator it = std::find(conns.begin(), conns.end(), conn); std::vector<SrsTcpConnection*>::iterator it = std::find(conns.begin(), conns.end(), conn);
// removed by destroy, ignore. // removed by destroy, ignore.
if (it == conns.end()) { if (it == conns.end()) {

View file

@ -40,7 +40,7 @@
#include <srs_app_gb28181_sip.hpp> #include <srs_app_gb28181_sip.hpp>
class SrsServer; class SrsServer;
class SrsConnection; class SrsTcpConnection;
class SrsHttpServeMux; class SrsHttpServeMux;
class SrsHttpServer; class SrsHttpServer;
class SrsIngester; class SrsIngester;
@ -257,7 +257,7 @@ private:
// maybe valid but the process is not SRS, the init.d script will never start server. // maybe valid but the process is not SRS, the init.d script will never start server.
int pid_fd; int pid_fd;
// All connections, connection manager // All connections, connection manager
std::vector<SrsConnection*> conns; std::vector<SrsTcpConnection*> conns;
// All listners, listener manager. // All listners, listener manager.
std::vector<SrsListener*> listeners; std::vector<SrsListener*> listeners;
// Signal manager which convert gignal to io message. // Signal manager which convert gignal to io message.
@ -343,12 +343,12 @@ public:
// TODO: FIXME: Fetch from hybrid server manager. // TODO: FIXME: Fetch from hybrid server manager.
virtual SrsHttpServeMux* api_server(); virtual SrsHttpServeMux* api_server();
private: private:
virtual srs_error_t fd2conn(SrsListenerType type, srs_netfd_t stfd, SrsConnection** pconn); virtual srs_error_t fd2conn(SrsListenerType type, srs_netfd_t stfd, SrsTcpConnection** pconn);
// Interface IConnectionManager // Interface IConnectionManager
public: public:
// A callback for connection to remove itself. // A callback for connection to remove itself.
// When connection thread cycle terminated, callback this to delete connection. // When connection thread cycle terminated, callback this to delete connection.
// @see SrsConnection.on_thread_stop(). // @see SrsTcpConnection.on_thread_stop().
virtual void remove(ISrsConnection* c); virtual void remove(ISrsConnection* c);
// Interface ISrsReloadHandler. // Interface ISrsReloadHandler.
public: public:

View file

@ -418,7 +418,7 @@ ISrsWakable::~ISrsWakable()
{ {
} }
SrsConsumer::SrsConsumer(SrsSource* s, SrsConnection* c) SrsConsumer::SrsConsumer(SrsSource* s, SrsTcpConnection* c)
{ {
source = s; source = s;
conn = c; conn = c;
@ -2578,7 +2578,7 @@ void SrsSource::on_unpublish()
} }
} }
srs_error_t SrsSource::create_consumer(SrsConnection* conn, SrsConsumer*& consumer) srs_error_t SrsSource::create_consumer(SrsTcpConnection* conn, SrsConsumer*& consumer)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;

View file

@ -51,7 +51,7 @@ class SrsRtmpServer;
class SrsEdgeProxyContext; class SrsEdgeProxyContext;
class SrsMessageArray; class SrsMessageArray;
class SrsNgExec; class SrsNgExec;
class SrsConnection; class SrsTcpConnection;
class SrsMessageHeader; class SrsMessageHeader;
class SrsHls; class SrsHls;
class SrsRtc; class SrsRtc;
@ -190,7 +190,7 @@ private:
SrsSource* source; SrsSource* source;
SrsMessageQueue* queue; SrsMessageQueue* queue;
// The owner connection for debug, maybe NULL. // The owner connection for debug, maybe NULL.
SrsConnection* conn; SrsTcpConnection* conn;
bool paused; bool paused;
// when source id changed, notice all consumers // when source id changed, notice all consumers
bool should_update_source_id; bool should_update_source_id;
@ -203,7 +203,7 @@ private:
srs_utime_t mw_duration; srs_utime_t mw_duration;
#endif #endif
public: public:
SrsConsumer(SrsSource* s, SrsConnection* c); SrsConsumer(SrsSource* s, SrsTcpConnection* c);
virtual ~SrsConsumer(); virtual ~SrsConsumer();
public: public:
// Set the size of queue. // Set the size of queue.
@ -599,7 +599,7 @@ public:
public: public:
// Create consumer // Create consumer
// @param consumer, output the create consumer. // @param consumer, output the create consumer.
virtual srs_error_t create_consumer(SrsConnection* conn, SrsConsumer*& consumer); virtual srs_error_t create_consumer(SrsTcpConnection* conn, SrsConsumer*& consumer);
// Dumps packets in cache to consumer. // Dumps packets in cache to consumer.
// @param ds, whether dumps the sequence header. // @param ds, whether dumps the sequence header.
// @param dm, whether dumps the metadata. // @param dm, whether dumps the metadata.

View file

@ -422,7 +422,7 @@ void SrsStatistic::on_stream_close(SrsRequest* req)
} }
} }
srs_error_t SrsStatistic::on_client(SrsContextId cid, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type) srs_error_t SrsStatistic::on_client(SrsContextId cid, SrsRequest* req, SrsTcpConnection* conn, SrsRtmpConnType type)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -474,7 +474,7 @@ void SrsStatistic::on_disconnect(SrsContextId cid)
vhost->nb_clients--; vhost->nb_clients--;
} }
void SrsStatistic::kbps_add_delta(SrsConnection* conn) void SrsStatistic::kbps_add_delta(SrsTcpConnection* conn)
{ {
// TODO: FIXME: Should not use context id as connection id. // TODO: FIXME: Should not use context id as connection id.
std::string id = conn->srs_id().c_str(); std::string id = conn->srs_id().c_str();

View file

@ -36,7 +36,7 @@
class SrsKbps; class SrsKbps;
class SrsWallClock; class SrsWallClock;
class SrsRequest; class SrsRequest;
class SrsConnection; class SrsTcpConnection;
class SrsJsonObject; class SrsJsonObject;
class SrsJsonArray; class SrsJsonArray;
@ -110,7 +110,7 @@ struct SrsStatisticClient
{ {
public: public:
SrsStatisticStream* stream; SrsStatisticStream* stream;
SrsConnection* conn; SrsTcpConnection* conn;
SrsRequest* req; SrsRequest* req;
SrsRtmpConnType type; SrsRtmpConnType type;
std::string id; std::string id;
@ -205,7 +205,7 @@ public:
// @param conn, the physical absract connection object. // @param conn, the physical absract connection object.
// @param type, the type of connection. // @param type, the type of connection.
// TODO: FIXME: We should not use context id as client id. // TODO: FIXME: We should not use context id as client id.
virtual srs_error_t on_client(SrsContextId id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type); virtual srs_error_t on_client(SrsContextId id, SrsRequest* req, SrsTcpConnection* conn, SrsRtmpConnType type);
// Client disconnect // Client disconnect
// @remark the on_disconnect always call, while the on_client is call when // @remark the on_disconnect always call, while the on_client is call when
// only got the request object, so the client specified by id maybe not // only got the request object, so the client specified by id maybe not
@ -215,7 +215,7 @@ public:
// Sample the kbps, add delta bytes of conn. // Sample the kbps, add delta bytes of conn.
// Use kbps_sample() to get all result of kbps stat. // Use kbps_sample() to get all result of kbps stat.
// TODO: FIXME: the add delta must use ISrsKbpsDelta interface instead. // TODO: FIXME: the add delta must use ISrsKbpsDelta interface instead.
virtual void kbps_add_delta(SrsConnection* conn); virtual void kbps_add_delta(SrsTcpConnection* conn);
// Calc the result for all kbps. // Calc the result for all kbps.
// @return the server kbps. // @return the server kbps.
virtual SrsKbps* kbps_sample(); virtual SrsKbps* kbps_sample();