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

For #913, http callback use complex error

This commit is contained in:
winlin 2017-09-22 19:54:50 +08:00
parent 59b53dab8b
commit 20a42599f3
22 changed files with 264 additions and 268 deletions

View file

@ -102,9 +102,9 @@ srs_thread_t srs_thread_self()
return (srs_thread_t)st_thread_self();
}
int srs_socket_connect(string server, int port, int64_t tm, srs_netfd_t* pstfd)
srs_error_t srs_socket_connect(string server, int port, int64_t tm, srs_netfd_t* pstfd)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
st_utime_t timeout = ST_UTIME_NO_TIMEOUT;
if (tm != SRS_CONSTS_NO_TMMS) {
@ -117,9 +117,7 @@ int srs_socket_connect(string server, int port, int64_t tm, srs_netfd_t* pstfd)
int sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock == -1){
ret = ERROR_SOCKET_CREATE;
srs_error("create socket error. ret=%d", ret);
return ret;
return srs_error_new(ERROR_SOCKET_CREATE, "create socket");
}
srs_fd_close_exec(sock);
@ -127,17 +125,13 @@ int srs_socket_connect(string server, int port, int64_t tm, srs_netfd_t* pstfd)
srs_assert(!stfd);
stfd = st_netfd_open_socket(sock);
if(stfd == NULL){
ret = ERROR_ST_OPEN_SOCKET;
srs_error("st_netfd_open_socket failed. ret=%d", ret);
return ret;
return srs_error_new(ERROR_ST_OPEN_SOCKET, "open socket");
}
// connect to server.
std::string ip = srs_dns_resolve(server);
if (ip.empty()) {
ret = ERROR_SYSTEM_IP_INVALID;
srs_error("dns resolve server error, ip empty. ret=%d", ret);
goto failed;
return srs_error_new(ERROR_SYSTEM_IP_INVALID, "resolve server %s", server.c_str());
}
addr.sin_family = AF_INET;
@ -145,20 +139,19 @@ int srs_socket_connect(string server, int port, int64_t tm, srs_netfd_t* pstfd)
addr.sin_addr.s_addr = inet_addr(ip.c_str());
if (st_connect((st_netfd_t)stfd, (const struct sockaddr*)&addr, sizeof(sockaddr_in), timeout) == -1){
ret = ERROR_ST_CONNECT;
srs_error("connect to server error. ip=%s, port=%d, ret=%d", ip.c_str(), port, ret);
err = srs_error_new(ERROR_ST_CONNECT, "connect to %s:%d", ip.c_str(), port);
goto failed;
}
srs_info("connect ok. server=%s, ip=%s, port=%d", server.c_str(), ip.c_str(), port);
*pstfd = stfd;
return ret;
return err;
failed:
if (stfd) {
srs_close_stfd(stfd);
}
return ret;
return err;
}
srs_cond_t srs_cond_new()
@ -252,10 +245,10 @@ SrsStSocket::~SrsStSocket()
{
}
int SrsStSocket::initialize(srs_netfd_t fd)
srs_error_t SrsStSocket::initialize(srs_netfd_t fd)
{
stfd = fd;
return ERROR_SUCCESS;
return srs_success;
}
bool SrsStSocket::is_never_timeout(int64_t tm)
@ -444,23 +437,22 @@ SrsTcpClient::~SrsTcpClient()
srs_freep(io);
}
int SrsTcpClient::connect()
srs_error_t SrsTcpClient::connect()
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
close();
srs_assert(stfd == NULL);
if ((ret = srs_socket_connect(host, port, timeout, &stfd)) != ERROR_SUCCESS) {
srs_error("connect tcp://%s:%d failed, to=%" PRId64 "ms. ret=%d", host.c_str(), port, timeout, ret);
return ret;
if ((err = srs_socket_connect(host, port, timeout, &stfd)) != srs_success) {
return srs_error_wrap(err, "tcp: connect %s:%d to=%d", host.c_str(), port, (int)timeout);
}
if ((ret = io->initialize(stfd)) != ERROR_SUCCESS) {
return ret;
if ((err = io->initialize(stfd)) != srs_success) {
return srs_error_wrap(err, "tcp: init socket object");
}
return ret;
return err;
}
void SrsTcpClient::close()