add function conn_pool_connect_server_ex
parent
d32a72db1f
commit
69463768ea
2
HISTORY
2
HISTORY
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
|
||||
Version 1.41 2019-09-29
|
||||
Version 1.41 2019-09-30
|
||||
* change CIDR network_bits range from [16, 32) to [10, 32)
|
||||
* ini_file_reader.c: fix empty string compare
|
||||
* multi_socket_client.c: code refine
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@ void conn_pool_disconnect_server(ConnectionInfo *pConnection)
|
|||
}
|
||||
}
|
||||
|
||||
int conn_pool_connect_server(ConnectionInfo *pConnection, \
|
||||
const int connect_timeout)
|
||||
int conn_pool_connect_server_ex(ConnectionInfo *pConnection,
|
||||
const int connect_timeout, const char *bind_ipaddr)
|
||||
{
|
||||
int result;
|
||||
int domain;
|
||||
|
|
@ -114,6 +114,11 @@ int conn_pool_connect_server(ConnectionInfo *pConnection, \
|
|||
return errno != 0 ? errno : EPERM;
|
||||
}
|
||||
|
||||
if (bind_ipaddr != NULL && *bind_ipaddr != '\0')
|
||||
{
|
||||
socketBind2(domain, pConnection->sock, bind_ipaddr, 0);
|
||||
}
|
||||
|
||||
SET_SOCKOPT_NOSIGPIPE(pConnection->sock);
|
||||
if ((result=tcpsetnonblockopt(pConnection->sock)) != 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FC_CONNECTION_SERVER_EQUAL(conn, target_ip, target_port) \
|
||||
(strcmp((conn).ip_addr, target_ip) == 0 && \
|
||||
(conn).port == target_port)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sock;
|
||||
|
|
@ -134,11 +138,28 @@ void conn_pool_disconnect_server(ConnectionInfo *pConnection);
|
|||
* parameters:
|
||||
* pConnection: the connection
|
||||
* connect_timeout: the connect timeout in seconds
|
||||
* bind_ipaddr: the ip address to bind, NULL or empty for any
|
||||
* NOTE: pConnection->sock will be closed when it >= 0 before connect
|
||||
* return 0 for success, != 0 for error
|
||||
*/
|
||||
int conn_pool_connect_server(ConnectionInfo *pConnection, \
|
||||
const int connect_timeout);
|
||||
int conn_pool_connect_server_ex(ConnectionInfo *pConnection,
|
||||
const int connect_timeout, const char *bind_ipaddr);
|
||||
|
||||
/**
|
||||
* connect to the server
|
||||
* parameters:
|
||||
* pConnection: the connection
|
||||
* connect_timeout: the connect timeout in seconds
|
||||
* NOTE: pConnection->sock will be closed when it >= 0 before connect
|
||||
* return 0 for success, != 0 for error
|
||||
*/
|
||||
static inline int conn_pool_connect_server(ConnectionInfo *pConnection,
|
||||
const int connect_timeout)
|
||||
{
|
||||
const char *bind_ipaddr = NULL;
|
||||
return conn_pool_connect_server_ex(pConnection,
|
||||
connect_timeout, bind_ipaddr);
|
||||
}
|
||||
|
||||
/**
|
||||
* get connection count of the pool
|
||||
|
|
|
|||
Loading…
Reference in New Issue