[Bugfix][API-760] in long time network api calling test, 8004 failure hanppend 3

Change-Id: I16be297c0f3f8fa0fc95a8909447f9848667c2b2
diff --git a/framework/lynq-ril-service/src/ril.cpp b/framework/lynq-ril-service/src/ril.cpp
index 9d71890..724bcb5 100755
--- a/framework/lynq-ril-service/src/ril.cpp
+++ b/framework/lynq-ril-service/src/ril.cpp
@@ -5896,6 +5896,21 @@
     }
     */
 }
+
+//add by hq for bug 760 2023/02/09
+static int setnonblocking(int sockfd) {
+    int flag = fcntl(sockfd, F_GETFL, 0);  //get current flag
+    if (flag < 0) {
+        RLOGE("fcntl F_GETFL fail");
+        return -1;
+    }
+    if (fcntl(sockfd, F_SETFL, flag | O_NONBLOCK) < 0) {  //add O_NONBLOCK
+        RLOGE("fcntl F_SETFL fail");
+        return -1;
+    }
+    return 0;
+}
+
 void LYNQ_RIL_RecSocket()
 {
     RLOGD("LYNQ_RIL_RecSocket start\n");
@@ -5929,6 +5944,13 @@
          RLOGE("Server Bind Failed:");
          exit(1);
     }
+
+    if(setnonblocking(server_socket_fd)!=0)
+    {
+        RLOGE("setnonblocking Failed");
+        exit(1);
+    }
+	
     /* create epoll fd,add socket to epoll */
     ep_fd = epoll_create(LYNQ_SOCKET_ENVNT_FD_MAX);
     //int len = sizeof(struct sockaddr_in);
@@ -5967,112 +5989,114 @@
                 socklen_t client_addr_length = sizeof(lynqClient_addr);
                 /* receive the data */
                 bzero(buffer, LYNQ_SOCKET_BUFFER);
-                if(recvfrom(server_socket_fd, buffer, LYNQ_SOCKET_BUFFER,0,(struct sockaddr*)&lynqClient_addr, &client_addr_length) == -1)
+                while(recvfrom(server_socket_fd, buffer, LYNQ_SOCKET_BUFFER,0,(struct sockaddr*)&lynqClient_addr, &client_addr_length) != -1)//add while by hq for bug 760 2023/02/09
                 {
-                    RLOGE("Receive Data Failed:");
-                    continue;
-                }
-                client_tmp = (lynq_client_t*)buffer;
-                RLOGD("[LYNQ socketId] utoken=%d,request=%d,len=%d,param=%s",client_tmp->uToken,client_tmp->request,client_tmp->paramLen,client_tmp->param);
-                //char test[36] = {};
-                //sprintf(test,"test okay len = %d",client_tmp->paramLen);
-                //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&client_addr,client_addr_length);
-                argv[0] = (char *)lynq_requset_to_string(client_tmp->request);
-                argc = 0;
-                if(client_tmp->paramLen > 0)
-                {
-                    /*transfer struct*/
-                    argc = parse_param(client_tmp->param, argv+1, MAX_ARGS);
-                    if(argc < 1)
+                    client_tmp = (lynq_client_t*)buffer;
+                    RLOGD("[LYNQ socketId] utoken=%d,request=%d,len=%d,param=%s",client_tmp->uToken,client_tmp->request,client_tmp->paramLen,client_tmp->param);
+                    //char test[36] = {};
+                    //sprintf(test,"test okay len = %d",client_tmp->paramLen);
+                    //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&client_addr,client_addr_length);
+                    argv[0] = (char *)lynq_requset_to_string(client_tmp->request);
+                    argc = 0;
+                    if(client_tmp->paramLen > 0)
                     {
-                        RLOGE("%s: error input.", buffer);
+                        /*transfer struct*/
+                        argc = parse_param(client_tmp->param, argv+1, MAX_ARGS);
+                        if(argc < 1)
+                        {
+                            RLOGE("%s: error input.", buffer);
+                            continue;
+                        }
+                    }
+                    printf("argc =%d\n",argc);
+                    argc = argc+1;
+                    for(int t = 0;t<argc;t++)
+                    {
+                        RLOGD("warren test argv[%d]=%s\n",t,argv[t]);
+                    }
+                    COMMAND *command = find_command(argv[0]);
+                    if(!command)
+                    {
+                        RLOGE("%s: No such command for DemoApp", argv[0]);
                         continue;
                     }
-                }
-                printf("argc =%d\n",argc);
-                argc = argc+1;
-                for(int t = 0;t<argc;t++)
-                {
-                    RLOGD("warren test argv[%d]=%s\n",t,argv[t]);
-                }
-                COMMAND *command = find_command(argv[0]);
-                if(!command)
-                {
-                    RLOGE("%s: No such command for DemoApp", argv[0]);
-                    continue;
-                }
-                int32_t request;
-                request = command->request;
-                RIL_SOCKET_ID id = RIL_SOCKET_1;
-                if(utils::is_support_dsds()) {
-                    id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
-                } else if(utils::is_suppport_dsss()) {
-                    id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
-                }
-                if(request == -1)
-                {
-                    (*(command->func)) (argc, argv, id, NULL);
-                    continue;
-                }
-                if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
-                    RLOGW("unsupported request code %d token %d", request);
-                    // FIXME this should perhaps return a response
-                    continue;
-                }
-                /*jb.qi add for two sim suspend 2022/9/19 start  lei modify for factory test of sleep*/
-                if(request == LYNQ_REQUEST_CHANGE_SCREEN_STATE || request == LYNQ_REQUEST_CHANGE_RADIO)
-                {
-                    int i;
-                    RLOGD("lynq_request_change_screen_state");
-                    if(request == LYNQ_REQUEST_CHANGE_SCREEN_STATE)
-                    {
-                        for(i=0;i<2;i++) //suspend sim0 and sim1
-                        {
-                            lynq_sendRequestToMd(RIL_REQUEST_SCREEN_STATE, i, argv, lynqClient_addr, client_tmp->uToken);
-                        }
+                    int32_t request;
+                    request = command->request;
+                    RIL_SOCKET_ID id = RIL_SOCKET_1;
+                    if(utils::is_support_dsds()) {
+                        id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
+                    } else if(utils::is_suppport_dsss()) {
+                        id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
                     }
-                    /*lei modify for factory test of sleep*/
-                    if(request == LYNQ_REQUEST_CHANGE_RADIO)
+                    if(request == -1)
                     {
-                        for(i=0;i<2;i++) //both radio on/off
-                        {
-                            lynq_sendRequestToMd(RIL_REQUEST_RADIO_POWER, i, argv, lynqClient_addr, client_tmp->uToken);
-                        }
+                        (*(command->func)) (argc, argv, id, NULL);
+                        continue;
                     }
-                    continue;
+                    if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
+                        RLOGW("unsupported request code %d token %d", request);
+                        // FIXME this should perhaps return a response
+                        continue;
+                    }
+                    /*jb.qi add for two sim suspend 2022/9/19 start  lei modify for factory test of sleep*/
+                    if(request == LYNQ_REQUEST_CHANGE_SCREEN_STATE || request == LYNQ_REQUEST_CHANGE_RADIO)
+                    {
+                        int i;
+                        RLOGD("lynq_request_change_screen_state");
+                        if(request == LYNQ_REQUEST_CHANGE_SCREEN_STATE)
+                        {
+                            for(i=0;i<2;i++) //suspend sim0 and sim1
+                            {
+                                lynq_sendRequestToMd(RIL_REQUEST_SCREEN_STATE, i, argv, lynqClient_addr, client_tmp->uToken);
+                            }
+                        }
+                        /*lei modify for factory test of sleep*/
+                        if(request == LYNQ_REQUEST_CHANGE_RADIO)
+                        {
+                            for(i=0;i<2;i++) //both radio on/off
+                            {
+                                lynq_sendRequestToMd(RIL_REQUEST_RADIO_POWER, i, argv, lynqClient_addr, client_tmp->uToken);
+                            }
+                        }
+                        continue;
+                    }
+                    /*jb.qi add for two sim suspend 2022/9/19 end*/
+                    RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
+                    RequestInfo *pRI  = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
+                    pRI->uToken = client_tmp->uToken;
+                    pRI->lynqEvent = 2;
+                    pRI->uClient_addr.sin_family = lynqClient_addr.sin_family;
+                    pRI->uClient_addr.sin_addr.s_addr = lynqClient_addr.sin_addr.s_addr;
+                    pRI->uClient_addr.sin_port = lynqClient_addr.sin_port;
+                    //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&pRI->uClient_addr,client_addr_length);
+                    //pRI->uClient_addr.sa_family = (struct sockaddr)client_addr.sa_family;
+                    //memcpy(pRI->uClient_addr.sa_data,&client_addr
+                    //Radio on/off only allow one thread operate.
+                    if(request == RIL_REQUEST_RADIO_POWER)
+                    {
+                        speciaRequest_wait();
+                    }
+    #ifdef ECALL_SUPPORT
+                    else if(request == RIL_REQUEST_ECALL_FAST_MAKE_ECALL)
+                    {
+                        init_redial_flag();
+                    }
+    #endif
+                    memset(Time_buf,0,sizeof(Time_buf));
+                    GetTimeString(Time_buf);
+                    //FUNCTION_CALLED(Time_buf,requestToString(request));
+                    int waittoken = pRI->token;
+                    (*(command->func)) (argc, argv, pRI->socket_id, pRI);
+                    FUNCTION_CALLED(Time_buf,requestToString(request));
+                    waitResponse(waittoken);
+                    memset(Time_buf,0,sizeof(Time_buf));
+                    GetTimeString(Time_buf);
+                    FUNCTION_RETURN(Time_buf,requestToString(request));          
+                    bzero(buffer, LYNQ_SOCKET_BUFFER);
+
                 }
-                /*jb.qi add for two sim suspend 2022/9/19 end*/
-                RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
-                RequestInfo *pRI  = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
-                pRI->uToken = client_tmp->uToken;
-                pRI->lynqEvent = 2;
-                pRI->uClient_addr.sin_family = lynqClient_addr.sin_family;
-                pRI->uClient_addr.sin_addr.s_addr = lynqClient_addr.sin_addr.s_addr;
-                pRI->uClient_addr.sin_port = lynqClient_addr.sin_port;
-                //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&pRI->uClient_addr,client_addr_length);
-                //pRI->uClient_addr.sa_family = (struct sockaddr)client_addr.sa_family;
-                //memcpy(pRI->uClient_addr.sa_data,&client_addr
-                //Radio on/off only allow one thread operate.
-                if(request == RIL_REQUEST_RADIO_POWER)
-                {
-                    speciaRequest_wait();
-                }
-#ifdef ECALL_SUPPORT
-                else if(request == RIL_REQUEST_ECALL_FAST_MAKE_ECALL)
-                {
-                    init_redial_flag();
-                }
-#endif
-                memset(Time_buf,0,sizeof(Time_buf));
-                GetTimeString(Time_buf);
-                //FUNCTION_CALLED(Time_buf,requestToString(request));
-                int waittoken = pRI->token;
-                (*(command->func)) (argc, argv, pRI->socket_id, pRI);
-                FUNCTION_CALLED(Time_buf,requestToString(request));
-                waitResponse(waittoken);
-                memset(Time_buf,0,sizeof(Time_buf));
-                GetTimeString(Time_buf);
-                FUNCTION_RETURN(Time_buf,requestToString(request));
+                RLOGE("process Receive Data end");
+             //   continue;                
             }
         }
      }