change return type of format_ip_address and format_ip_port
parent
1edcae9cf4
commit
79cd21f667
3
HISTORY
3
HISTORY
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
Version 1.86 2026-06-25
|
Version 1.86 2026-06-26
|
||||||
* add function fc_parse_version
|
* add function fc_parse_version
|
||||||
|
* change return type of format_ip_address and format_ip_port
|
||||||
|
|
||||||
Version 1.85 2026-06-23
|
Version 1.85 2026-06-23
|
||||||
* add functions fc_safe_srand and fc_safe_rand for more security under Linux
|
* add functions fc_safe_srand and fc_safe_rand for more security under Linux
|
||||||
|
|
|
||||||
|
|
@ -140,26 +140,27 @@ static int fast_multi_sock_client_do_send(FastMultiSockClient *client,
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
break;
|
break;
|
||||||
} else if (errno == EINTR) { //should retry
|
} else if (errno == EINTR) { //should retry
|
||||||
|
format_ip_address(entry->conn->ip_addr, formatted_ip);
|
||||||
logDebug("file: "__FILE__", line: %d, "
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"server: %s:%u, ignore interupt signal", __LINE__,
|
"server: %s:%u, ignore interupt signal", __LINE__,
|
||||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
formatted_ip, entry->conn->port);
|
||||||
entry->conn->port);
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
result = errno != 0 ? errno : ECONNRESET;
|
result = errno != 0 ? errno : ECONNRESET;
|
||||||
|
format_ip_address(entry->conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"send to server %s:%u fail, "
|
"send to server %s:%u fail, "
|
||||||
"errno: %d, error info: %s", __LINE__,
|
"errno: %d, error info: %s", __LINE__,
|
||||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
formatted_ip, entry->conn->port,
|
||||||
entry->conn->port, result, strerror(result));
|
result, strerror(result));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (bytes == 0) {
|
} else if (bytes == 0) {
|
||||||
|
format_ip_address(entry->conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"send to server %s:%u, sock: %d fail, "
|
"send to server %s:%u, sock: %d fail, "
|
||||||
"connection disconnected", __LINE__,
|
"connection disconnected", __LINE__, formatted_ip,
|
||||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
|
||||||
entry->conn->port, entry->conn->sock);
|
entry->conn->port, entry->conn->sock);
|
||||||
|
|
||||||
result = ECONNRESET;
|
result = ECONNRESET;
|
||||||
|
|
@ -203,10 +204,10 @@ static int fast_multi_sock_client_send_data(FastMultiSockClient *client,
|
||||||
if (client->entries[i].conn->sock < 0) {
|
if (client->entries[i].conn->sock < 0) {
|
||||||
client->entries[i].error_no = ENOTCONN;
|
client->entries[i].error_no = ENOTCONN;
|
||||||
client->entries[i].done = true;
|
client->entries[i].done = true;
|
||||||
|
format_ip_address(client->entries[i].conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"NOT connected to %s:%u", __LINE__,
|
"NOT connected to %s:%u", __LINE__,
|
||||||
format_ip_address(client->entries[i].conn->ip_addr,
|
formatted_ip, client->entries[i].conn->port);
|
||||||
formatted_ip), client->entries[i].conn->port);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,26 +257,27 @@ static int fast_multi_sock_client_do_recv(FastMultiSockClient *client,
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
break;
|
break;
|
||||||
} else if (errno == EINTR) { //should retry
|
} else if (errno == EINTR) { //should retry
|
||||||
|
format_ip_address(entry->conn->ip_addr, formatted_ip);
|
||||||
logDebug("file: "__FILE__", line: %d, "
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"server: %s:%u, ignore interupt signal", __LINE__,
|
"server: %s:%u, ignore interupt signal", __LINE__,
|
||||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
formatted_ip, entry->conn->port);
|
||||||
entry->conn->port);
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
result = errno != 0 ? errno : ECONNRESET;
|
result = errno != 0 ? errno : ECONNRESET;
|
||||||
|
format_ip_address(entry->conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"server: %s:%u, recv failed, "
|
"server: %s:%u, recv failed, "
|
||||||
"errno: %d, error info: %s", __LINE__,
|
"errno: %d, error info: %s", __LINE__,
|
||||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
formatted_ip, entry->conn->port,
|
||||||
entry->conn->port, result, strerror(result));
|
result, strerror(result));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (bytes == 0) {
|
} else if (bytes == 0) {
|
||||||
|
format_ip_address(entry->conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"server: %s:%u, sock: %d, recv failed, "
|
"server: %s:%u, sock: %d, recv failed, "
|
||||||
"connection disconnected", __LINE__,
|
"connection disconnected", __LINE__, formatted_ip,
|
||||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
|
||||||
entry->conn->port, entry->conn->sock);
|
entry->conn->port, entry->conn->sock);
|
||||||
|
|
||||||
result = ECONNRESET;
|
result = ECONNRESET;
|
||||||
|
|
@ -290,10 +292,10 @@ static int fast_multi_sock_client_do_recv(FastMultiSockClient *client,
|
||||||
entry->recv_stage = fms_stage_recv_body;
|
entry->recv_stage = fms_stage_recv_body;
|
||||||
body_length = client->get_body_length_func(&entry->recv_buffer);
|
body_length = client->get_body_length_func(&entry->recv_buffer);
|
||||||
if (body_length < 0) {
|
if (body_length < 0) {
|
||||||
|
format_ip_address(entry->conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"server: %s:%u, body_length: %d < 0", __LINE__,
|
"server: %s:%u, body_length: %d < 0", __LINE__,
|
||||||
format_ip_address(entry->conn->ip_addr, formatted_ip),
|
formatted_ip, entry->conn->port, body_length);
|
||||||
entry->conn->port, body_length);
|
|
||||||
result = EPIPE;
|
result = EPIPE;
|
||||||
break;
|
break;
|
||||||
} else if (body_length == 0) {
|
} else if (body_length == 0) {
|
||||||
|
|
@ -374,10 +376,10 @@ static int fast_multi_sock_client_deal_io(FastMultiSockClient *client)
|
||||||
&client->ioevent, index);
|
&client->ioevent, index);
|
||||||
|
|
||||||
if (event & IOEVENT_ERROR) {
|
if (event & IOEVENT_ERROR) {
|
||||||
|
format_ip_address(entry->conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"server: %s:%u, recv error event: %d, connection "
|
"server: %s:%u, recv error event: %d, connection reset",
|
||||||
"reset", __LINE__, format_ip_address(entry->conn->
|
__LINE__, formatted_ip, entry->conn->port, event);
|
||||||
ip_addr, formatted_ip), entry->conn->port, event);
|
|
||||||
|
|
||||||
fast_multi_sock_client_finish(client, entry, ECONNRESET);
|
fast_multi_sock_client_finish(client, entry, ECONNRESET);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -404,10 +406,10 @@ static int fast_multi_sock_client_deal_io(FastMultiSockClient *client)
|
||||||
if (!client->entries[i].done) {
|
if (!client->entries[i].done) {
|
||||||
fast_multi_sock_client_finish(client,
|
fast_multi_sock_client_finish(client,
|
||||||
client->entries + i, ETIMEDOUT);
|
client->entries + i, ETIMEDOUT);
|
||||||
|
format_ip_address(client->entries[i].conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"recv from %s:%u timedout", __LINE__,
|
"recv from %s:%u timedout", __LINE__,
|
||||||
format_ip_address(client->entries[i].conn->ip_addr,
|
formatted_ip, client->entries[i].conn->port);
|
||||||
formatted_ip), client->entries[i].conn->port);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -259,11 +259,11 @@ static int fc_server_check_ip_port(FCServerConfig *ctx,
|
||||||
id1 = current->server->id;
|
id1 = current->server->id;
|
||||||
id2 = previous->server->id;
|
id2 = previous->server->id;
|
||||||
}
|
}
|
||||||
|
format_ip_address(previous->ip_addr.str, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"config file: %s, duplicate ip:port %s:%u, "
|
"config file: %s, duplicate ip:port %s:%u, "
|
||||||
"the server ids: %d, %d", __LINE__,
|
"the server ids: %d, %d", __LINE__, config_filename,
|
||||||
config_filename, format_ip_address(previous->ip_addr.str,
|
formatted_ip, previous->port, id1, id2);
|
||||||
formatted_ip), previous->port, id1, id2);
|
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -714,14 +714,14 @@ static int check_addresses_duplicate(FCServerConfig *ctx,
|
||||||
ppend = group_addr->address_array.addrs + group_addr->address_array.count;
|
ppend = group_addr->address_array.addrs + group_addr->address_array.count;
|
||||||
for (ppaddr=group_addr->address_array.addrs+1; ppaddr<ppend; ppaddr++) {
|
for (ppaddr=group_addr->address_array.addrs+1; ppaddr<ppend; ppaddr++) {
|
||||||
if (fc_server_cmp_address_ptr(ppaddr, pprevious) == 0) {
|
if (fc_server_cmp_address_ptr(ppaddr, pprevious) == 0) {
|
||||||
|
format_ip_address((*ppaddr)->conn.ip_addr, formatted_ip),
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"config filename: %s, section: %s, group: %.*s, "
|
"config filename: %s, section: %s, group: %.*s, "
|
||||||
"duplicate ip and port: %s:%u", __LINE__,
|
"duplicate ip and port: %s:%u", __LINE__,
|
||||||
config_filename, section_name,
|
config_filename, section_name,
|
||||||
group_addr->server_group->group_name.len,
|
group_addr->server_group->group_name.len,
|
||||||
group_addr->server_group->group_name.str,
|
group_addr->server_group->group_name.str,
|
||||||
format_ip_address((*ppaddr)->conn.ip_addr, formatted_ip),
|
formatted_ip, (*ppaddr)->conn.port);
|
||||||
(*ppaddr)->conn.port);
|
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
}
|
}
|
||||||
pprevious = ppaddr;
|
pprevious = ppaddr;
|
||||||
|
|
@ -967,12 +967,12 @@ static int fc_server_set_host(FCServerConfig *ctx, FCServerInfo *server,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->share_between_groups && (count > 1 && addr->conn.port > 0)) {
|
if (!ctx->share_between_groups && (count > 1 && addr->conn.port > 0)) {
|
||||||
|
format_ip_address(addr->conn.ip_addr, formatted_ip),
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"config filename: %s, section: %s, "
|
"config filename: %s, section: %s, "
|
||||||
"host %s:%u belongs to %d groups",
|
"host %s:%u belongs to %d groups",
|
||||||
__LINE__, config_filename, section_name,
|
__LINE__, config_filename, section_name,
|
||||||
format_ip_address(addr->conn.ip_addr, formatted_ip),
|
formatted_ip, addr->conn.port, count);
|
||||||
addr->conn.port, count);
|
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1544,9 +1544,10 @@ static void fc_group_servers_to_string(FCServerConfig *ctx,
|
||||||
gaddr->server_group->group_name.str,
|
gaddr->server_group->group_name.str,
|
||||||
SERVER_ITEM_HOST_AFFIX_STR);
|
SERVER_ITEM_HOST_AFFIX_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
format_ip_address((*addr)->conn.ip_addr, formatted_ip),
|
||||||
fast_buffer_append(buffer, " = %s:%u\n",
|
fast_buffer_append(buffer, " = %s:%u\n",
|
||||||
format_ip_address((*addr)->conn.ip_addr, formatted_ip),
|
formatted_ip, (*addr)->conn.port);
|
||||||
(*addr)->conn.port);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1655,9 +1656,9 @@ static void fc_server_log_group_servers(FCGroupAddresses *gaddr)
|
||||||
|
|
||||||
end = gaddr->address_array.addrs + gaddr->address_array.count;
|
end = gaddr->address_array.addrs + gaddr->address_array.count;
|
||||||
for (addr=gaddr->address_array.addrs; addr<end; addr++) {
|
for (addr=gaddr->address_array.addrs; addr<end; addr++) {
|
||||||
|
format_ip_address((*addr)->conn.ip_addr, formatted_ip),
|
||||||
logInfo(" %d. %s:%u", (int)(addr - gaddr->address_array.addrs + 1),
|
logInfo(" %d. %s:%u", (int)(addr - gaddr->address_array.addrs + 1),
|
||||||
format_ip_address((*addr)->conn.ip_addr, formatted_ip),
|
formatted_ip, (*addr)->conn.port);
|
||||||
(*addr)->conn.port);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -706,11 +706,11 @@ static inline bool is_ipv6_addr(const char *ip)
|
||||||
return (*ip == ':' || strchr(ip, ':') != NULL); //ipv6
|
return (*ip == ':' || strchr(ip, ':') != NULL); //ipv6
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline const char *format_ip_address(const char *ip, char *buff)
|
static inline int format_ip_address(const char *ip, char *buff)
|
||||||
{
|
{
|
||||||
|
int ip_len;
|
||||||
if (is_ipv6_addr(ip))
|
if (is_ipv6_addr(ip))
|
||||||
{
|
{
|
||||||
int ip_len;
|
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
ip_len = strlen(ip);
|
ip_len = strlen(ip);
|
||||||
|
|
@ -720,17 +720,17 @@ static inline const char *format_ip_address(const char *ip, char *buff)
|
||||||
p += ip_len;
|
p += ip_len;
|
||||||
*p++ = ']';
|
*p++ = ']';
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
return p - buff;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(buff, ip);
|
ip_len = strlen(ip);
|
||||||
|
memcpy(buff, ip, ip_len + 1);
|
||||||
|
return ip_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
return buff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline const char *format_ip_port(const char *ip,
|
static inline int format_ip_port(const char *ip, const int port, char *buff)
|
||||||
const int port, char *buff)
|
|
||||||
{
|
{
|
||||||
int ip_len;
|
int ip_len;
|
||||||
bool is_ipv6;
|
bool is_ipv6;
|
||||||
|
|
@ -753,7 +753,7 @@ static inline const char *format_ip_port(const char *ip,
|
||||||
p += fc_itoa(port, p);
|
p += fc_itoa(port, p);
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
return buff;
|
return p - buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tcp_set_try_again_when_interrupt(const bool value);
|
void tcp_set_try_again_when_interrupt(const bool value);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue