mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2025-02-21 11:41:18 +00:00
!9065 bug:record conn fd to free
Merge pull request !9065 from 宋晨曦/master
This commit is contained in:
commit
b52de3e9fa
@ -59,6 +59,10 @@ int32_t StartSocketListening(ListenerModule module, const LocalListenerInfo *inf
|
||||
void StopSocketListening(ListenerModule moduleId);
|
||||
|
||||
int32_t AuthSetTcpKeepaliveOption(int32_t fd, ModeCycle cycle);
|
||||
bool IsExistWifiConnItemByConnId(int32_t fd);
|
||||
void DeleteWifiConnItemByConnId(int32_t fd);
|
||||
int32_t WifiConnListLockInit(void);
|
||||
void WifiConnListLockDeinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -643,6 +643,11 @@ int32_t AuthConnInit(const AuthConnListener *listener)
|
||||
AUTH_LOGE(AUTH_CONN, "init br/ble/p2p conn fail");
|
||||
return SOFTBUS_AUTH_CONN_INIT_FAIL;
|
||||
}
|
||||
if (WifiConnListLockInit() != SOFTBUS_OK) {
|
||||
(void)memset_s(&g_listener, sizeof(g_listener), 0, sizeof(AuthConnListener));
|
||||
AUTH_LOGE(AUTH_CONN, "init WifiConnListLock fail");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (InitWiFiConn() != SOFTBUS_OK) {
|
||||
(void)memset_s(&g_listener, sizeof(g_listener), 0, sizeof(AuthConnListener));
|
||||
AUTH_LOGE(AUTH_CONN, "init wifi conn fail");
|
||||
@ -656,6 +661,7 @@ void AuthConnDeinit(void)
|
||||
UnsetSocketCallback();
|
||||
ConnUnSetConnectCallback(MODULE_DEVICE_AUTH);
|
||||
ClearConnRequest();
|
||||
WifiConnListLockDeinit();
|
||||
(void)memset_s(&g_listener, sizeof(g_listener), 0, sizeof(AuthConnListener));
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,9 @@
|
||||
#include "lnn_feature_capability.h"
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_base_listener.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_socket.h"
|
||||
|
||||
#define AUTH_TIMEOUT_MS (10 * 1000)
|
||||
#define TO_AUTH_FSM(ptr) CONTAINER_OF(ptr, AuthFsm, fsm)
|
||||
@ -1560,6 +1562,7 @@ int32_t AuthSessionStartAuth(const AuthParam *authParam, const AuthConnInfo *con
|
||||
ReleaseAuthLock();
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
DeleteWifiConnItemByConnId(GetConnId(authParam->connId));
|
||||
authFsm->info.isNeedFastAuth = authParam->isFastAuth;
|
||||
(void)UpdateLocalAuthState(authFsm->authSeq, &authFsm->info);
|
||||
AuthFsmStateIndex nextState = STATE_SYNC_DEVICE_ID;
|
||||
@ -1728,6 +1731,7 @@ int32_t AuthSessionHandleDeviceDisconnected(uint64_t connId, bool isNeedDisconne
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
AuthFsm *item = NULL;
|
||||
bool isDisconnected = false;
|
||||
LIST_FOR_EACH_ENTRY(item, &g_authFsmList, AuthFsm, node) {
|
||||
if (item->info.connId != connId) {
|
||||
continue;
|
||||
@ -1740,6 +1744,7 @@ int32_t AuthSessionHandleDeviceDisconnected(uint64_t connId, bool isNeedDisconne
|
||||
GetConnType(item->info.connId) == AUTH_LINK_TYPE_P2P)) {
|
||||
if (isNeedDisconnect) {
|
||||
DisconnectAuthDevice(&item->info.connId);
|
||||
isDisconnected = true;
|
||||
} else {
|
||||
UpdateFd(&item->info.connId, AUTH_INVALID_FD);
|
||||
}
|
||||
@ -1747,6 +1752,11 @@ int32_t AuthSessionHandleDeviceDisconnected(uint64_t connId, bool isNeedDisconne
|
||||
LnnFsmPostMessage(&item->fsm, FSM_MSG_DEVICE_DISCONNECTED, NULL);
|
||||
}
|
||||
ReleaseAuthLock();
|
||||
if (isNeedDisconnect && !isDisconnected && GetConnType(connId) == AUTH_LINK_TYPE_WIFI &&
|
||||
IsExistWifiConnItemByConnId(GetConnId(connId))) {
|
||||
DeleteWifiConnItemByConnId(GetConnId(connId));
|
||||
DisconnectAuthDevice(&connId);
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,8 @@ static InnerChannelListener g_listener[] = {
|
||||
};
|
||||
|
||||
static SocketCallback g_callback = { NULL, NULL, NULL };
|
||||
static ListNode g_wifiConnList = { &g_wifiConnList, &g_wifiConnList };
|
||||
static SoftBusMutex g_wifiConnListLock;
|
||||
|
||||
static void NotifyChannelDisconnected(int32_t channelId);
|
||||
static void NotifyChannelDataReceived(int32_t channelId, const SocketPktHead *head, const uint8_t *data);
|
||||
@ -228,6 +230,84 @@ static uint8_t *RecvPacketData(int32_t fd, uint32_t len)
|
||||
return data;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ListNode node;
|
||||
int32_t fd;
|
||||
} WifiConnInstance;
|
||||
|
||||
static bool RequireWifiConnListLock(void)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_wifiConnListLock) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "wifiConnList lock fail");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ReleaseWifiConnListLock(void)
|
||||
{
|
||||
if (SoftBusMutexUnlock(&g_wifiConnListLock) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "wifiConnList unlock fail");
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t AddWifiConnItem(int32_t fd)
|
||||
{
|
||||
if (!RequireWifiConnListLock()) {
|
||||
AUTH_LOGE(AUTH_CONN, "RequireWifiConnListLock fail");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
WifiConnInstance *connItem = (WifiConnInstance *)SoftBusCalloc(sizeof(WifiConnInstance));
|
||||
if (connItem == NULL) {
|
||||
AUTH_LOGE(AUTH_CONN, "malloc connItem fail");
|
||||
ReleaseWifiConnListLock();
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
connItem->fd = fd;
|
||||
ListNodeInsert(&g_wifiConnList, &connItem->node);
|
||||
AUTH_LOGI(AUTH_CONN, "add wifi conn item. fd=%{public}d", fd);
|
||||
ReleaseWifiConnListLock();
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
bool IsExistWifiConnItemByConnId(int32_t fd)
|
||||
{
|
||||
if (!RequireWifiConnListLock()) {
|
||||
AUTH_LOGE(AUTH_CONN, "RequireWifiConnListLock fail");
|
||||
return false;
|
||||
}
|
||||
WifiConnInstance *item = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, &g_wifiConnList, WifiConnInstance, node) {
|
||||
if (item->fd != fd) {
|
||||
continue;
|
||||
}
|
||||
ReleaseWifiConnListLock();
|
||||
return true;
|
||||
}
|
||||
AUTH_LOGE(AUTH_CONN, "wifi conn item is not found. fd=%{public}d", fd);
|
||||
ReleaseWifiConnListLock();
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeleteWifiConnItemByConnId(int32_t fd)
|
||||
{
|
||||
if (!RequireWifiConnListLock()) {
|
||||
AUTH_LOGE(AUTH_CONN, "RequireWifiConnListLock fail");
|
||||
return;
|
||||
}
|
||||
WifiConnInstance *item = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, &g_wifiConnList, WifiConnInstance, node) {
|
||||
if (item->fd != fd) {
|
||||
continue;
|
||||
}
|
||||
AUTH_LOGI(AUTH_CONN, "delete wifi conn item. fd=%{public}d", fd);
|
||||
ListDelete(&item->node);
|
||||
SoftBusFree(item);
|
||||
break;
|
||||
}
|
||||
ReleaseWifiConnListLock();
|
||||
}
|
||||
|
||||
static int32_t ProcessSocketOutEvent(ListenerModule module, int32_t fd)
|
||||
{
|
||||
AUTH_LOGI(AUTH_CONN, "socket client connect succ: fd=%{public}d.", fd);
|
||||
@ -240,6 +320,10 @@ static int32_t ProcessSocketOutEvent(ListenerModule module, int32_t fd)
|
||||
AUTH_LOGE(AUTH_CONN, "set none block mode fail.");
|
||||
goto FAIL;
|
||||
}
|
||||
if (AddWifiConnItem(fd) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "insert wifi conn item fail.");
|
||||
goto FAIL;
|
||||
}
|
||||
NotifyConnected(module, fd, true);
|
||||
return SOFTBUS_OK;
|
||||
|
||||
@ -321,6 +405,10 @@ static int32_t OnConnectEvent(ListenerModule module, int32_t cfd, const ConnectO
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (module == AUTH && AddWifiConnItem(cfd) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "insert wifi conn item fail.");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
NotifyConnected(module, cfd, false);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
@ -756,4 +844,20 @@ int32_t AuthSetTcpKeepaliveOption(int32_t fd, ModeCycle cycle)
|
||||
fd, tcpKeepaliveOption.keepaliveIdle, tcpKeepaliveOption.keepaliveIntvl, tcpKeepaliveOption.keepaliveCount,
|
||||
tcpKeepaliveOption.userTimeout);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t WifiConnListLockInit(void)
|
||||
{
|
||||
if (SoftBusMutexInit(&g_wifiConnListLock, NULL) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "wifiConnList mutex init fail");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void WifiConnListLockDeinit(void)
|
||||
{
|
||||
if (SoftBusMutexDestroy(&g_wifiConnListLock) != SOFTBUS_OK) {
|
||||
AUTH_LOGE(AUTH_CONN, "wifiConnList mutex destroy fail");
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "auth_channel.h"
|
||||
#include "auth_meta_manager.h"
|
||||
#include "auth_tcp_connection.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "common_list.h"
|
||||
#include "lnn_connection_addr_utils.h"
|
||||
@ -779,6 +780,7 @@ static int32_t AddAuthChannelInfo(AuthChannelInfo *info)
|
||||
TRANS_LOGE(TRANS_SVC, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
DeleteWifiConnItemByConnId(info->authId);
|
||||
if (SoftBusMutexLock(&g_authChannelList->lock) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SVC, "fail to lock authChannelList.");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
|
Loading…
x
Reference in New Issue
Block a user