Commit e1a27285 authored by 黄振令's avatar 黄振令

【修改内容】1. tcp连接粘包问题:1)使用json格式找'{'找到完成的json;2). 收到数据有'\0',用'\0'来区分粘包;2....

【修改内容】1. tcp连接粘包问题:1)使用json格式找'{'找到完成的json;2). 收到数据有'\0',用'\0'来区分粘包;2. 同意发送格式,发送数据接口数据发送修改为不包括'\0';3. tcp连接增加锁
parent a279a29f
......@@ -382,7 +382,7 @@ int KK_Send_CloudState(int state)
cJSON_AddItemToObject(root, MSG_INFO_STR, infoObj);
cJSON_AddItemToObject(root, MSG_PAYLOAD_STR,payloadObj);
out=cJSON_Print(root);
kk_ipc_send(IPC_APP2MID, out, strlen(out)+1);
kk_ipc_send(IPC_APP2MID, out, strlen(out));
cJSON_Delete(root);
free(payloadStr);
free(infoStr);
......@@ -401,6 +401,6 @@ void KK_Sendto_DevData(const char *topic,const char *data)
if(send_data == NULL){
return;
}
kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data)+1);
kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data));
free(send_data);
}
......@@ -100,7 +100,7 @@ static void watcher_cb (struct ev_loop *loop ,struct ev_io *w, int revents)
if (strncmp(validDat,MAGIC_ACK, strlen(MAGIC_ACK)) == 0){
}else{
kk_ipc_send_ex(loop_ctrl->type, MAGIC_ACK, strlen(MAGIC_ACK)+1, chlMark);
kk_ipc_send_ex(loop_ctrl->type, MAGIC_ACK, strlen(MAGIC_ACK), chlMark);
}
loop_ctrl->isconnect =1;
......@@ -453,7 +453,7 @@ int kk_ipc_isconnect(ipc_type type){
{
for(int i =0; i<20;i++){
kk_ipc_send(type, MAGIC, strlen(MAGIC)+1);
kk_ipc_send(type, MAGIC, strlen(MAGIC));
usleep(500000);
if (loop_ctrl->isconnect == 1){
break;
......
This diff is collapsed.
......@@ -22,7 +22,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){
dm_queue_msg_insert4(buf);
}else{
kk_ipc_send(IPC_MID2APP, buf, strlen(buf) + 1);
kk_ipc_send(IPC_MID2APP, buf, strlen(buf) );
free(buf);
}
cJSON_Delete(root);
......
......@@ -153,7 +153,7 @@ void mid2p_cb(void* data, int len, char* chalMark){
void gw2mid_cb(void* data, int len, char* chalMark){
if (data != NULL){
printf("gw2mid_cb chalMark=%s, data: %s RECEIVED \r\n", chalMark, data);
printf("gw2mid_cb chalMark=%s, data: %s [%d]RECEIVED \r\n", chalMark, data,len);
mid2p_cb(data,len,chalMark);
}
}
......
......@@ -549,7 +549,7 @@ int OTA_publishProgress(void *handle, char* payload){
cJSON_AddStringToObject(root, "info", topicBuf);
cJSON_AddStringToObject(root, "payload", payload);
void *buf = cJSON_Print(root);
kk_ipc_send(IPC_MID2APP, buf, strlen(buf) + 1);
kk_ipc_send(IPC_MID2APP, buf, strlen(buf));
free(msgTypeStr);
free(topicBuf);
free(buf);
......
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
......@@ -112,7 +113,7 @@ static int send_result_resp(cJSON * result,
char * str_result = rpc_cJSON_Print(result_root);
printf("send json:\n%s\n",str_result);
return_value = kk_sendData2CCU(str_result, strlen(str_result)+1);
return_value = kk_sendData2CCU(str_result, strlen(str_result));
free(str_result);
rpc_cJSON_Delete(result_root);
return return_value;
......@@ -154,7 +155,7 @@ static int send_error_resp(int code, char* message,
}
char * str_result = rpc_cJSON_Print(result_root);
//printf("alla=========== :%d\n", strlen(str_result)+1);
return_value = kk_sendData2CCU(str_result, strlen(str_result)+1);
return_value = kk_sendData2CCU(str_result, strlen(str_result));
printf("send_error_resp:\n%s\n", str_result);
free(str_result);
rpc_cJSON_Delete(result_root);
......@@ -227,7 +228,7 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
void _cb(void* data, int len, char* chlmark){
if (data != NULL){
printf("plat_cb: %s RECEIVED \r\n", data);
printf("plat_cb: %s [%d]RECEIVED \r\n", data,len);
cJSON *root;
char *end_ptr = NULL;
......@@ -625,7 +626,7 @@ int jrpc_send_msg(cJSON * msgJson) {
return_value = kk_sendData2CCU(str_result, strlen(str_result)+1);
return_value = kk_sendData2CCU(str_result, strlen(str_result));
free(str_result);
return return_value;
}
......@@ -1012,5 +1013,4 @@ void rpc_reportDevices(void)
}
}
rpc_report_devices(devicesJson);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment