From 3a8c6f32c09fdf744697eff85d80ad083a424881 Mon Sep 17 00:00:00 2001 From: HubretXie Date: Wed, 12 Dec 2018 11:29:14 +0800 Subject: [PATCH] Update at_socket.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改socket读取遗留数据逻辑 --- components/net/at/at_socket/at_socket.c | 32 ++++++++----------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 80b86f8198..3925f0f57c 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -627,6 +627,15 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f at_dev_ops->at_set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb); } + /* receive packet list last transmission of remaining data */ + rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); + if((recv_len = at_recvpkt_get(&(sock->recvpkt_list), (char *)mem, len)) > 0) + { + rt_mutex_release(sock->recv_lock); + goto __exit; + } + rt_mutex_release(sock->recv_lock); + /* socket passively closed, receive function return 0 */ if (sock->state == AT_SOCKET_CLOSED) { @@ -640,15 +649,6 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f goto __exit; } - /* receive packet list last transmission of remaining data */ - rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); - if((recv_len = at_recvpkt_get(&(sock->recvpkt_list), (char *)mem, len)) > 0) - { - rt_mutex_release(sock->recv_lock); - goto __exit; - } - rt_mutex_release(sock->recv_lock); - /* non-blocking sockets receive data */ if (flags & MSG_DONTWAIT) { @@ -715,19 +715,7 @@ __exit: } else { - /* try to read Legacy data */ - /* receive packet list last transmission of remaining data */ - rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); - recv_len = at_recvpkt_get(&(sock->recvpkt_list), (char *)mem, len); - rt_mutex_release(sock->recv_lock); - if(recv_len<=0) - { - at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); - } - else - { - result = recv_len; - } + at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); } return result;