diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 3925f0f57c..cccb35ae1a 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -572,10 +572,16 @@ __exit: if (result < 0) { - at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); + if (sock != RT_NULL) + { + at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); + } } - at_do_event_changes(sock, AT_EVENT_SEND, RT_TRUE); + if (sock) + { + at_do_event_changes(sock, AT_EVENT_SEND, RT_TRUE); + } return result; } @@ -699,24 +705,27 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f __exit: - if (recv_len > 0) + if (sock != RT_NULL) { - result = recv_len; - at_do_event_changes(sock, AT_EVENT_RECV, RT_FALSE); - errno = 0; - if (!rt_slist_isempty(&sock->recvpkt_list)) + if (recv_len > 0) { - at_do_event_changes(sock, AT_EVENT_RECV, RT_TRUE); + result = recv_len; + at_do_event_changes(sock, AT_EVENT_RECV, RT_FALSE); + errno = 0; + if (!rt_slist_isempty(&sock->recvpkt_list)) + { + at_do_event_changes(sock, AT_EVENT_RECV, RT_TRUE); + } + else + { + at_do_event_clean(sock, AT_EVENT_RECV); + } } else { - at_do_event_clean(sock, AT_EVENT_RECV); + at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); } } - else - { - at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); - } return result; } @@ -807,7 +816,10 @@ __exit: if (result < 0) { - at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); + if (sock != RT_NULL) + { + at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE); + } } else {