mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #742, refine the object live cycle. 3.0.15
This commit is contained in:
parent
f4c0af8bfc
commit
dca9749f37
19 changed files with 286 additions and 226 deletions
|
@ -421,10 +421,14 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
|||
return ret;
|
||||
}
|
||||
|
||||
SrsTcpClient::SrsTcpClient()
|
||||
SrsTcpClient::SrsTcpClient(string h, int p, int64_t tm)
|
||||
{
|
||||
io = NULL;
|
||||
stfd = NULL;
|
||||
|
||||
host = h;
|
||||
port = p;
|
||||
timeout = tm;
|
||||
}
|
||||
|
||||
SrsTcpClient::~SrsTcpClient()
|
||||
|
@ -432,26 +436,19 @@ SrsTcpClient::~SrsTcpClient()
|
|||
close();
|
||||
}
|
||||
|
||||
bool SrsTcpClient::connected()
|
||||
{
|
||||
return io;
|
||||
}
|
||||
|
||||
int SrsTcpClient::connect(string host, int port, int64_t timeout)
|
||||
int SrsTcpClient::connect()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// when connected, ignore.
|
||||
if (io) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// connect host.
|
||||
if ((ret = srs_socket_connect(host, port, timeout, &stfd)) != ERROR_SUCCESS) {
|
||||
srs_error("connect server %s:%d failed. ret=%d", host.c_str(), port, ret);
|
||||
close();
|
||||
|
||||
srs_assert(stfd == NULL);
|
||||
if ((ret = srs_socket_connect(host, port, timeout * 1000, &stfd)) != ERROR_SUCCESS) {
|
||||
srs_error("connect tcp://%s:%d failed, to=%"PRId64"ms. ret=%d", host.c_str(), port, timeout, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_assert(io == NULL);
|
||||
io = new SrsStSocket(stfd);
|
||||
|
||||
return ret;
|
||||
|
@ -459,7 +456,7 @@ int SrsTcpClient::connect(string host, int port, int64_t timeout)
|
|||
|
||||
void SrsTcpClient::close()
|
||||
{
|
||||
// when closed, ignore.
|
||||
// Ignore when already closed.
|
||||
if (!io) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue