Move psock check from [get|set]sockopt to psock_[get|set]sockopt

This commit is contained in:
Xiang Xiao 2018-08-26 14:25:54 -06:00 committed by Gregory Nutt
parent 655be281e6
commit bcf9360e5f
3 changed files with 15 additions and 12 deletions

View File

@ -41,6 +41,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
#include <semaphore.h>

View File

@ -101,6 +101,13 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
return -EINVAL;
}
/* Verify that the sockfd corresponds to valid, allocated socket */
if (psock == NULL || psock->s_crefs <= 0)
{
return -EBADF;
}
#ifdef CONFIG_NET_USRSOCK
if (psock->s_type == SOCK_USRSOCK_TYPE)
{
@ -410,14 +417,8 @@ int getsockopt(int sockfd, int level, int option, void *value, socklen_t *value_
int ret;
/* Get the underlying socket structure */
/* Verify that the sockfd corresponds to valid, allocated socket */
psock = sockfd_socket(sockfd);
if (!psock || psock->s_crefs <= 0)
{
set_errno(EBADF);
return ERROR;
}
/* Then let psock_getsockopt() do all of the work */

View File

@ -95,6 +95,13 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
return -EINVAL;
}
/* Verify that the sockfd corresponds to valid, allocated socket */
if (psock == NULL || psock->s_crefs <= 0)
{
return -EBADF;
}
#ifdef CONFIG_NET_USRSOCK
if (psock->s_type == SOCK_USRSOCK_TYPE)
{
@ -450,14 +457,8 @@ int setsockopt(int sockfd, int level, int option, const void *value, socklen_t v
int ret;
/* Get the underlying socket structure */
/* Verify that the sockfd corresponds to valid, allocated socket */
psock = sockfd_socket(sockfd);
if (!psock || psock->s_crefs <= 0)
{
set_errno(EBADF);
return ERROR;
}
/* Then let psock_setockopt() do all of the work */