add function fc_server_check_connect_ex
parent
89ad53974f
commit
6e5511614d
2
HISTORY
2
HISTORY
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Version 1.44 2020-02-19
|
Version 1.44 2020-02-20
|
||||||
* add test file src/tests/test_pthread_lock.c
|
* add test file src/tests/test_pthread_lock.c
|
||||||
* add uniq_skiplist.[hc]
|
* add uniq_skiplist.[hc]
|
||||||
* add function split_string_ex
|
* add function split_string_ex
|
||||||
|
|
|
||||||
|
|
@ -1451,3 +1451,59 @@ void fc_server_to_log(FCServerConfig *ctx)
|
||||||
fc_server_log_groups(ctx);
|
fc_server_log_groups(ctx);
|
||||||
fc_server_log_servers(ctx);
|
fc_server_log_servers(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConnectionInfo *fc_server_check_connect_ex(FCAddressPtrArray *addr_array,
|
||||||
|
const int connect_timeout, const char *bind_ipaddr,
|
||||||
|
const bool log_connect_error, int *err_no)
|
||||||
|
{
|
||||||
|
FCAddressInfo **current;
|
||||||
|
FCAddressInfo **addr;
|
||||||
|
FCAddressInfo **end;
|
||||||
|
|
||||||
|
if (addr_array->count <= 0) {
|
||||||
|
*err_no = ENOENT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
current = addr_array->addrs + addr_array->index;
|
||||||
|
if ((*current)->conn.sock >= 0) {
|
||||||
|
return &(*current)->conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*err_no= conn_pool_connect_server_ex(&(*current)->conn,
|
||||||
|
connect_timeout, bind_ipaddr, log_connect_error)) == 0)
|
||||||
|
{
|
||||||
|
return &(*current)->conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addr_array->count == 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
end = addr_array->addrs + addr_array->count;
|
||||||
|
for (addr=addr_array->addrs; addr<end; addr++) {
|
||||||
|
if (addr == current) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((*err_no= conn_pool_connect_server_ex(&(*addr)->conn,
|
||||||
|
connect_timeout, bind_ipaddr,
|
||||||
|
log_connect_error)) == 0)
|
||||||
|
{
|
||||||
|
addr_array->index = addr - addr_array->addrs;
|
||||||
|
return &(*addr)->conn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fc_server_disconnect(FCAddressPtrArray *addr_array)
|
||||||
|
{
|
||||||
|
FCAddressInfo **current;
|
||||||
|
|
||||||
|
current = addr_array->addrs + addr_array->index;
|
||||||
|
if ((*current)->conn.sock >= 0) {
|
||||||
|
close((*current)->conn.sock);
|
||||||
|
(*current)->conn.sock = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int alloc;
|
int alloc;
|
||||||
int count;
|
int count;
|
||||||
|
int index;
|
||||||
FCAddressInfo **addrs;
|
FCAddressInfo **addrs;
|
||||||
} FCAddressPtrArray;
|
} FCAddressPtrArray;
|
||||||
|
|
||||||
|
|
@ -172,6 +173,16 @@ int fc_server_to_config_string(FCServerConfig *ctx, FastBuffer *buffer);
|
||||||
|
|
||||||
void fc_server_to_log(FCServerConfig *ctx);
|
void fc_server_to_log(FCServerConfig *ctx);
|
||||||
|
|
||||||
|
ConnectionInfo *fc_server_check_connect_ex(FCAddressPtrArray *addr_array,
|
||||||
|
const int connect_timeout, const char *bind_ipaddr,
|
||||||
|
const bool log_connect_error, int *err_no);
|
||||||
|
|
||||||
|
#define fc_server_check_connect(addr_array, connect_timeout, err_no) \
|
||||||
|
fc_server_check_connect_ex(addr_array, connect_timeout, NULL, true, err_no)
|
||||||
|
|
||||||
|
|
||||||
|
void fc_server_disconnect(FCAddressPtrArray *addr_array);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue