1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

use tcp client for raw connect.

This commit is contained in:
winlin 2015-10-13 17:59:51 +08:00
parent 20fcfb3eee
commit a9bb6061c3
4 changed files with 126 additions and 12 deletions

View file

@ -208,19 +208,46 @@ public:
* the common tcp client, to connect to specified TCP server,
* reconnect and close the connection.
*/
class SrsTcpClient
class SrsTcpClient : public ISrsProtocolReaderWriter
{
private:
st_netfd_t stfd;
SrsStSocket* io;
public:
SrsTcpClient();
virtual ~SrsTcpClient();
public:
/**
* whether connected to server.
*/
virtual bool connected();
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.
* @remark ignore when connected.
*/
virtual int connect(std::string host, int port, int64_t timeout);
/**
* close the connection.
* @remark ignore when closed.
*/
virtual void close();
// interface ISrsProtocolReaderWriter
public:
virtual bool is_never_timeout(int64_t timeout_us);
virtual void set_recv_timeout(int64_t timeout_us);
virtual int64_t get_recv_timeout();
virtual void set_send_timeout(int64_t timeout_us);
virtual int64_t get_send_timeout();
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
virtual int read(void* buf, size_t size, ssize_t* nread);
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
virtual int write(void* buf, size_t size, ssize_t* nwrite);
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
};
// initialize st, requires epoll.