Skip to content

Commit

Permalink
Fix the bug that netlink receive wait does not hang up
Browse files Browse the repository at this point in the history
Signed-off-by: wangyingdong <[email protected]>
  • Loading branch information
wangyingdong1 authored and wangchen61698 committed Aug 20, 2024
1 parent 8cc27f2 commit fe2dc34
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
17 changes: 11 additions & 6 deletions net/netlink/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,21 @@ netlink_tryget_response(FAR struct netlink_conn_s *conn);
* Note: The network will be momentarily locked to support exclusive
* access to the pending response list.
*
* Input Parameters:
* conn - The Netlink connection
* response - The next response from the head of the pending response list
* is returned. This function will block until a response is
* received if the pending response list is empty. NULL will be
* returned only in the event of a failure.
*
* Returned Value:
* The next response from the head of the pending response list is
* returned. This function will block until a response is received if
* the pending response list is empty. NULL will be returned only in the
* event of a failure.
* Zero (OK) is returned if the notification was successfully set up.
* A negated error value is returned if an unexpected error occurred
*
****************************************************************************/

FAR struct netlink_response_s *
netlink_get_response(FAR struct netlink_conn_s *conn);
int netlink_get_response(FAR struct netlink_conn_s *conn,
FAR struct netlink_response_s **response);

/****************************************************************************
* Name: netlink_check_response
Expand Down
26 changes: 15 additions & 11 deletions net/netlink/netlink_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,23 @@ netlink_tryget_response(FAR struct netlink_conn_s *conn)
* Note: The network will be momentarily locked to support exclusive
* access to the pending response list.
*
* Input Parameters:
* conn - The Netlink connection
* response - The next response from the head of the pending response list
* is returned. This function will block until a response is
* received if the pending response list is empty. NULL will be
* returned only in the event of a failure.
*
* Returned Value:
* The next response from the head of the pending response list is
* returned. This function will block until a response is received if
* the pending response list is empty. NULL will be returned only in the
* event of a failure.
* Zero (OK) is returned if the notification was successfully set up.
* A negated error value is returned if an unexpected error occurred
*
****************************************************************************/

FAR struct netlink_response_s *
netlink_get_response(FAR struct netlink_conn_s *conn)
int netlink_get_response(FAR struct netlink_conn_s *conn,
FAR struct netlink_response_s **response)
{
FAR struct netlink_response_s *resp;
int ret;
int ret = OK;

DEBUGASSERT(conn != NULL);

Expand All @@ -425,7 +429,7 @@ netlink_get_response(FAR struct netlink_conn_s *conn)
*/

net_lock();
while ((resp = netlink_tryget_response(conn)) == NULL)
while ((*response = netlink_tryget_response(conn)) == NULL)
{
sem_t waitsem;

Expand All @@ -447,7 +451,7 @@ netlink_get_response(FAR struct netlink_conn_s *conn)
{
/* Wait for a response to be queued */

nxsem_post(&waitsem);
ret = net_sem_wait(&waitsem);
}

/* Clean-up the semaphore */
Expand All @@ -464,7 +468,7 @@ netlink_get_response(FAR struct netlink_conn_s *conn)
}

net_unlock();
return resp;
return ret;
}

/****************************************************************************
Expand Down
11 changes: 7 additions & 4 deletions net/netlink/netlink_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ static ssize_t netlink_recvmsg(FAR struct socket *psock,
FAR socklen_t *fromlen = &msg->msg_namelen;
FAR struct netlink_response_s *entry;
FAR struct socket_conn_s *conn;
int ret = OK;

DEBUGASSERT(from == NULL ||
(fromlen != NULL && *fromlen >= sizeof(struct sockaddr_nl)));
Expand All @@ -678,13 +679,15 @@ static ssize_t netlink_recvmsg(FAR struct socket *psock,
return -EAGAIN;
}

/* Wait for the response. This should always succeed. */
/* Wait for the response. */

ret = netlink_get_response(psock->s_conn, &entry);

/* If interrupted by signals, return errno */

entry = netlink_get_response(psock->s_conn);
DEBUGASSERT(entry != NULL);
if (entry == NULL)
{
return -EPIPE;
return ret;
}
}

Expand Down

0 comments on commit fe2dc34

Please sign in to comment.