[Bugfix][bug-view-662] Fix the issue of deinit getting stuck
Only Configure:No
Affected branch:master
Affected module:SIM
Is it affected on: only ZXIC
Self-test: Yes
Doc Update:No
Change-Id: I0bd955947e125e88d3eea558c3d7beadd66364e2
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-sim/lynq_module_socket.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-sim/lynq_module_socket.cpp
index c47cff4..d03b022 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-sim/lynq_module_socket.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-sim/lynq_module_socket.cpp
@@ -307,6 +307,7 @@
}
/*hq add for urc broadcase optimisson 2023/01/03 end*/
+int urc_state = 0;
void *thread_urc_recv(void *p)
{
Parcel *urc_p =NULL;
@@ -314,12 +315,14 @@
int res = 0;
lynq_head_t* phead;
int level,index,size;
+ urc_state = 1;
LYINFLOG("urc recv thread is running");
while(module_urc_status)
{
bzero(urc_data,LYNQ_REC_BUF);
+
res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);
- if(res<sizeof(int32_t)*2)
+ if(res<(int)sizeof(int32_t)*2)
{
LYERRLOG("thread_urc_recv step2 fail: res is %d",res);
continue;
@@ -337,7 +340,6 @@
continue;
}
LYDBGLOG("__FUNCTION__ %s __LINE__ %d\n", __FUNCTION__, __LINE__);
-
if(urc_data_is_in_shm_data(phead->resp_type,level,index,size))
{
LYINFLOG("__FUNCTION__ %s __LINE__ %d,use share memory\n", __FUNCTION__, __LINE__);
@@ -371,6 +373,7 @@
LYDBGLOG("__FUNCTION__ %s __LINE__ %d\n", __FUNCTION__, __LINE__);
}
LYINFLOG("urc recv thread ended");
+ urc_state = 0;
return NULL;
}
@@ -422,18 +425,28 @@
BLOCK_PROCESS_URC_MSG_LOCK(); //just cancel urc process tid when recv from
module_urc_status = 0;
- if(module_urc_tid!=-1)
+ // if(module_urc_tid!=-1)
+ // {
+ // ret = pthread_cancel(module_urc_tid);
+ // LYINFLOG("pthread cancel urc rev ret = %d",ret);
+ // }
+ //ret = pthread_join(module_urc_tid,NULL);
+ //LYINFLOG("pthread join urc tid ret = %d",ret);
+ //BLOCK_PROCESS_URC_MSG_UNLOCK();
+
+ for(int count = 0; count < 7 ;count++)
+ {
+ BLOCK_PROCESS_URC_MSG_UNLOCK();
+ usleep(200000);
+ BLOCK_PROCESS_URC_MSG_LOCK();
+ }
+ if(urc_state == 1)
{
ret = pthread_cancel(module_urc_tid);
- LYINFLOG("pthread cancel urc rev ret = %d",ret);
+ LYINFLOG("pthread cancel urc rev ret = %d",ret);
}
BLOCK_PROCESS_URC_MSG_UNLOCK();
- if(module_urc_tid != -1)
- {
- ret = pthread_join(module_urc_tid,NULL);
- LYINFLOG("pthread join urc tid ret = %d",ret);
- module_urc_tid =-1;
- }
+ module_urc_tid = -1;
}
void lynq_close_urc_process_thread()
@@ -470,6 +483,7 @@
module_urc_addr_serv.sin_family = AF_INET;
module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);
module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);
+
/* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
if(ret <0)
@@ -479,6 +493,18 @@
module_urc_sock_fd =-1;
return RESULT_ERROR;
}
+
+ struct timeval tv;
+ tv.tv_sec = 1; // 秒
+ tv.tv_usec = 0; // 微秒
+ ret = setsockopt(module_urc_sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+ if (ret < 0) {
+ LYERRLOG("urc socket set SO_RCVTIMEO error");
+ close(module_urc_sock_fd);
+ module_urc_sock_fd = -1;
+ return RESULT_ERROR;
+ }
+
ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));
if(ret <0)
{