1
This commit is contained in:
1 parent
d3e211793c
commit
fd040176a0
1 file changed
+7
-6
@@ -382,7 +382,7 @@ int etcp_find_free_local_link_id(struct ETCP_CONN* etcp) {
|
||||
if (!etcp) return -1;
|
||||
|
||||
// Битовый массив для 256 id (32 байта * 8 бит = 256)
|
||||
uint8_t used_ids[32] = {0};
|
||||
uint8_t used_ids[32] = {1};// индекс 0 всегда занят
|
||||
|
||||
// Помечаем занятые id
|
||||
struct ETCP_LINK* link = etcp->links;
|
||||
@@ -567,7 +567,6 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "etcp_link_new: calloc failed - out of memory or pool exhausted");
|
||||
return NULL;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "NEW link: etcp=[%s] link=%p etcp=%p", etcp->log_name, link, etcp);
|
||||
|
||||
link->conn = conn;
|
||||
link->etcp = etcp;
|
||||
@@ -597,7 +596,7 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
|
||||
// Выделяем свободный local_link_id
|
||||
int free_id = etcp_find_free_local_link_id(etcp);
|
||||
if (free_id < 0) {
|
||||
if (free_id <= 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "etcp_link_new: no free local_link_id available");
|
||||
u_free(link);
|
||||
return NULL;
|
||||
@@ -605,7 +604,6 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
link->local_link_id = (uint8_t)free_id;
|
||||
|
||||
memcpy(&link->remote_addr, remote_addr, sizeof(struct sockaddr_storage));
|
||||
// link->last_activity = time(NULL);
|
||||
|
||||
link->ip_port_hash = sockaddr_hash(remote_addr);
|
||||
link->last_recv_local_time = get_time_tb(); // Initialize to prevent immediate timeout
|
||||
@@ -631,6 +629,7 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
if (insert_link(conn, link) < 0) {
|
||||
// откатываем то, что успели
|
||||
// (пока список ещё не добавлен — просто free)
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "Can not insert link to socket");
|
||||
u_free(link);
|
||||
return NULL;
|
||||
}
|
||||
@@ -639,11 +638,13 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
while (l && l->next) l=l->next;
|
||||
if (l) l->next = link; else etcp->links = link;
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "NEW link initialized on etcp=[%s] link=%p socket=%s id=%d is_server=%d mtu=%d", etcp->log_name, link, conn->name, link->local_link_id, link->is_server, link->mtu);
|
||||
|
||||
if (is_server == 0) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "etcp_link_new: client link, calling etcp_link_send_init");
|
||||
etcp_link_enter_init(link);
|
||||
}
|
||||
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
@@ -942,7 +943,7 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
conn->peer_node_id=peer_id;
|
||||
etcp_update_log_name(conn); // Update log_name with peer_node_id
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "New connection from %s peer_id=%ld etcp=%p",
|
||||
ip_to_str(&addr, addr.ss_family).str, peer_id, conn);
|
||||
ip_to_str(&((struct sockaddr_in *)&addr)->sin_addr.s_addr, addr.ss_family).str, peer_id, conn);
|
||||
// Add connection to instance list
|
||||
conn->next = e_sock->instance->connections;
|
||||
e_sock->instance->connections = conn;
|
||||
|
||||
Reference in new issue
Block a user