net/rpmsg: simplify the socket timeout of connect

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-08-16 17:16:17 +08:00 committed by Xiang Xiao
parent dc97ee9b36
commit 64e95dc1f5

View File

@ -290,6 +290,8 @@ static int rpmsg_socket_sync(FAR struct rpmsg_socket_conn_s *conn,
return ret; return ret;
} }
ret = OK;
if (conn->sendsize == 0) if (conn->sendsize == 0)
{ {
ret = net_timedwait(&conn->sendsem, timeout); ret = net_timedwait(&conn->sendsem, timeout);
@ -638,7 +640,6 @@ static int rpmsg_socket_listen(FAR struct socket *psock, int backlog)
static int rpmsg_socket_connect_internal(FAR struct socket *psock) static int rpmsg_socket_connect_internal(FAR struct socket *psock)
{ {
FAR struct rpmsg_socket_conn_s *conn = psock->s_conn; FAR struct rpmsg_socket_conn_s *conn = psock->s_conn;
unsigned int timeout;
unsigned int tc; unsigned int tc;
int ret; int ret;
@ -657,22 +658,7 @@ static int rpmsg_socket_connect_internal(FAR struct socket *psock)
return ret; return ret;
} }
ret = -ETIMEDOUT; ret = rpmsg_socket_sync(conn, _SO_TIMEOUT(psock->s_rcvtimeo));
timeout = _SO_TIMEOUT(psock->s_rcvtimeo);
for (tc = 0; tc < timeout * 1000; )
{
ret = rpmsg_socket_sync(conn, timeout);
if (ret != RPMSG_ERR_ADDR)
{
break;
}
if (timeout != UINT_MAX)
{
tc += RPMSG_TICK_COUNT;
}
}
if (ret < 0) if (ret < 0)
{ {