diff --git a/services/distributedfiledaemon/include/channel_manager/system_notifier.h b/services/distributedfiledaemon/include/channel_manager/system_notifier.h index f704e319fa5d82538eb7e642808b45fdb5191d66..75e88e42c4f03dbff4e570ea6c066335a58c8d88 100644 --- a/services/distributedfiledaemon/include/channel_manager/system_notifier.h +++ b/services/distributedfiledaemon/include/channel_manager/system_notifier.h @@ -40,7 +40,7 @@ public: int32_t CreateLocalLiveView(const std::string &networkId); int32_t CreateNotification(const std::string &networkId); - int32_t DestroyNotifyByNetworkId(const std::string &networkId); + int32_t DestroyNotifyByNetworkId(const std::string &networkId, bool needNotifyRemote = true); int32_t DestroyNotifyByNotificationId(int32_t notifyId); void ClearAllConnect(); int32_t GetNotificationMapSize(); diff --git a/services/distributedfiledaemon/include/network/session_pool.h b/services/distributedfiledaemon/include/network/session_pool.h index 852107276ae1138977261fe208995eeedae5f067..72b422a2a69a179efe2cd56af32dc0ef5f59f89e 100644 --- a/services/distributedfiledaemon/include/network/session_pool.h +++ b/services/distributedfiledaemon/include/network/session_pool.h @@ -36,7 +36,7 @@ public: void ReleaseSession(const int32_t fd); void ReleaseSession(const std::string &cid, bool isReleaseAll); void ReleaseAllSession(); - bool CheckIfGetSession(const int32_t fd); + bool CheckIfGetSession(const int32_t fd, bool &isServer); void SinkOffline(const std::string &cid); bool FindSocketId(int32_t socketId); private: diff --git a/services/distributedfiledaemon/src/channel_manager/channel_manager.cpp b/services/distributedfiledaemon/src/channel_manager/channel_manager.cpp index 854ad20fdaedea453955572d4f30e811878bdcb1..46fe0ee0089966270e8554bc631b5b6c9e5f6503 100644 --- a/services/distributedfiledaemon/src/channel_manager/channel_manager.cpp +++ b/services/distributedfiledaemon/src/channel_manager/channel_manager.cpp @@ -115,6 +115,7 @@ int32_t ChannelManager::Init() int32_t ret = Listen(socketServerId, g_low_qosInfo, g_lowQosTvParamIndex, &channelManagerListener); if (ret != ERR_OK) { LOGE("service listen failed, ret: %{public}d", ret); + Shutdown(socketServerId); return ERR_LISTEN_SOCKET_FAILED; } @@ -263,6 +264,7 @@ int32_t ChannelManager::CreateClientChannel(const std::string &networkId) } if (!SoftBusPermissionCheck::SetAccessInfoToSocket(socketId)) { LOGE("Fill and set accessInfo failed"); + Shutdown(socketId); return ERR_BAD_VALUE; } diff --git a/services/distributedfiledaemon/src/channel_manager/system_notifier.cpp b/services/distributedfiledaemon/src/channel_manager/system_notifier.cpp index a6224722887ae18d9b05a94f93c95021e98973e1..b08661565ff88fb41cdc1ecc536301c9c07956b2 100644 --- a/services/distributedfiledaemon/src/channel_manager/system_notifier.cpp +++ b/services/distributedfiledaemon/src/channel_manager/system_notifier.cpp @@ -249,7 +249,6 @@ void SystemNotifier::UpdateResourceMapByLanguage() template std::string SystemNotifier::GetKeyValue(const std::string &key, Args &&...args) { - std::lock_guard lock(g_resourceMapMutex); auto it = g_resourceMap.find(key); if (it == g_resourceMap.end()) { return ""; @@ -396,7 +395,7 @@ int32_t SystemNotifier::DestroyNotifyByNotificationId(int32_t notificationId) return ret; } -int32_t SystemNotifier::DestroyNotifyByNetworkId(const std::string &networkId) +int32_t SystemNotifier::DestroyNotifyByNetworkId(const std::string &networkId, bool needNotifyRemote) { LOGI("DestroyNotifyByNetworkId for networkId: %{public}.6s", networkId.c_str()); int32_t notificationId = 0; diff --git a/services/distributedfiledaemon/src/ipc/daemon_stub.cpp b/services/distributedfiledaemon/src/ipc/daemon_stub.cpp index 2fa662dbf4798b502abecbc8cd38b1315ea63d20..135dd40ca5c5752922a0f9f550287a0b2e55387b 100644 --- a/services/distributedfiledaemon/src/ipc/daemon_stub.cpp +++ b/services/distributedfiledaemon/src/ipc/daemon_stub.cpp @@ -186,9 +186,10 @@ int32_t DaemonStub::HandleOpenP2PConnectionEx(MessageParcel &data, MessageParcel return E_IPC_READ_FAILED; } auto remote = data.ReadRemoteObject(); - LOGW("is FileManager ? result is %{public}d", remote == nullptr); - auto remoteReverseObj = iface_cast(remote); + if (remoteReverseObj == nullptr) { + LOGW("nullptr pass, is FileManager situation!"); + } int32_t res = OpenP2PConnectionEx(networkId, remoteReverseObj); reply.WriteInt32(res); LOGI("DaemonStub::End OpenP2PConnection, res = %{public}d.", res); diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index 48467616614df99b036904c0a046e6c632545a10..89b463dbea9b9bdeba08efa9b16ee08940f0d4ce 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -181,15 +181,18 @@ void NetworkAgentTemplate::GetSessionProcessInner(NotifyParam param) string cidStr(param.remoteCid, CID_MAX_LEN); int fd = param.fd; LOGI("NOTIFY_GET_SESSION, old fd %{public}d, remote cid %{public}s", fd, Utils::GetAnonyString(cidStr).c_str()); - bool ifGetSession = sessionPool_.CheckIfGetSession(fd); + bool isServer = false; + bool ifGetSession = sessionPool_.CheckIfGetSession(fd, isServer); sessionPool_.ReleaseSession(fd); if (ifGetSession && ConnectCount::GetInstance()->CheckCount(cidStr)) { // for client GetSession(cidStr); } else { - // for server + // for server and client active close sessionPool_.SinkOffline(cidStr); - SystemNotifier::GetInstance().DestroyNotifyByNetworkId(cidStr); + } + if (isServer) { + SystemNotifier::GetInstance().DestroyNotifyByNetworkId(cidStr, false); } } diff --git a/services/distributedfiledaemon/src/network/session_pool.cpp b/services/distributedfiledaemon/src/network/session_pool.cpp index 76e6e715fed48232303032cc2e621709f7261227..08b41defe63de8f05c42331c28c4054cd542ad6c 100644 --- a/services/distributedfiledaemon/src/network/session_pool.cpp +++ b/services/distributedfiledaemon/src/network/session_pool.cpp @@ -48,7 +48,7 @@ void SessionPool::ReleaseSession(const int32_t fd) } } -bool SessionPool::CheckIfGetSession(const int32_t fd) +bool SessionPool::CheckIfGetSession(const int32_t fd, bool &isServer) { lock_guard lock(sessionPoolLock_); std::shared_ptr session = nullptr; @@ -59,8 +59,11 @@ bool SessionPool::CheckIfGetSession(const int32_t fd) } } if (session == nullptr) { + // client disconnect, server allconnect disconnect + isServer = false; return false; } + isServer = session->IsFromServer(); return !session->IsFromServer(); } diff --git a/services/distributedfiledaemon/test/unittest/channel_manager/control_cmd_parser_test.cpp b/services/distributedfiledaemon/test/unittest/channel_manager/control_cmd_parser_test.cpp index 685c90b5e5ff3213735844a3bc25f5e63b89635a..580651b9f2a79af798f59d7753695e7219feea56 100644 --- a/services/distributedfiledaemon/test/unittest/channel_manager/control_cmd_parser_test.cpp +++ b/services/distributedfiledaemon/test/unittest/channel_manager/control_cmd_parser_test.cpp @@ -38,7 +38,7 @@ int32_t SystemNotifier::CreateLocalLiveView(const std::string &networkId) return g_publishNotification; } -int32_t SystemNotifier::DestroyNotifyByNetworkId(const std::string &networkId) +int32_t SystemNotifier::DestroyNotifyByNetworkId(const std::string &networkId, bool needNotifyRemonte) { return g_cancelNotification; }