diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h index c2b83ed0fa6f0..b12cf9647a3eb 100644 --- a/net/netlink/netlink.h +++ b/net/netlink/netlink.h @@ -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 diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c index 39f7fcc861ed6..f68d79791d7fc 100644 --- a/net/netlink/netlink_conn.c +++ b/net/netlink/netlink_conn.c @@ -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); @@ -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; @@ -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 */ @@ -464,7 +468,7 @@ netlink_get_response(FAR struct netlink_conn_s *conn) } net_unlock(); - return resp; + return ret; } /**************************************************************************** diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c index abfa27d9fc523..d1eb6f03884f4 100644 --- a/net/netlink/netlink_sockif.c +++ b/net/netlink/netlink_sockif.c @@ -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))); @@ -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; } }