change function conn_pool_connect_server_ex
parent
69463768ea
commit
9534dfba56
|
|
@ -86,7 +86,8 @@ void conn_pool_disconnect_server(ConnectionInfo *pConnection)
|
|||
}
|
||||
|
||||
int conn_pool_connect_server_ex(ConnectionInfo *pConnection,
|
||||
const int connect_timeout, const char *bind_ipaddr)
|
||||
const int connect_timeout, const char *bind_ipaddr,
|
||||
const bool log_connect_error)
|
||||
{
|
||||
int result;
|
||||
int domain;
|
||||
|
|
@ -108,15 +109,18 @@ int conn_pool_connect_server_ex(ConnectionInfo *pConnection,
|
|||
pConnection->sock = socket(domain, SOCK_STREAM, 0);
|
||||
if(pConnection->sock < 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"socket create failed, errno: %d, " \
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"socket create fail, errno: %d, "
|
||||
"error info: %s", __LINE__, errno, STRERROR(errno));
|
||||
return errno != 0 ? errno : EPERM;
|
||||
}
|
||||
|
||||
if (bind_ipaddr != NULL && *bind_ipaddr != '\0')
|
||||
{
|
||||
socketBind2(domain, pConnection->sock, bind_ipaddr, 0);
|
||||
if ((result=socketBind2(domain, pConnection->sock, bind_ipaddr, 0)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
SET_SOCKOPT_NOSIGPIPE(pConnection->sock);
|
||||
|
|
@ -127,14 +131,17 @@ int conn_pool_connect_server_ex(ConnectionInfo *pConnection,
|
|||
return result;
|
||||
}
|
||||
|
||||
if ((result=connectserverbyip_nb(pConnection->sock, \
|
||||
pConnection->ip_addr, pConnection->port, \
|
||||
if ((result=connectserverbyip_nb(pConnection->sock,
|
||||
pConnection->ip_addr, pConnection->port,
|
||||
connect_timeout)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"connect to %s:%d fail, errno: %d, " \
|
||||
"error info: %s", __LINE__, pConnection->ip_addr, \
|
||||
pConnection->port, result, STRERROR(result));
|
||||
if (log_connect_error)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"connect to server %s:%d fail, errno: %d, "
|
||||
"error info: %s", __LINE__, pConnection->ip_addr,
|
||||
pConnection->port, result, STRERROR(result));
|
||||
}
|
||||
|
||||
close(pConnection->sock);
|
||||
pConnection->sock = -1;
|
||||
|
|
|
|||
|
|
@ -139,11 +139,13 @@ void conn_pool_disconnect_server(ConnectionInfo *pConnection);
|
|||
* pConnection: the connection
|
||||
* connect_timeout: the connect timeout in seconds
|
||||
* bind_ipaddr: the ip address to bind, NULL or empty for any
|
||||
* log_connect_error: if log error info when connect fail
|
||||
* NOTE: pConnection->sock will be closed when it >= 0 before connect
|
||||
* return 0 for success, != 0 for error
|
||||
*/
|
||||
int conn_pool_connect_server_ex(ConnectionInfo *pConnection,
|
||||
const int connect_timeout, const char *bind_ipaddr);
|
||||
const int connect_timeout, const char *bind_ipaddr,
|
||||
const bool log_connect_error);
|
||||
|
||||
/**
|
||||
* connect to the server
|
||||
|
|
@ -158,7 +160,23 @@ static inline int conn_pool_connect_server(ConnectionInfo *pConnection,
|
|||
{
|
||||
const char *bind_ipaddr = NULL;
|
||||
return conn_pool_connect_server_ex(pConnection,
|
||||
connect_timeout, bind_ipaddr);
|
||||
connect_timeout, bind_ipaddr, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* connect to the server
|
||||
* parameters:
|
||||
* pConnection: the connection
|
||||
* connect_timeout: the connect timeout in seconds
|
||||
* return 0 for success, != 0 for error
|
||||
*/
|
||||
static inline int conn_pool_connect_server_anyway(ConnectionInfo *pConnection,
|
||||
const int connect_timeout)
|
||||
{
|
||||
const char *bind_ipaddr = NULL;
|
||||
pConnection->sock = -1;
|
||||
return conn_pool_connect_server_ex(pConnection,
|
||||
connect_timeout, bind_ipaddr, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue