From 20fcfb3eeed7940b77241b4c5667b3b28a704226 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 13 Oct 2015 17:37:59 +0800 Subject: [PATCH] fix bug, use system utility --- trunk/src/app/srs_app_caster_flv.cpp | 6 +++--- trunk/src/app/srs_app_caster_flv.hpp | 2 +- trunk/src/app/srs_app_mpegts_udp.cpp | 6 +++--- trunk/src/app/srs_app_mpegts_udp.hpp | 2 +- trunk/src/app/srs_app_rtsp.cpp | 9 +++++---- trunk/src/app/srs_app_rtsp.hpp | 2 +- trunk/src/app/srs_app_st.cpp | 17 +++++++++++++++++ trunk/src/app/srs_app_st.hpp | 10 ++++++++++ 8 files changed, 41 insertions(+), 13 deletions(-) diff --git a/trunk/src/app/srs_app_caster_flv.cpp b/trunk/src/app/srs_app_caster_flv.cpp index ac78c0dbc..a0d38cda9 100644 --- a/trunk/src/app/srs_app_caster_flv.cpp +++ b/trunk/src/app/srs_app_caster_flv.cpp @@ -273,8 +273,8 @@ int SrsDynamicHttpConn::connect() } // connect host. - if ((ret = srs_socket_connect(req->host, ::atoi(req->port.c_str()), ST_UTIME_NO_TIMEOUT, &stfd)) != ERROR_SUCCESS) { - srs_error("mpegts: connect server %s:%s failed. ret=%d", req->host.c_str(), req->port.c_str(), ret); + if ((ret = srs_socket_connect(req->host, req->port, ST_UTIME_NO_TIMEOUT, &stfd)) != ERROR_SUCCESS) { + srs_error("mpegts: connect server %s:%d failed. ret=%d", req->host.c_str(), req->port, ret); return ret; } io = new SrsStSocket(stfd); @@ -308,7 +308,7 @@ int SrsDynamicHttpConn::connect() } // TODO: FIXME: refine the connect_app. -int SrsDynamicHttpConn::connect_app(string ep_server, string ep_port) +int SrsDynamicHttpConn::connect_app(string ep_server, int ep_port) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_caster_flv.hpp b/trunk/src/app/srs_app_caster_flv.hpp index cf0d11f86..f6a03838e 100644 --- a/trunk/src/app/srs_app_caster_flv.hpp +++ b/trunk/src/app/srs_app_caster_flv.hpp @@ -104,7 +104,7 @@ private: // connect to rtmp output url. // @remark ignore when not connected, reconnect when disconnected. virtual int connect(); - virtual int connect_app(std::string ep_server, std::string ep_port); + virtual int connect_app(std::string ep_server, int ep_port); // close the connected io and rtmp to ready to be re-connect. virtual void close(); }; diff --git a/trunk/src/app/srs_app_mpegts_udp.cpp b/trunk/src/app/srs_app_mpegts_udp.cpp index efb4e5bcd..71593f72c 100644 --- a/trunk/src/app/srs_app_mpegts_udp.cpp +++ b/trunk/src/app/srs_app_mpegts_udp.cpp @@ -616,8 +616,8 @@ int SrsMpegtsOverUdp::connect() } // connect host. - if ((ret = srs_socket_connect(req->host, ::atoi(req->port.c_str()), ST_UTIME_NO_TIMEOUT, &stfd)) != ERROR_SUCCESS) { - srs_error("mpegts: connect server %s:%s failed. ret=%d", req->host.c_str(), req->port.c_str(), ret); + if ((ret = srs_socket_connect(req->host, req->port, ST_UTIME_NO_TIMEOUT, &stfd)) != ERROR_SUCCESS) { + srs_error("mpegts: connect server %s:%d failed. ret=%d", req->host.c_str(), req->port, ret); return ret; } io = new SrsStSocket(stfd); @@ -651,7 +651,7 @@ int SrsMpegtsOverUdp::connect() } // TODO: FIXME: refine the connect_app. -int SrsMpegtsOverUdp::connect_app(string ep_server, string ep_port) +int SrsMpegtsOverUdp::connect_app(string ep_server, int ep_port) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_mpegts_udp.hpp b/trunk/src/app/srs_app_mpegts_udp.hpp index 400e8627e..98b4cd3c3 100644 --- a/trunk/src/app/srs_app_mpegts_udp.hpp +++ b/trunk/src/app/srs_app_mpegts_udp.hpp @@ -126,7 +126,7 @@ private: // connect to rtmp output url. // @remark ignore when not connected, reconnect when disconnected. virtual int connect(); - virtual int connect_app(std::string ep_server, std::string ep_port); + virtual int connect_app(std::string ep_server, int ep_port); // close the connected io and rtmp to ready to be re-connect. virtual void close(); }; diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index ca73a659a..b35eccb03 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -648,7 +648,8 @@ int SrsRtspConn::connect() // parse uri if (!req) { - std::string schema, host, vhost, app, port, param; + std::string schema, host, vhost, app, param; + int port; srs_discovery_tc_url(rtsp_tcUrl, schema, host, vhost, app, port, param); // generate output by template. @@ -662,8 +663,8 @@ int SrsRtspConn::connect() } // connect host. - if ((ret = srs_socket_connect(req->host, ::atoi(req->port.c_str()), ST_UTIME_NO_TIMEOUT, &stfd)) != ERROR_SUCCESS) { - srs_error("rtsp: connect server %s:%s failed. ret=%d", req->host.c_str(), req->port.c_str(), ret); + if ((ret = srs_socket_connect(req->host, req->port, ST_UTIME_NO_TIMEOUT, &stfd)) != ERROR_SUCCESS) { + srs_error("rtsp: connect server %s:%d failed. ret=%d", req->host.c_str(), req->port, ret); return ret; } io = new SrsStSocket(stfd); @@ -697,7 +698,7 @@ int SrsRtspConn::connect() } // TODO: FIXME: refine the connect_app. -int SrsRtspConn::connect_app(string ep_server, string ep_port) +int SrsRtspConn::connect_app(string ep_server, int ep_port) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_rtsp.hpp b/trunk/src/app/srs_app_rtsp.hpp index 40c9c599a..3fa245053 100644 --- a/trunk/src/app/srs_app_rtsp.hpp +++ b/trunk/src/app/srs_app_rtsp.hpp @@ -181,7 +181,7 @@ private: // connect to rtmp output url. // @remark ignore when not connected, reconnect when disconnected. virtual int connect(); - virtual int connect_app(std::string ep_server, std::string ep_port); + virtual int connect_app(std::string ep_server, int ep_port); }; /** diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index 810eccdb5..8d90e8084 100644 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -23,6 +23,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +#include +using namespace std; + #include #include @@ -406,6 +409,20 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite) return ret; } +SrsTcpClient::SrsTcpClient() +{ +} + +SrsTcpClient::~SrsTcpClient() +{ +} + +int SrsTcpClient::connect(string host, int port, int64_t timeout) +{ + int ret = ERROR_SUCCESS; + return ret; +} + #ifdef __linux__ #include diff --git a/trunk/src/app/srs_app_st.hpp b/trunk/src/app/srs_app_st.hpp index 31af7d41f..6125c50f0 100644 --- a/trunk/src/app/srs_app_st.hpp +++ b/trunk/src/app/srs_app_st.hpp @@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +#include + #include #include @@ -211,6 +213,14 @@ class SrsTcpClient public: SrsTcpClient(); virtual ~SrsTcpClient(); +public: + /** + * connect to server over TCP. + * @param host the ip or hostname of server. + * @param port the port to connect to. + * @param timeout the timeout in us. + */ + virtual int connect(std::string host, int port, int64_t timeout); }; // initialize st, requires epoll.