mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-12-24 02:25:59 +00:00
!5012 fix: fix session num exceed limit on udp channel
Merge pull request !5012 from xuxiaoqing/master
This commit is contained in:
commit
7ea6d13fb7
@ -172,6 +172,8 @@ int32_t ClientGetSessionCallbackAdapterByName(const char *sessionName, SessionLi
|
||||
int32_t ClientGetSessionCallbackAdapterById(int32_t sessionId, SessionListenerAdapter *callbackAdapter);
|
||||
|
||||
int32_t ClientGetPeerSocketInfoById(int32_t sessionId, PeerSocketInfo *peerSocketInfo);
|
||||
|
||||
bool IsSessionExceedLimit();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1913,4 +1913,19 @@ int32_t ClientGetPeerSocketInfoById(int32_t sessionId, PeerSocketInfo *peerSocke
|
||||
peerSocketInfo->dataType = (TransDataType)sessionNode->info.flag;
|
||||
(void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
bool IsSessionExceedLimit()
|
||||
{
|
||||
if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
|
||||
TRANS_LOGE(TRANS_SDK, "lock failed");
|
||||
return true;
|
||||
}
|
||||
if (g_sessionIdNum >= MAX_SESSION_ID) {
|
||||
(void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
|
||||
TRANS_LOGE(TRANS_SDK, "sessionId num exceed limit.");
|
||||
return true;
|
||||
}
|
||||
(void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
|
||||
return false;
|
||||
}
|
@ -16,8 +16,9 @@
|
||||
#include "string.h"
|
||||
#include "anonymizer.h"
|
||||
#include "client_trans_session_adapter.h"
|
||||
#include "socket.h"
|
||||
#include "client_trans_session_manager.h"
|
||||
#include "inner_socket.h"
|
||||
#include "socket.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_error_code.h"
|
||||
@ -102,6 +103,9 @@ int32_t Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISock
|
||||
int32_t Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener *listener)
|
||||
{
|
||||
TRANS_LOGI(TRANS_SDK, "Bind: socket=%d", socket);
|
||||
if (IsSessionExceedLimit()) {
|
||||
return SOFTBUS_TRANS_SESSION_CNT_EXCEEDS_LIMIT;
|
||||
}
|
||||
return ClientBind(socket, qos, qosCount, listener);
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,9 @@ int32_t TransOnChannelOpened(const char *sessionName, const ChannelInfo *channel
|
||||
TRANS_LOGW(TRANS_SDK, "[client] invalid param.");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (IsSessionExceedLimit()) {
|
||||
return SOFTBUS_TRANS_SESSION_CNT_EXCEEDS_LIMIT;
|
||||
}
|
||||
|
||||
int32_t ret = SOFTBUS_ERR;
|
||||
int32_t udpPort = 0;
|
||||
|
@ -31,7 +31,7 @@ typedef struct {
|
||||
const StreamFrameInfo *param);
|
||||
int32_t (*OnFileGetSessionId)(int32_t channelId, int32_t *sessionId);
|
||||
void (*OnMessageReceived)(void);
|
||||
void (*OnUdpChannelOpened)(int32_t channelId);
|
||||
int32_t (*OnUdpChannelOpened)(int32_t channelId);
|
||||
void (*OnUdpChannelClosed)(int32_t channelId, ShutdownReason reason);
|
||||
void (*OnQosEvent)(int channelId, int eventId, int tvCount, const QosTv *tvList);
|
||||
} UdpChannelMgrCb;
|
||||
|
@ -148,20 +148,22 @@ static int32_t TransSetUdpChannelEnable(int32_t channelId, bool isEnable)
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
static void OnUdpChannelOpened(int32_t channelId)
|
||||
static int32_t OnUdpChannelOpened(int32_t channelId)
|
||||
{
|
||||
UdpChannel channel;
|
||||
if (memset_s(&channel, sizeof(UdpChannel), 0, sizeof(UdpChannel)) != EOK) {
|
||||
TRANS_LOGE(TRANS_SDK, "on udp channel opened memset failed.");
|
||||
return;
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (TransGetUdpChannel(channelId, &channel) != SOFTBUS_OK) {
|
||||
int ret = TransGetUdpChannel(channelId, &channel);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "get udp channelId=%d failed.", channelId);
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
if (TransSetUdpChannelEnable(channelId, true) != SOFTBUS_OK) {
|
||||
ret = TransSetUdpChannelEnable(channelId, true);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "set udp channelId=%d enable failed.", channelId);
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
SessionType type = TYPE_BUTT;
|
||||
switch (channel.businessType) {
|
||||
@ -173,7 +175,7 @@ static void OnUdpChannelOpened(int32_t channelId)
|
||||
break;
|
||||
default:
|
||||
TRANS_LOGE(TRANS_SDK, "unsupport businessType=%d.", channel.businessType);
|
||||
return;
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
ChannelInfo info = {0};
|
||||
info.channelId = channel.channelId;
|
||||
@ -187,8 +189,9 @@ static void OnUdpChannelOpened(int32_t channelId)
|
||||
info.routeType = channel.routeType;
|
||||
info.businessType = channel.businessType;
|
||||
if ((g_sessionCb != NULL) && (g_sessionCb->OnSessionOpened != NULL)) {
|
||||
g_sessionCb->OnSessionOpened(channel.info.mySessionName, &info, type);
|
||||
return g_sessionCb->OnSessionOpened(channel.info.mySessionName, &info, type);
|
||||
}
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
static UdpChannel *ConvertChannelInfoToUdpChannel(const char *sessionName, const ChannelInfo *channel)
|
||||
|
@ -314,9 +314,16 @@ int32_t TransOnFileChannelOpened(const char *sessionName, const ChannelInfo *cha
|
||||
TRANS_LOGE(TRANS_FILE, "start file channel as server failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_udpChannelMgrCb->OnUdpChannelOpened(channel->channelId);
|
||||
if (g_udpChannelMgrCb->OnUdpChannelOpened(channel->channelId) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_FILE, "udp channel open failed.");
|
||||
NSTACKX_DFileClose(fileSession);
|
||||
*filePort = 0;
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (UpdateFileRecvPath(channel->channelId, &fileListener, fileSession)) {
|
||||
TRANS_LOGE(TRANS_FILE, "update receive file path failed");
|
||||
NSTACKX_DFileClose(fileSession);
|
||||
*filePort = 0;
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user