bugfixed: uniq_addresses use FCAddressPtrArray
parent
fb03bf23ba
commit
ec22ab681e
2
HISTORY
2
HISTORY
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Version 1.44 2020-06-01
|
Version 1.44 2020-06-28
|
||||||
* 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
|
||||||
|
|
|
||||||
|
|
@ -107,19 +107,19 @@ static int fc_server_calc_ip_port_count(FCServerConfig *ctx)
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fc_server_check_alloc_group_addresses(FCAddressArray *array)
|
static int fc_server_check_alloc_group_addresses(FCAddressPtrArray *array)
|
||||||
{
|
{
|
||||||
int new_alloc;
|
int new_alloc;
|
||||||
int bytes;
|
int bytes;
|
||||||
FCAddressInfo *new_addrs;
|
FCAddressInfo **new_addrs;
|
||||||
|
|
||||||
if (array->count < array->alloc) {
|
if (array->count < array->alloc) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_alloc = array->alloc > 0 ? 2 * array->alloc : 2;
|
new_alloc = array->alloc > 0 ? 2 * array->alloc : 2;
|
||||||
bytes = sizeof(FCAddressInfo) * new_alloc;
|
bytes = sizeof(FCAddressInfo *) * new_alloc;
|
||||||
new_addrs = (FCAddressInfo *)malloc(bytes);
|
new_addrs = (FCAddressInfo **)malloc(bytes);
|
||||||
if (new_addrs == NULL) {
|
if (new_addrs == NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"malloc %d bytes fail", __LINE__, bytes);
|
"malloc %d bytes fail", __LINE__, bytes);
|
||||||
|
|
@ -128,7 +128,7 @@ static int fc_server_check_alloc_group_addresses(FCAddressArray *array)
|
||||||
memset(new_addrs, 0, bytes);
|
memset(new_addrs, 0, bytes);
|
||||||
|
|
||||||
if (array->addrs != NULL) {
|
if (array->addrs != NULL) {
|
||||||
memcpy(new_addrs, array->addrs, sizeof(FCAddressInfo) * array->count);
|
memcpy(new_addrs, array->addrs, sizeof(FCAddressInfo *) * array->count);
|
||||||
free(array->addrs);
|
free(array->addrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,24 +138,32 @@ static int fc_server_check_alloc_group_addresses(FCAddressArray *array)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FCAddressInfo *fc_server_add_to_uniq_addresses(
|
static FCAddressInfo *fc_server_add_to_uniq_addresses(
|
||||||
FCAddressArray *addr_array, const FCAddressInfo *addr)
|
FCAddressPtrArray *addr_ptr_array, const FCAddressInfo *addr)
|
||||||
{
|
{
|
||||||
FCAddressInfo *p;
|
FCAddressInfo *p;
|
||||||
FCAddressInfo *end;
|
FCAddressInfo **pp;
|
||||||
|
FCAddressInfo **end;
|
||||||
|
|
||||||
end = addr_array->addrs + addr_array->count;
|
end = addr_ptr_array->addrs + addr_ptr_array->count;
|
||||||
for (p=addr_array->addrs; p<end; p++) {
|
for (pp=addr_ptr_array->addrs; pp<end; pp++) {
|
||||||
if (FC_CONNECTION_SERVER_EQUAL1(addr->conn, p->conn)) {
|
if (FC_CONNECTION_SERVER_EQUAL1(addr->conn, (*pp)->conn)) {
|
||||||
return p;
|
return *pp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fc_server_check_alloc_group_addresses(addr_array) != 0) {
|
if (fc_server_check_alloc_group_addresses(addr_ptr_array) != 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
p = addr_array->addrs + addr_array->count;
|
p = (FCAddressInfo *)malloc(sizeof(FCAddressInfo));
|
||||||
|
if (p == NULL) {
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"malloc %d bytes fail", __LINE__,
|
||||||
|
(int)sizeof(FCAddressInfo));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
*p = *addr;
|
*p = *addr;
|
||||||
addr_array->count++;
|
addr_ptr_array->addrs[addr_ptr_array->count++] = p;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,8 +176,8 @@ static int fc_server_init_ip_port_array(FCServerConfig *ctx)
|
||||||
FCServerMap *map;
|
FCServerMap *map;
|
||||||
FCServerInfo *server;
|
FCServerInfo *server;
|
||||||
FCServerInfo *send;
|
FCServerInfo *send;
|
||||||
FCAddressInfo *paddr;
|
FCAddressInfo **paddr;
|
||||||
FCAddressInfo *pend;
|
FCAddressInfo **pend;
|
||||||
|
|
||||||
map_array = &ctx->sorted_server_arrays.by_ip_port;
|
map_array = &ctx->sorted_server_arrays.by_ip_port;
|
||||||
|
|
||||||
|
|
@ -192,8 +200,8 @@ static int fc_server_init_ip_port_array(FCServerConfig *ctx)
|
||||||
pend = server->uniq_addresses.addrs + server->uniq_addresses.count;
|
pend = server->uniq_addresses.addrs + server->uniq_addresses.count;
|
||||||
for (paddr=server->uniq_addresses.addrs; paddr<pend; paddr++) {
|
for (paddr=server->uniq_addresses.addrs; paddr<pend; paddr++) {
|
||||||
map->server = server;
|
map->server = server;
|
||||||
FC_SET_STRING(map->ip_addr, paddr->conn.ip_addr);
|
FC_SET_STRING(map->ip_addr, (*paddr)->conn.ip_addr);
|
||||||
map->port = paddr->conn.port;
|
map->port = (*paddr)->conn.port;
|
||||||
map++;
|
map++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -737,14 +745,14 @@ static int fc_server_set_group_server_address(FCServerInfo *server,
|
||||||
if (addr == NULL) {
|
if (addr == NULL) {
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=fc_server_check_alloc_group_address_ptrs(
|
if ((result=fc_server_check_alloc_group_address_ptrs(
|
||||||
&group_addr->address_array)) != 0)
|
&group_addr->address_array)) != 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
group_addr->address_array.addrs[group_addr->address_array.count] = addr;
|
group_addr->address_array.addrs[group_addr->address_array.count++] = addr;
|
||||||
group_addr->address_array.count++;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -831,6 +839,7 @@ static int fc_server_set_host(FCServerConfig *ctx, FCServerInfo *server,
|
||||||
} else {
|
} else {
|
||||||
new_addr = addr;
|
new_addr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=fc_server_set_group_server_address(server,
|
if ((result=fc_server_set_group_server_address(server,
|
||||||
group_addr, new_addr)) != 0)
|
group_addr, new_addr)) != 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ typedef struct
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int id; //server id
|
int id; //server id
|
||||||
FCAddressArray uniq_addresses;
|
FCAddressPtrArray uniq_addresses;
|
||||||
FCGroupAddresses group_addrs[FC_MAX_GROUP_COUNT];
|
FCGroupAddresses group_addrs[FC_MAX_GROUP_COUNT];
|
||||||
} FCServerInfo;
|
} FCServerInfo;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@
|
||||||
#include "fastcommon/logger.h"
|
#include "fastcommon/logger.h"
|
||||||
#include "fastcommon/shared_func.h"
|
#include "fastcommon/shared_func.h"
|
||||||
|
|
||||||
|
#define OneArgument(a) printf("One Argument func is called!\n")
|
||||||
|
#define TwoArguments(a, b) printf("Two Arguments func is called!\n")
|
||||||
|
#define TreeArguments(a, b, c) printf("Tree Arguments func is called!\n")
|
||||||
|
#define MacroKernel(_1, _2, _3, FUNC, ...) FUNC
|
||||||
|
#define Macro(...) MacroKernel(__VA_ARGS__, TreeArguments, TwoArguments, OneArgument, ...)(__VA_ARGS__)
|
||||||
|
|
||||||
static inline int get_lock_info(int fd, struct flock *lock)
|
static inline int get_lock_info(int fd, struct flock *lock)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
@ -43,6 +49,9 @@ int main(int argc, char *argv[])
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
struct flock lock;
|
struct flock lock;
|
||||||
|
|
||||||
|
Macro(1);
|
||||||
|
Macro(1, 2);
|
||||||
|
Macro(1, 2, 3);
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
|
fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue