Skip to content

Commit

Permalink
fix for atparser.c, mk3060.c, bk7231.c (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
huaianrenhnu authored and xiaowenxia committed Jan 22, 2019
1 parent 1fdd636 commit 552487d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
5 changes: 2 additions & 3 deletions network/sal/atparser/atparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,8 @@ static void at_worker(void *arg)
LOGD(MODULE_NAME, "AT! %s\r\n", oob->prefix);
if (oob->postfix == NULL) {
oob->cb(oob->arg, NULL, 0);
memset(buf + offset - strlen(oob->prefix), 0,
strlen(oob->prefix));
offset -= strlen(oob->prefix);
memset(buf, 0, offset);
offset = 0;
} else {
if (oob->reallen == 0) {
memset(oob->oobinputdata, 0, oob->maxlen);
Expand Down
4 changes: 3 additions & 1 deletion network/sal/sal_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,9 @@ int sal_recvfrom(int s, void *mem, size_t len, int flags,
SAL_ERROR("invalid copylen %d, len = %d, it would underflow\n", copylen, len);
return -1;
}
if ((len == copylen) || (pstsock->rcvevent <= 0) || ((flags & MSG_PEEK) != 0)) {

len -= copylen;
if ((len <= 0) || (pstsock->rcvevent <= 0) || ((flags & MSG_PEEK) != 0)) {
done = 1;
}
} else {
Expand Down
18 changes: 14 additions & 4 deletions network/sal/wifi/bk7231/bk7231.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ static void handle_socket_data()
uint32_t len = 0;
char reader[16] = {0};
char *recvdata = NULL;
char single;

/* Eat the "OCKET," */
at.read(reader, 6);
Expand Down Expand Up @@ -163,15 +164,23 @@ static void handle_socket_data()
return;
}
/* Prepare socket data */
recvdata = (char *)aos_malloc(len + 1);
recvdata = (char *)aos_malloc(len);
if (!recvdata) {
LOGE(TAG, "Error: %s %d out of memory, len is %d. \r\n", __func__, __LINE__, len);
return;
}

at.read(recvdata, len);
recvdata[len] = '\0';
LOGD(TAG, "The socket data is %s", recvdata);
ret = at.read(recvdata, len);
if (ret != len) {
LOGE(TAG, "at read error recv %d want %d!\n", ret, len);
goto err;
}

at.read(&single, 1);
if (single != '\r') {
LOGE(TAG, "at fail to read delimiter %d after data %d!\n", '\r', single);
goto err;
}

if (g_netconn_data_input_cb && (g_link[link_id].fd >= 0)) {
/* TODO get recv data src ip and port*/
Expand All @@ -184,6 +193,7 @@ static void handle_socket_data()
LOGD(TAG, "%s socket data on link %d with length %d posted to sal\n",
__func__, link_id, len);

err:
aos_free(recvdata);

}
Expand Down
18 changes: 14 additions & 4 deletions network/sal/wifi/mk3060/mk3060.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,24 @@ static void handle_socket_data()
return;
}
/* Prepare socket data */
recvdata = (char *)aos_malloc(len + 1);
recvdata = (char *)aos_malloc(len);
if (!recvdata) {
LOGE(TAG, "Error: %s %d out of memory, len is %d. \r\n", __func__, __LINE__, len);
return;
}

at.read(recvdata, len);
recvdata[len] = '\0';
LOGD(TAG, "The socket data is %s", recvdata);
ret = at.read(recvdata, len);
if (ret != len) {
LOGE(TAG, "at read error recv %d want %d!\n", ret, len);
goto err;
}

memset(reader, 0, sizeof(reader));
at.read(reader, 2);
if (strncmp(reader, AT_RECV_PREFIX, 2) != 0) {
LOGE(TAG, "at fail to read delimiter %s after data %s!\n", AT_RECV_PREFIX, reader);
goto err;
}

if (g_netconn_data_input_cb && (g_link[link_id].fd >= 0)) {
/* TODO get recv data src ip and port*/
Expand All @@ -304,6 +313,7 @@ static void handle_socket_data()
LOGD(TAG, "%s socket data on link %d with length %d posted to sal\n",
__func__, link_id, len);

err:
aos_free(recvdata);

}
Expand Down

0 comments on commit 552487d

Please sign in to comment.