net: replace net_sem*wait with conn_dev_sem*wait to simplify code logic

optimize the current code format according to the previous net_xxx_wait
implementation to reduce multiple calls of similar code

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-11-24 20:17:18 +08:00
committed by Alan C. Assis
parent aee7ea0d7d
commit 8f41613374
42 changed files with 196 additions and 205 deletions
+8 -9
View File
@@ -562,7 +562,7 @@ static void udp_recvfrom_initialize(FAR struct udp_conn_s *conn,
* Evaluate the result of the recv operations
*
* Input Parameters:
* result The result of the net_sem_timedwait operation
* result The result of the conn_dev_sem_timedwait operation
* (may indicate EINTR)
* pstate A pointer to the state structure to be initialized
*
@@ -588,8 +588,8 @@ static ssize_t udp_recvfrom_result(int result, struct udp_recvfrom_s *pstate)
return pstate->ir_result;
}
/* If net_sem_timedwait failed, then we were probably reawakened by a
* signal. In this case, net_sem_timedwait will have returned negated
/* If conn_dev_sem_timedwait failed, then we were probably reawakened by a
* signal. In this case, conn_dev_sem_timedwait will have returned negated
* errno appropriately.
*/
@@ -765,14 +765,13 @@ ssize_t psock_udp_recvfrom(FAR struct socket *psock, FAR struct msghdr *msg,
tls_cleanup_push(tls_get_info(), udp_callback_cleanup, &info);
/* Wait for either the receive to complete or for an error/timeout
* to occur. net_sem_timedwait will also terminate if a signal is
* received.
* to occur. conn_dev_sem_timedwait will also terminate if a
* signal is received.
*/
conn_dev_unlock(&conn->sconn, dev);
ret = net_sem_timedwait(&state.ir_sem,
_SO_TIMEOUT(conn->sconn.s_rcvtimeo));
conn_dev_lock(&conn->sconn, dev);
ret = conn_dev_sem_timedwait(&state.ir_sem, true,
_SO_TIMEOUT(conn->sconn.s_rcvtimeo),
&conn->sconn, dev);
tls_cleanup_pop(tls_get_info(), 0);
if (ret == -ETIMEDOUT)
{
+5 -5
View File
@@ -717,14 +717,15 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
conn_lock(&conn->sconn);
while (udp_wrbuffer_inqueue_size(conn) + len > conn->sndbufs)
{
conn_unlock(&conn->sconn);
if (nonblock)
{
conn_unlock(&conn->sconn);
return -EAGAIN;
}
ret = net_sem_timedwait_uninterruptible(&conn->sndsem,
udp_send_gettimeout(start, timeout));
ret = conn_dev_sem_timedwait(&conn->sndsem, false,
udp_send_gettimeout(start, timeout),
&conn->sconn, NULL);
if (ret < 0)
{
if (ret == -ETIMEDOUT)
@@ -732,10 +733,9 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
ret = -EAGAIN;
}
conn_unlock(&conn->sconn);
return ret;
}
conn_lock(&conn->sconn);
}
conn_unlock(&conn->sconn);
+4 -6
View File
@@ -480,13 +480,13 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
netdev_txnotify_dev(state.st_dev, UDP_POLL);
/* Wait for either the receive to complete or for an error/timeout to
* occur. NOTES: net_sem_timedwait will also terminate if a signal
* occur. NOTES: conn_dev_sem_timedwait will also terminate if a signal
* is received.
*/
conn_dev_unlock(&conn->sconn, state.st_dev);
ret = net_sem_timedwait(&state.st_sem,
_SO_TIMEOUT(conn->sconn.s_sndtimeo));
ret = conn_dev_sem_timedwait(&state.st_sem, true,
_SO_TIMEOUT(conn->sconn.s_sndtimeo),
&conn->sconn, state.st_dev);
if (ret >= 0)
{
/* The result of the sendto operation is the number of bytes
@@ -496,8 +496,6 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
ret = state.st_sndlen;
}
conn_dev_lock(&conn->sconn, state.st_dev);
/* Make sure that no further events are processed */
udp_callback_free(state.st_dev, conn, state.st_cb);
+2 -3
View File
@@ -85,9 +85,8 @@ int udp_txdrain(FAR struct socket *psock, unsigned int timeout)
if (!sq_empty(&conn->write_q))
{
conn->txdrain_sem = &waitsem;
conn_unlock(&conn->sconn);
ret = net_sem_timedwait_uninterruptible(&waitsem, timeout);
conn_lock(&conn->sconn);
ret = conn_dev_sem_timedwait(&waitsem, false, timeout,
&conn->sconn, NULL);
conn->txdrain_sem = NULL;
}