format ip address for IPv6
parent
9a720533ce
commit
226fd0d378
3
HISTORY
3
HISTORY
|
|
@ -1,7 +1,8 @@
|
|||
|
||||
Version 1.73 2024-02-20
|
||||
Version 1.73 2024-03-05
|
||||
* add macro FC_SET_STRING_EMPTY
|
||||
* struct fast_task_info remove fields: connect_timeout and network_timeout
|
||||
* format ip address for IPv6
|
||||
|
||||
Version 1.72 2024-01-21
|
||||
* call fast_mblock_ref_counter_dec for delay free node correctly
|
||||
|
|
|
|||
|
|
@ -119,7 +119,8 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind);
|
|||
#endif
|
||||
|
||||
// 由于要支持IPv6,所以将IP_ADDRESS_SIZE的值由16修改为46
|
||||
#define IP_ADDRESS_SIZE INET6_ADDRSTRLEN //46
|
||||
#define IP_ADDRESS_SIZE INET6_ADDRSTRLEN //46
|
||||
#define FORMATTED_IP_SIZE (IP_ADDRESS_SIZE + 2)
|
||||
#define INFINITE_FILE_SIZE (256 * 1024LL * 1024 * 1024 * 1024 * 1024LL)
|
||||
|
||||
#define FILE_RESOURCE_TAG_STR "file://"
|
||||
|
|
|
|||
|
|
@ -204,6 +204,7 @@ int conn_pool_connect_server_ex1(ConnectionInfo *conn,
|
|||
const char *bind_ipaddr, const bool log_connect_error)
|
||||
{
|
||||
int result;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
if (conn->sock >= 0)
|
||||
{
|
||||
|
|
@ -221,12 +222,12 @@ int conn_pool_connect_server_ex1(ConnectionInfo *conn,
|
|||
{
|
||||
if (log_connect_error)
|
||||
{
|
||||
FC_FORMAT_IP_ADDRESS(conn->ip_addr, new_ip_addr);
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"connect to %s%sserver %s:%u fail, errno: %d, "
|
||||
"error info: %s", __LINE__, service_name != NULL ?
|
||||
service_name : "", service_name != NULL ? " " : "",
|
||||
new_ip_addr, conn->port, result, STRERROR(result));
|
||||
formatted_ip, conn->port, result, STRERROR(result));
|
||||
}
|
||||
|
||||
close(conn->sock);
|
||||
|
|
@ -241,6 +242,7 @@ int conn_pool_async_connect_server_ex(ConnectionInfo *conn,
|
|||
const char *bind_ipaddr)
|
||||
{
|
||||
int result;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
if (conn->sock >= 0)
|
||||
{
|
||||
|
|
@ -256,10 +258,10 @@ int conn_pool_async_connect_server_ex(ConnectionInfo *conn,
|
|||
result = asyncconnectserverbyip(conn->sock, conn->ip_addr, conn->port);
|
||||
if (!(result == 0 || result == EINPROGRESS))
|
||||
{
|
||||
FC_FORMAT_IP_ADDRESS(conn->ip_addr, new_ip_addr);
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"connect to server %s:%u fail, errno: %d, "
|
||||
"error info: %s", __LINE__, new_ip_addr,
|
||||
"error info: %s", __LINE__, formatted_ip,
|
||||
conn->port, result, STRERROR(result));
|
||||
close(conn->sock);
|
||||
conn->sock = -1;
|
||||
|
|
@ -281,6 +283,7 @@ static ConnectionInfo *get_connection(ConnectionPool *cp,
|
|||
ConnectionManager *cm;
|
||||
ConnectionNode *node;
|
||||
ConnectionInfo *ci;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
time_t current_time;
|
||||
|
||||
pthread_mutex_lock(&cp->lock);
|
||||
|
|
@ -321,13 +324,13 @@ static ConnectionInfo *get_connection(ConnectionPool *cp,
|
|||
if ((cp->max_count_per_entry > 0) &&
|
||||
(cm->total_count >= cp->max_count_per_entry))
|
||||
{
|
||||
FC_FORMAT_IP_ADDRESS(conn->ip_addr, new_ip_addr);
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
*err_no = ENOSPC;
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"connections: %d of %s%sserver %s:%u exceed limit: %d",
|
||||
__LINE__, cm->total_count, service_name != NULL ?
|
||||
service_name : "", service_name != NULL ? " " : "",
|
||||
new_ip_addr, conn->port, cp->max_count_per_entry);
|
||||
formatted_ip, conn->port, cp->max_count_per_entry);
|
||||
pthread_mutex_unlock(&cm->lock);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -377,12 +380,15 @@ static ConnectionInfo *get_connection(ConnectionPool *cp,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"server %s:%u, new connection: %d, " \
|
||||
"total_count: %d, free_count: %d", \
|
||||
__LINE__, conn->ip_addr, conn->port, \
|
||||
node->conn->sock, cm->total_count, \
|
||||
cm->free_count);
|
||||
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server %s:%u, new connection: %d, "
|
||||
"total_count: %d, free_count: %d",
|
||||
__LINE__, formatted_ip, conn->port,
|
||||
node->conn->sock, cm->total_count,
|
||||
cm->free_count);
|
||||
}
|
||||
return node->conn;
|
||||
}
|
||||
else
|
||||
|
|
@ -425,13 +431,16 @@ static ConnectionInfo *get_connection(ConnectionPool *cp,
|
|||
{
|
||||
cm->total_count--;
|
||||
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server %s:%u, connection: %d idle "
|
||||
"time: %d exceeds max idle time: %d, "
|
||||
"total_count: %d, free_count: %d", __LINE__,
|
||||
conn->ip_addr, conn->port, ci->sock, (int)
|
||||
(current_time - node->atime), cp->max_idle_time,
|
||||
cm->total_count, cm->free_count);
|
||||
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server %s:%u, connection: %d idle "
|
||||
"time: %d exceeds max idle time: %d, "
|
||||
"total_count: %d, free_count: %d", __LINE__,
|
||||
formatted_ip, conn->port, ci->sock, (int)
|
||||
(current_time - node->atime), cp->max_idle_time,
|
||||
cm->total_count, cm->free_count);
|
||||
}
|
||||
|
||||
G_COMMON_CONNECTION_CALLBACKS[ci->comm_type].
|
||||
close_connection(ci);
|
||||
|
|
@ -440,11 +449,16 @@ static ConnectionInfo *get_connection(ConnectionPool *cp,
|
|||
}
|
||||
|
||||
pthread_mutex_unlock(&cm->lock);
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"server %s:%u, reuse connection: %d, " \
|
||||
"total_count: %d, free_count: %d",
|
||||
__LINE__, conn->ip_addr, conn->port,
|
||||
ci->sock, cm->total_count, cm->free_count);
|
||||
|
||||
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server %s:%u, reuse connection: %d, "
|
||||
"total_count: %d, free_count: %d",
|
||||
__LINE__, formatted_ip, conn->port,
|
||||
ci->sock, cm->total_count, cm->free_count);
|
||||
}
|
||||
|
||||
*err_no = 0;
|
||||
return ci;
|
||||
}
|
||||
|
|
@ -526,26 +540,27 @@ static int close_connection(ConnectionPool *cp, ConnectionInfo *conn,
|
|||
{
|
||||
ConnectionManager *cm;
|
||||
ConnectionNode *node;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
pthread_mutex_lock(&cp->lock);
|
||||
cm = (ConnectionManager *)fc_hash_find(&cp->hash_array, key->str, key->len);
|
||||
pthread_mutex_unlock(&cp->lock);
|
||||
if (cm == NULL)
|
||||
{
|
||||
FC_FORMAT_IP_ADDRESS(conn->ip_addr, new_ip_addr);
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"hash entry of server %s:%u not exist",
|
||||
__LINE__, new_ip_addr, conn->port);
|
||||
__LINE__, formatted_ip, conn->port);
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
node = (ConnectionNode *)((char *)conn - sizeof(ConnectionNode));
|
||||
if (node->manager != cm)
|
||||
{
|
||||
FC_FORMAT_IP_ADDRESS(conn->ip_addr, new_ip_addr);
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"manager of server entry %s:%u is invalid!",
|
||||
__LINE__, new_ip_addr, conn->port);
|
||||
__LINE__, formatted_ip, conn->port);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -554,11 +569,14 @@ static int close_connection(ConnectionPool *cp, ConnectionInfo *conn,
|
|||
{
|
||||
cm->total_count--;
|
||||
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server %s:%u, release connection: %d, "
|
||||
"total_count: %d, free_count: %d",
|
||||
__LINE__, conn->ip_addr, conn->port,
|
||||
conn->sock, cm->total_count, cm->free_count);
|
||||
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server %s:%u, release connection: %d, "
|
||||
"total_count: %d, free_count: %d",
|
||||
__LINE__, formatted_ip, conn->port,
|
||||
conn->sock, cm->total_count, cm->free_count);
|
||||
}
|
||||
|
||||
G_COMMON_CONNECTION_CALLBACKS[conn->comm_type].
|
||||
close_connection(conn);
|
||||
|
|
@ -578,11 +596,14 @@ static int close_connection(ConnectionPool *cp, ConnectionInfo *conn,
|
|||
cm->head = node;
|
||||
cm->free_count++;
|
||||
|
||||
logDebug("file: "__FILE__", line: %d, " \
|
||||
"server %s:%u, free connection: %d, " \
|
||||
"total_count: %d, free_count: %d",
|
||||
__LINE__, conn->ip_addr, conn->port,
|
||||
conn->sock, cm->total_count, cm->free_count);
|
||||
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||
format_ip_address(conn->ip_addr, formatted_ip);
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server %s:%u, free connection: %d, "
|
||||
"total_count: %d, free_count: %d",
|
||||
__LINE__, formatted_ip, conn->port,
|
||||
conn->sock, cm->total_count, cm->free_count);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&cm->lock);
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ static int fast_multi_sock_client_do_send(FastMultiSockClient *client,
|
|||
{
|
||||
int bytes;
|
||||
int result;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
result = 0;
|
||||
while (entry->remain > 0) {
|
||||
|
|
@ -139,27 +140,26 @@ static int fast_multi_sock_client_do_send(FastMultiSockClient *client,
|
|||
break;
|
||||
} else if (errno == EINTR) { //should retry
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server: %s:%u, ignore interupt signal",
|
||||
__LINE__, entry->conn->ip_addr,
|
||||
"server: %s:%u, ignore interupt signal", __LINE__,
|
||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
||||
entry->conn->port);
|
||||
continue;
|
||||
} else {
|
||||
result = errno != 0 ? errno : ECONNRESET;
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send to server %s:%u fail, "
|
||||
"errno: %d, error info: %s",
|
||||
__LINE__, entry->conn->ip_addr,
|
||||
entry->conn->port,
|
||||
result, strerror(result));
|
||||
"errno: %d, error info: %s", __LINE__,
|
||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
||||
entry->conn->port, result, strerror(result));
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (bytes == 0) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"send to server %s:%u, sock: %d fail, "
|
||||
"connection disconnected",
|
||||
__LINE__, entry->conn->ip_addr, entry->conn->port,
|
||||
entry->conn->sock);
|
||||
"connection disconnected", __LINE__,
|
||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
||||
entry->conn->port, entry->conn->sock);
|
||||
|
||||
result = ECONNRESET;
|
||||
break;
|
||||
|
|
@ -190,6 +190,7 @@ static int fast_multi_sock_client_send_data(FastMultiSockClient *client,
|
|||
{
|
||||
int i;
|
||||
int result;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
for (i=0; i<client->entry_count; i++) {
|
||||
client->entries[i].remain = send_buffer->length;
|
||||
|
|
@ -202,9 +203,9 @@ static int fast_multi_sock_client_send_data(FastMultiSockClient *client,
|
|||
client->entries[i].error_no = ENOTCONN;
|
||||
client->entries[i].done = true;
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"NOT connected to %s:%u",
|
||||
__LINE__, client->entries[i].conn->ip_addr,
|
||||
client->entries[i].conn->port);
|
||||
"NOT connected to %s:%u", __LINE__,
|
||||
format_ip_address(client->entries[i].conn->ip_addr,
|
||||
formatted_ip), client->entries[i].conn->port);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -244,6 +245,7 @@ static int fast_multi_sock_client_do_recv(FastMultiSockClient *client,
|
|||
{
|
||||
int bytes;
|
||||
int result;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
result = 0;
|
||||
while (entry->remain > 0) {
|
||||
|
|
@ -254,27 +256,26 @@ static int fast_multi_sock_client_do_recv(FastMultiSockClient *client,
|
|||
break;
|
||||
} else if (errno == EINTR) { //should retry
|
||||
logDebug("file: "__FILE__", line: %d, "
|
||||
"server: %s:%u, ignore interupt signal",
|
||||
__LINE__, entry->conn->ip_addr,
|
||||
"server: %s:%u, ignore interupt signal", __LINE__,
|
||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
||||
entry->conn->port);
|
||||
continue;
|
||||
} else {
|
||||
result = errno != 0 ? errno : ECONNRESET;
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"server: %s:%u, recv failed, "
|
||||
"errno: %d, error info: %s",
|
||||
__LINE__, entry->conn->ip_addr,
|
||||
entry->conn->port,
|
||||
result, strerror(result));
|
||||
"errno: %d, error info: %s", __LINE__,
|
||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
||||
entry->conn->port, result, strerror(result));
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (bytes == 0) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"server: %s:%u, sock: %d, recv failed, "
|
||||
"connection disconnected",
|
||||
__LINE__, entry->conn->ip_addr, entry->conn->port,
|
||||
entry->conn->sock);
|
||||
"connection disconnected", __LINE__,
|
||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
||||
entry->conn->port, entry->conn->sock);
|
||||
|
||||
result = ECONNRESET;
|
||||
break;
|
||||
|
|
@ -289,8 +290,8 @@ static int fast_multi_sock_client_do_recv(FastMultiSockClient *client,
|
|||
body_length = client->get_body_length_func(&entry->recv_buffer);
|
||||
if (body_length < 0) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"server: %s:%u, body_length: %d < 0",
|
||||
__LINE__, entry->conn->ip_addr,
|
||||
"server: %s:%u, body_length: %d < 0", __LINE__,
|
||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
||||
entry->conn->port, body_length);
|
||||
result = EPIPE;
|
||||
break;
|
||||
|
|
@ -320,6 +321,7 @@ static int fast_multi_sock_client_deal_io(FastMultiSockClient *client)
|
|||
int index;
|
||||
int remain_timeout;
|
||||
FastMultiSockEntry *entry;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
while (client->pulling_count > 0) {
|
||||
remain_timeout = client->deadline_time_ms -
|
||||
|
|
@ -329,7 +331,7 @@ static int fast_multi_sock_client_deal_io(FastMultiSockClient *client)
|
|||
}
|
||||
|
||||
count = ioevent_poll_ex(&client->ioevent, remain_timeout);
|
||||
logInfo("poll count: %d\n", count);
|
||||
//logInfo("poll count: %d\n", count);
|
||||
for (index=0; index<count; index++) {
|
||||
event = IOEVENT_GET_EVENTS(&client->ioevent, index);
|
||||
entry = (FastMultiSockEntry *)IOEVENT_GET_DATA(
|
||||
|
|
@ -337,15 +339,15 @@ static int fast_multi_sock_client_deal_io(FastMultiSockClient *client)
|
|||
|
||||
if (event & IOEVENT_ERROR) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"server: %s:%u, recv error event: %d, "
|
||||
"connection reset", __LINE__,
|
||||
entry->conn->ip_addr, entry->conn->port, event);
|
||||
"server: %s:%u, recv error event: %d, connection "
|
||||
"reset", __LINE__, format_ip_address(entry->conn->
|
||||
ip_addr, formatted_ip), entry->conn->port, event);
|
||||
|
||||
fast_multi_sock_client_finish(client, entry, ECONNRESET);
|
||||
continue;
|
||||
}
|
||||
|
||||
logInfo("sock: %d, event: %d", entry->conn->sock, event);
|
||||
//logInfo("sock: %d, event: %d", entry->conn->sock, event);
|
||||
|
||||
result = entry->io_callback(client, entry);
|
||||
if (result != 0 || entry->remain == 0) {
|
||||
|
|
@ -366,9 +368,9 @@ static int fast_multi_sock_client_deal_io(FastMultiSockClient *client)
|
|||
fast_multi_sock_client_finish(client,
|
||||
client->entries + i, ETIMEDOUT);
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"recv from %s:%u timedout",
|
||||
__LINE__, client->entries[i].conn->ip_addr,
|
||||
client->entries[i].conn->port);
|
||||
"recv from %s:%u timedout", __LINE__,
|
||||
format_ip_address(client->entries[i].conn->ip_addr,
|
||||
formatted_ip), client->entries[i].conn->port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -244,6 +244,7 @@ static int fc_server_check_ip_port(FCServerConfig *ctx,
|
|||
FCServerMap *previous;
|
||||
FCServerMap *current;
|
||||
FCServerMap *end;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
int id1;
|
||||
int id2;
|
||||
|
||||
|
|
@ -261,8 +262,8 @@ static int fc_server_check_ip_port(FCServerConfig *ctx,
|
|||
logError("file: "__FILE__", line: %d, "
|
||||
"config file: %s, duplicate ip:port %s:%u, "
|
||||
"the server ids: %d, %d", __LINE__,
|
||||
config_filename, previous->ip_addr.str,
|
||||
previous->port, id1, id2);
|
||||
config_filename, format_ip_address(previous->ip_addr.str,
|
||||
formatted_ip), previous->port, id1, id2);
|
||||
return EEXIST;
|
||||
}
|
||||
|
||||
|
|
@ -698,6 +699,7 @@ static int check_addresses_duplicate(FCServerConfig *ctx,
|
|||
FCAddressInfo **ppaddr;
|
||||
FCAddressInfo **ppend;
|
||||
FCAddressInfo **pprevious;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
if (group_addr->address_array.count <= 1) {
|
||||
return 0;
|
||||
|
|
@ -715,7 +717,8 @@ static int check_addresses_duplicate(FCServerConfig *ctx,
|
|||
config_filename, section_name,
|
||||
group_addr->server_group->group_name.len,
|
||||
group_addr->server_group->group_name.str,
|
||||
(*ppaddr)->conn.ip_addr, (*ppaddr)->conn.port);
|
||||
format_ip_address((*ppaddr)->conn.ip_addr, formatted_ip),
|
||||
(*ppaddr)->conn.port);
|
||||
return EEXIST;
|
||||
}
|
||||
pprevious = ppaddr;
|
||||
|
|
@ -899,6 +902,7 @@ static int fc_server_set_host(FCServerConfig *ctx, FCServerInfo *server,
|
|||
FCGroupAddresses *group_addr;
|
||||
const FCAddressInfo *new_addr;
|
||||
FCAddressInfo addr_holder;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
int result;
|
||||
int count;
|
||||
int group_index;
|
||||
|
|
@ -964,7 +968,8 @@ static int fc_server_set_host(FCServerConfig *ctx, FCServerInfo *server,
|
|||
"config filename: %s, section: %s, "
|
||||
"host %s:%u belongs to %d groups",
|
||||
__LINE__, config_filename, section_name,
|
||||
addr->conn.ip_addr, addr->conn.port, count);
|
||||
format_ip_address(addr->conn.ip_addr, formatted_ip),
|
||||
addr->conn.port, count);
|
||||
return EEXIST;
|
||||
}
|
||||
|
||||
|
|
@ -1523,6 +1528,7 @@ static void fc_group_servers_to_string(FCServerConfig *ctx,
|
|||
{
|
||||
FCAddressInfo **addr;
|
||||
FCAddressInfo **end;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
end = gaddr->address_array.addrs + gaddr->address_array.count;
|
||||
for (addr=gaddr->address_array.addrs; addr<end; addr++) {
|
||||
|
|
@ -1536,7 +1542,8 @@ static void fc_group_servers_to_string(FCServerConfig *ctx,
|
|||
SERVER_ITEM_HOST_AFFIX_STR);
|
||||
}
|
||||
fast_buffer_append(buffer, " = %s:%u\n",
|
||||
(*addr)->conn.ip_addr, (*addr)->conn.port);
|
||||
format_ip_address((*addr)->conn.ip_addr, formatted_ip),
|
||||
(*addr)->conn.port);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1641,11 +1648,13 @@ static void fc_server_log_group_servers(FCGroupAddresses *gaddr)
|
|||
{
|
||||
FCAddressInfo **addr;
|
||||
FCAddressInfo **end;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
end = gaddr->address_array.addrs + gaddr->address_array.count;
|
||||
for (addr=gaddr->address_array.addrs; addr<end; addr++) {
|
||||
logInfo(" %d. %s:%u", (int)(addr - gaddr->address_array.addrs + 1),
|
||||
(*addr)->conn.ip_addr, (*addr)->conn.port);
|
||||
format_ip_address((*addr)->conn.ip_addr, formatted_ip),
|
||||
(*addr)->conn.port);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -816,7 +816,6 @@ bool is_private_ip(const char* ip);
|
|||
*/
|
||||
int parseAddress(char *src, char *parts[2]);
|
||||
|
||||
|
||||
/** get current time in ns
|
||||
* return: current time
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1056,6 +1056,7 @@ int socketClientEx2(int af, const char *server_ip,
|
|||
{
|
||||
int sock;
|
||||
bool auto_detect;
|
||||
char formatted_ip[FORMATTED_IP_SIZE];
|
||||
|
||||
sock = socketCreateEx2(af, server_ip,
|
||||
flags, bind_ipaddr, err_no);
|
||||
|
|
@ -1069,11 +1070,11 @@ int socketClientEx2(int af, const char *server_ip,
|
|||
server_port, timeout, auto_detect);
|
||||
if (*err_no != 0)
|
||||
{
|
||||
FC_FORMAT_IP_ADDRESS(server_ip, new_ip_addr);
|
||||
format_ip_address(server_ip, formatted_ip);
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"connect to %s:%u fail, "
|
||||
"errno: %d, error info: %s",
|
||||
__LINE__, new_ip_addr, server_port,
|
||||
__LINE__, formatted_ip, server_port,
|
||||
*err_no, STRERROR(*err_no));
|
||||
close(sock);
|
||||
return -4;
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@
|
|||
#ifndef _SOCKETOPT_H_
|
||||
#define _SOCKETOPT_H_
|
||||
|
||||
#include <net/if.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
|
@ -53,7 +54,7 @@
|
|||
#define FAST_WRITE_BUFF_SIZE (256 * 1024)
|
||||
|
||||
#define FC_FORMAT_IP_ADDRESS(old_ip_addr, new_ip_addr) \
|
||||
char new_ip_addr[IP_ADDRESS_SIZE + 2]; \
|
||||
char new_ip_addr[FORMATTED_IP_SIZE]; \
|
||||
do { \
|
||||
if (is_ipv6_addr(old_ip_addr)) { \
|
||||
sprintf(new_ip_addr, "[%s]", old_ip_addr); \
|
||||
|
|
@ -714,6 +715,35 @@ static inline bool is_ipv6_addr(const char *ip)
|
|||
return (*ip == ':' || strchr(ip, ':') != NULL); //ipv6
|
||||
}
|
||||
|
||||
static inline const char *format_ip_address(const char *ip, char *buff)
|
||||
{
|
||||
if (is_ipv6_addr(ip))
|
||||
{
|
||||
sprintf(buff, "[%s]", ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(buff, ip);
|
||||
}
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
static inline const char *format_ip_port(const char *ip,
|
||||
const int port, char *buff)
|
||||
{
|
||||
if (is_ipv6_addr(ip))
|
||||
{
|
||||
sprintf(buff, "[%s]:%u", ip, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buff, "%s:%u", ip, port);
|
||||
}
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
void tcp_set_try_again_when_interrupt(const bool value);
|
||||
|
||||
static inline void tcp_dont_try_again_when_interrupt()
|
||||
|
|
|
|||
Loading…
Reference in New Issue