From e38a8e937864ebae325ed0d10a3134f288cb8baf Mon Sep 17 00:00:00 2001 From: wenbodong2015 <815611030@qq.com> Date: Sat, 10 Jul 2021 23:10:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3at=5Fsocket=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 失败现象为“找不到EAGAIN”,此问题由libc改动引发。 --- components/net/at/at_socket/at_socket.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 6d4c040856..46d158dabf 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include From b9d24aff61993f8e95b7d5fa405bd4b7f2d0fe7c Mon Sep 17 00:00:00 2001 From: wenbodong2015 <815611030@qq.com> Date: Sat, 10 Jul 2021 23:14:14 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3at=5Fsocket=E5=9C=A8?= =?UTF-8?q?=E6=9E=81=E9=99=90=E6=83=85=E5=86=B5=E4=B8=8B=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AT模块在执行AT+CLOSE并返回OK后,在实际关闭前(上报URC前)仍然有 可能接收到数据。所以接收数据时需要判断状态是否为AT_SOCKET_CONNECT。 另,at_recv_notice_cb在拒绝数据包时,没有释放数据包内存,从而导致 内在泄漏。 --- components/net/at/at_socket/at_socket.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 46d158dabf..27d2101c79 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -652,14 +652,20 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con RT_ASSERT(event == AT_SOCKET_EVT_RECV); /* check the socket object status */ - if (sock->magic != AT_SOCKET_MAGIC) + if (sock->magic != AT_SOCKET_MAGIC || sock->state != AT_SOCKET_CONNECT) { + rt_free((void *)buff); return; } /* put receive buffer to receiver packet list */ rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); - at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz); + if (!at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz)) + { + rt_free((void *)buff); + rt_mutex_release(sock->recv_lock); + return; + } rt_mutex_release(sock->recv_lock); rt_sem_release(sock->recv_notice); From 0f6586c660817344e75b52729e5f14928a4d81d9 Mon Sep 17 00:00:00 2001 From: wenbodong2015 <815611030@qq.com> Date: Fri, 16 Jul 2021 00:25:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=20=E4=BC=98=E5=8C=96at=5Fsocket=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=B3=84=E9=9C=B2=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/at/at_socket/at_socket.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 27d2101c79..27f12fa336 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -79,7 +79,7 @@ struct at_socket *at_get_socket(int socket) } /* get a block to the AT socket receive list*/ -static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) +static rt_err_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) { at_recv_pkt_t pkt = RT_NULL; @@ -87,7 +87,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) if (pkt == RT_NULL) { LOG_E("No memory for receive packet table!"); - return 0; + return -RT_ENOMEM; } pkt->bfsz_totle = length; @@ -96,7 +96,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) rt_slist_append(rlist, &pkt->list); - return length; + return RT_EOK; } /* delete and free all receive buffer list */ @@ -652,7 +652,7 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con RT_ASSERT(event == AT_SOCKET_EVT_RECV); /* check the socket object status */ - if (sock->magic != AT_SOCKET_MAGIC || sock->state != AT_SOCKET_CONNECT) + if (sock->magic != AT_SOCKET_MAGIC || sock->state == AT_SOCKET_CLOSED) { rt_free((void *)buff); return; @@ -660,7 +660,7 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con /* put receive buffer to receiver packet list */ rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); - if (!at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz)) + if (at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz) != RT_EOK) { rt_free((void *)buff); rt_mutex_release(sock->recv_lock);