Skip to content

Commit

Permalink
[at]at_recvfrom添加错误事件,保持与改之前的逻辑一致
Browse files Browse the repository at this point in the history
  • Loading branch information
yangpengya committed Dec 26, 2023
1 parent 713cf9b commit 0132838
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions components/net/at/at_socket/at_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit 0132838

Please sign in to comment.