[feature][T8TSK-4] Optimize the network module, provide state buffer variables 4, add brief comment
Change-Id: I91866e5177dc1df32112761b516780594c5365db
diff --git a/lib/liblynq-network/lynq_network.cpp b/lib/liblynq-network/lynq_network.cpp
index 77762ae..82a02c5 100755
--- a/lib/liblynq-network/lynq_network.cpp
+++ b/lib/liblynq-network/lynq_network.cpp
@@ -156,6 +156,14 @@
return 0;
}
+/**@brief wait response with expected token and write msg to parcel in some time
+* @param p [IN]: pointer the parcel
+* @param token [IN]: the expected token for the response msg
+* @param time_out [IN]: timeout.
+* @return
+* 0:success
+* other:failure
+*/
const int waitResponse(Parcel*& p, int token,int time_out)
{
int waitToken = token;
@@ -223,11 +231,21 @@
}
}
+/**@brief print solicied response msg's head information
+* @param head [IN]: head information
+* @return none
+*/
void PrintHeader(lynq_resp_t& head)
{
LYINFLOG("resp_type=%d,token=%d,request=%d,slot_id=%d,error_code=%d",head.resp_type,head.token,head.request,head.slot_id,head.error);
}
+/**@brief get solicied response msg's head
+* @param head [OUT]: head information
+* @return
+* 0:success
+* other:failure
+*/
int GetHeader(Parcel* &p, lynq_resp_t& head)
{
LYINFLOG("get header");
@@ -247,6 +265,17 @@
}
}
+/**@brief send msg to service and get response from service
+* @param request_id [IN]: request id
+* @param time_out [IN]: wait time uplimit
+* @param p [IN]: point to response msg's parcel
+* @param argc [IN]: how many parameters in parameter string
+* @param format [IN]: parameter string's format
+* @param ... [IN]: the specific parameter
+* @return
+* 0:success
+* other:failure
+*/
int lynq_get_common_request(int request_id, int time_out, Parcel*& p, int argc, const char* format,...)
{
lynq_client_t client;
@@ -306,6 +335,11 @@
return;
}
+/**@ a thread just for recv\buffer solicited msg's response and notice waiting thread
+* @param p [IN]: no meaning
+* @return
+* always null
+*/
void *thread_rc_recv(void *p)
{
Parcel* rc_p;
@@ -328,22 +362,22 @@
LYERRLOG("%s recv len %d less %d",__func__, rc_len,sizeof(int)*2);
continue;
}
- rc_p= new Parcel;
- if(rc_p==NULL)
- {
- null_cnt++;
- LYERRLOG("%s rc_p is NULL, cnt is %d",__func__, null_cnt);
+ rc_p= new Parcel;
+ if(rc_p==NULL)
+ {
+ null_cnt++;
+ LYERRLOG("%s rc_p is NULL, cnt is %d",__func__, null_cnt);
if(null_cnt>20)
{
goto rc_recv_end;
}
continue;
- }
+ }
else
{
null_cnt=0;
}
-
+
rc_p->setData((uint8_t *)rc_data,rc_len); // p.setData((uint8_t *) buffer, buflen);
rc_p->setDataPosition(0);
if(rc_p->dataAvail()>0)
@@ -367,11 +401,11 @@
BLOCK_RC_MSG_UNLOCK();
break;
}
- else
- {
- LYERRLOG("%s rc_p data Avail %d not greater than 0",__func__, rc_p->dataAvail());
+ else
+ {
+ LYERRLOG("%s rc_p data Avail %d not greater than 0",__func__, rc_p->dataAvail());
delete rc_p;
- }
+ }
}
}