Fix the bug that netlink receive wait does not hang up
Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
This commit is contained in:
parent
ff0194fb74
commit
84f326a66b
@ -457,16 +457,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
|
||||
|
@ -485,19 +485,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);
|
||||
|
||||
@ -507,7 +511,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;
|
||||
|
||||
@ -529,7 +533,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 */
|
||||
@ -546,7 +550,7 @@ netlink_get_response(FAR struct netlink_conn_s *conn)
|
||||
}
|
||||
|
||||
net_unlock();
|
||||
return resp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -674,6 +674,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)));
|
||||
@ -694,13 +695,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user