From 01328387bebf94c0fb7c99c48ab3b3da39182a12 Mon Sep 17 00:00:00 2001 From: yangpeng Date: Tue, 26 Dec 2023 17:28:45 +0800 Subject: [PATCH] =?UTF-8?q?[at]at=5Frecvfrom=E6=B7=BB=E5=8A=A0=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BA=8B=E4=BB=B6=EF=BC=8C=E4=BF=9D=E6=8C=81=E4=B8=8E?= =?UTF-8?q?=E6=94=B9=E4=B9=8B=E5=89=8D=E7=9A=84=E9=80=BB=E8=BE=91=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/at/at_socket/at_socket.c | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index d163e8ddb87..2beed442bbb 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -972,7 +972,7 @@ int at_accept(int socket, struct sockaddr *name, socklen_t *namelen) int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) { struct at_socket *sock = RT_NULL; - int timeout; + int timeout, result = 0; size_t recv_len = 0; if (mem == RT_NULL || len == 0) @@ -1011,7 +1011,8 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f if (sock->state == AT_SOCKET_CLOSED) { /* socket passively closed, receive function return 0 */ - return 0; + result = 0; + break; } rt_sem_control(sock->recv_notice, RT_IPC_CMD_RESET, RT_NULL); @@ -1026,30 +1027,41 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f at_do_event_clean(sock, AT_EVENT_RECV); } errno = 0; - return recv_len; + result = recv_len; + break; } if (flags & MSG_DONTWAIT) { errno = EAGAIN; - return -1; + result = -1; + break; } /* set AT socket receive timeout */ - if ((timeout = sock->recv_timeout) == 0) + if (sock->recv_timeout == 0) { timeout = RT_WAITING_FOREVER; } else { - timeout = rt_tick_from_millisecond(timeout); + timeout = rt_tick_from_millisecond(sock->recv_timeout); } if (rt_sem_take(sock->recv_notice, timeout) != RT_EOK) { + LOG_D("AT socket (%d) receive timeout (%d)!", socket, timeout); errno = EAGAIN; - return -1; + result = -1; + break; } } + + if (result <= 0) + { + at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); + } + + return result; } int at_recv(int s, void *mem, size_t len, int flags)