Skip to content

Commit 8f95b78

Browse files
committed
[net][at] fix at select receive event change issue.
1 parent 0aa4b72 commit 8f95b78

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

components/net/at/at_socket/at_socket.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static void at_closed_notice_cb(int socket, at_socket_evt_t event, const char *b
513513
sock->state = AT_SOCKET_CLOSED;
514514
rt_sem_release(sock->recv_notice);
515515
}
516+
516517
int at_connect(int socket, const struct sockaddr *name, socklen_t namelen)
517518
{
518519
struct at_socket *sock;
@@ -611,7 +612,13 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f
611612
sock->state = AT_SOCKET_CONNECT;
612613
}
613614

614-
if (sock->state != AT_SOCKET_CONNECT)
615+
/* socket passively closed, receive function return 0 */
616+
if (sock->state == AT_SOCKET_CLOSED)
617+
{
618+
result = 0;
619+
goto __exit;
620+
}
621+
else if (sock->state != AT_SOCKET_CONNECT)
615622
{
616623
LOG_E("received data error, current socket (%d) state (%d) is error.", socket, sock->state);
617624
result = -1;
@@ -664,26 +671,28 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f
664671
else
665672
{
666673
LOG_D("received data exit, current socket (%d) is closed by remote.", socket);
667-
result = -1;
674+
result = 0;
668675
goto __exit;
669676
}
670677
}
671678
}
672679

673680
__exit:
674681

675-
if (result < 0)
676-
{
677-
at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE);
678-
}
679-
else
682+
if (recv_len > 0)
680683
{
681684
result = recv_len;
682-
if (recv_len)
685+
at_do_event_changes(sock, AT_EVENT_RECV, RT_FALSE);
686+
687+
if (!rt_slist_isempty(&sock->recvpkt_list))
683688
{
684-
at_do_event_changes(sock, AT_EVENT_RECV, RT_FALSE);
689+
at_do_event_changes(sock, AT_EVENT_RECV, RT_TRUE);
685690
}
686691
}
692+
else
693+
{
694+
at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE);
695+
}
687696

688697
return result;
689698
}

components/net/at/include/at.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
extern "C" {
3333
#endif
3434

35-
#define AT_SW_VERSION "1.0.1"
36-
#define AT_SW_VERSION_NUM 0x10000
35+
#define AT_SW_VERSION "1.0.2"
36+
#define AT_SW_VERSION_NUM 0x10002
3737

3838
#define DBG_ENABLE
3939
#define DBG_SECTION_NAME "AT"

0 commit comments

Comments
 (0)