提交 e1a660f6 编写于 作者: L liangshenglin1 提交者: Gitee

fix bug of connectAbility timeout

Signed-off-by: Nliangshenglin <liangshenglin1@huawei.com>
上级 fc8fa9f1
......@@ -70,7 +70,7 @@ public:
std::string GetDataBusName();
int GetProto() const;
void WaitForInit(bool newProxy);
void WaitForInit();
std::u16string GetInterfaceDescriptor();
private:
......
......@@ -98,6 +98,7 @@ public:
bool AttachObject(IRemoteObject *object);
bool AttachObjectInner(IRemoteObject *object);
bool DetachObject(IRemoteObject *object);
bool DetachObjectInner(IRemoteObject *object);
bool OnThreadTerminated(const std::string &threadName);
......@@ -207,6 +208,7 @@ private:
std::map<uint32_t, std::shared_ptr<InvokerRawData>> rawData_;
IPCWorkThreadPool *threadPool_ = nullptr;
sptr<IRemoteObject> registryObject_ = nullptr;
friend void IPCObjectProxy::OnLastStrongRef(const void *objectId);
#ifndef CONFIG_IPC_SINGLE
std::mutex databusProcMutex_;
......
......@@ -164,7 +164,7 @@ void IPCObjectProxy::OnFirstStrongRef(const void *objectId)
}
}
void IPCObjectProxy::WaitForInit(bool newProxy)
void IPCObjectProxy::WaitForInit()
{
#ifndef CONFIG_IPC_SINGLE
int type = 0;
......@@ -172,7 +172,7 @@ void IPCObjectProxy::WaitForInit(bool newProxy)
{
std::lock_guard<std::mutex> lockGuard(initMutex_);
if (IsObjectDead()) {
ZLOGI(LABEL, "check a dead proxy, init again");
ZLOGW(LABEL, "check a dead proxy, init again");
isRemoteDead_ = false;
isFinishInit_ = false;
}
......@@ -182,9 +182,6 @@ void IPCObjectProxy::WaitForInit(bool newProxy)
return;
}
#ifndef CONFIG_IPC_SINGLE
if (newProxy == true) {
ReleaseProto();
}
type = UpdateProto();
#endif
isFinishInit_ = true;
......@@ -203,15 +200,24 @@ void IPCObjectProxy::OnLastStrongRef(const void *objectId)
ZLOGE(LABEL, "OnLastStrongRef current is null");
return;
}
if (current->DetachObject(this)) { // if detach successfully, this proxy will be destroyed
#ifndef CONFIG_IPC_SINGLE
ReleaseProto();
std::shared_ptr<DBinderSessionObject> session = nullptr;
#endif
IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker();
if (invoker != nullptr) {
invoker->ReleaseHandle(handle_);
{
std::lock_guard<std::recursive_mutex> lock(current->mutex_);
if (current->DetachObjectInner(this) == false) { // if detach successfully, this proxy will be destroyed
return;
}
#ifndef CONFIG_IPC_SINGLE
ReleaseProto();
session = current->ProxyQueryDBinderSession(handle_);
(void)current->ProxyDetachDBinderSession(handle_);
(void)current->DetachHandleToIndex(handle_);
#endif
}
IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker();
if (invoker != nullptr) {
invoker->ReleaseHandle(handle_);
}
}
......@@ -231,7 +237,7 @@ bool IPCObjectProxy::AddDeathRecipient(const sptr<DeathRecipient> &recipient)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (IsObjectDead()) {
ZLOGI(LABEL, "%s: proxy is already dead", __func__);
ZLOGW(LABEL, "%s: proxy is already dead", __func__);
return false;
}
......@@ -269,9 +275,9 @@ bool IPCObjectProxy::AddDeathRecipient(const sptr<DeathRecipient> &recipient)
#ifndef CONFIG_IPC_SINGLE
if (proto_ == IRemoteObject::IF_PROT_DATABUS) {
status = AddDbinderDeathRecipient();
ZLOGE(LABEL, "%s: fail to add dbinder death recipient, status = %d", __func__, status);
#ifndef BUILD_PUBLIC_VERSION
if (!status) {
ZLOGE(LABEL, "failed to add dbinder death recipient");
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, DbinderErrorCode::ERROR_TYPE,
DbinderErrorCode::RPC_DRIVER, DbinderErrorCode::ERROR_CODE,
DbinderErrorCode::SET_DEATH_RECIPIENT_FAILURE);
......@@ -593,8 +599,8 @@ void IPCObjectProxy::ReleaseDatabusProto()
return;
}
if (GetProto() != IRemoteObject::IF_PROT_DATABUS) {
ZLOGI(LABEL, "not databus dbinder, need do nothing");
if (proto_ != IRemoteObject::IF_PROT_DATABUS) {
ZLOGW(LABEL, "not databus dbinder, need do nothing");
return;
}
......@@ -602,19 +608,9 @@ void IPCObjectProxy::ReleaseDatabusProto()
MessageOption option = { MessageOption::TF_ASYNC };
uint32_t err = SendRequestInner(false, DBINDER_DECREFS_TRANSACTION, data, reply, option);
if (err != ERR_NONE) {
ZLOGE(LABEL, "DBINDER_DECREFS_TRANSACTION transact return error = %{public}u", err);
ZLOGW(LABEL, "DBINDER_DECREFS_TRANSACTION transact return error = %{public}u", err);
// do nothing
}
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
if (current == nullptr) {
ZLOGE(LABEL, "release proto current is null");
return;
}
(void)current->ProxyDetachDBinderSession(handle_);
(void)current->DetachHandleToIndex(handle_);
return;
}
void IPCObjectProxy::ReleaseBinderProto()
......
......@@ -124,7 +124,6 @@ std::u16string IPCProcessSkeleton::MakeHandleDescriptor(int handle)
IRemoteObject *IPCProcessSkeleton::FindOrNewObject(int handle)
{
bool newProxy = false;
IRemoteObject *remoteObject = nullptr;
std::u16string descriptor = MakeHandleDescriptor(handle);
{
......@@ -135,7 +134,7 @@ IRemoteObject *IPCProcessSkeleton::FindOrNewObject(int handle)
if (handle == REGISTRY_HANDLE) {
IRemoteInvoker *invoker = IPCThreadSkeleton::GetRemoteInvoker(IRemoteObject::IF_PROT_DEFAULT);
if (invoker == nullptr) {
DBINDER_LOGE("fail to get invoker");
DBINDER_LOGE("failed to get invoker");
return nullptr;
}
if (!invoker->PingService(REGISTRY_HANDLE)) {
......@@ -144,7 +143,6 @@ IRemoteObject *IPCProcessSkeleton::FindOrNewObject(int handle)
}
}
newProxy = true;
auto proxy = new IPCObjectProxy(handle, descriptor);
proxy->AttemptAcquire(this); // AttemptAcquire always returns true as life time is extended
remoteObject = reinterpret_cast<IRemoteObject *>(proxy);
......@@ -159,7 +157,7 @@ IRemoteObject *IPCProcessSkeleton::FindOrNewObject(int handle)
}
IPCObjectProxy *remoteProxy = reinterpret_cast<IPCObjectProxy *>(remoteObject);
remoteProxy->WaitForInit(newProxy);
remoteProxy->WaitForInit();
return remoteObject;
}
......@@ -237,6 +235,11 @@ bool IPCProcessSkeleton::IsContainsObject(IRemoteObject *object)
bool IPCProcessSkeleton::DetachObject(IRemoteObject *object)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
return DetachObjectInner(object);
}
bool IPCProcessSkeleton::DetachObjectInner(IRemoteObject *object)
{
int strongRef = object->GetSptrRefCount();
if (strongRef > 0) {
DBINDER_LOGI("proxy is still strong referenced:%{public}d", strongRef);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册