net: Add file_socket function
and move the socket special process from fstat/nx_vfcntl/ to file_fstat/file_vfcntl Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: Ia10341538488ba3a8444df8e73fb5257b2a1f512
This commit is contained in:
parent
a44f62ddf7
commit
2e0901fcaa
@ -187,6 +187,16 @@ int sockfd_allocate(FAR struct socket *psock, int oflags)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
FAR struct socket *file_socket(FAR struct file *filep)
|
||||||
|
{
|
||||||
|
if (filep != NULL && INODE_IS_SOCKET(filep->f_inode))
|
||||||
|
{
|
||||||
|
return filep->f_priv;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
FAR struct socket *sockfd_socket(int sockfd)
|
FAR struct socket *sockfd_socket(int sockfd)
|
||||||
{
|
{
|
||||||
FAR struct file *filep;
|
FAR struct file *filep;
|
||||||
@ -196,12 +206,7 @@ FAR struct socket *sockfd_socket(int sockfd)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (INODE_IS_SOCKET(filep->f_inode))
|
return file_socket(filep);
|
||||||
{
|
|
||||||
return filep->f_priv;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -56,6 +56,20 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
|
|||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check for operations on a socket descriptor */
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET
|
||||||
|
if (INODE_IS_SOCKET(filep->f_inode) &&
|
||||||
|
cmd != F_DUPFD && cmd != F_GETFD && cmd != F_SETFD)
|
||||||
|
{
|
||||||
|
/* Yes.. defer socket descriptor operations to
|
||||||
|
* psock_vfcntl(). The errno is not set on failures.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return psock_vfcntl(file_socket(filep), cmd, ap);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case F_DUPFD:
|
case F_DUPFD:
|
||||||
@ -239,27 +253,11 @@ static int nx_vfcntl(int fd, int cmd, va_list ap)
|
|||||||
{
|
{
|
||||||
DEBUGASSERT(filep != NULL);
|
DEBUGASSERT(filep != NULL);
|
||||||
|
|
||||||
/* check for operations on a socket descriptor */
|
/* Let file_vfcntl() do the real work. The errno is not set on
|
||||||
|
* failures.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_NET
|
ret = file_vfcntl(filep, cmd, ap);
|
||||||
if (INODE_IS_SOCKET(filep->f_inode) &&
|
|
||||||
cmd != F_DUPFD && cmd != F_GETFD && cmd != F_SETFD)
|
|
||||||
{
|
|
||||||
/* Yes.. defer socket descriptor operations to
|
|
||||||
* psock_vfcntl(). The errno is not set on failures.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = psock_vfcntl(sockfd_socket(fd), cmd, ap);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Let file_vfcntl() do the real work. The errno is not set on
|
|
||||||
* failures.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = file_vfcntl(filep, cmd, ap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -191,6 +191,15 @@ int file_fstat(FAR struct file *filep, FAR struct stat *buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_NET
|
||||||
|
if (INODE_IS_SOCKET(inode))
|
||||||
|
{
|
||||||
|
/* Let the networking logic handle the fstat() */
|
||||||
|
|
||||||
|
ret = psock_fstat(file_socket(filep), buf);
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* Check if the inode is a proxy for a block or MTD driver */
|
/* Check if the inode is a proxy for a block or MTD driver */
|
||||||
@ -244,21 +253,6 @@ int fstat(int fd, FAR struct stat *buf)
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_NET
|
|
||||||
if (INODE_IS_SOCKET(filep->f_inode))
|
|
||||||
{
|
|
||||||
/* Let the networking logic handle the fstat() */
|
|
||||||
|
|
||||||
ret = psock_fstat(sockfd_socket(fd), buf);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Perform the fstat operation */
|
/* Perform the fstat operation */
|
||||||
|
|
||||||
ret = file_fstat(filep, buf);
|
ret = file_fstat(filep, buf);
|
||||||
|
@ -168,6 +168,7 @@ typedef uint8_t sockcaps_t;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct file; /* Forward reference */
|
struct file; /* Forward reference */
|
||||||
|
struct stat; /* Forward reference */
|
||||||
struct socket; /* Forward reference */
|
struct socket; /* Forward reference */
|
||||||
struct pollfd; /* Forward reference */
|
struct pollfd; /* Forward reference */
|
||||||
|
|
||||||
@ -521,6 +522,7 @@ int sockfd_allocate(FAR struct socket *psock, int oflags);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
FAR struct socket *file_socket(FAR struct file *filep);
|
||||||
FAR struct socket *sockfd_socket(int sockfd);
|
FAR struct socket *sockfd_socket(int sockfd);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -1312,8 +1314,6 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
struct stat; /* Forward reference. See sys/stat.h */
|
|
||||||
|
|
||||||
int psock_fstat(FAR struct socket *psock, FAR struct stat *buf);
|
int psock_fstat(FAR struct socket *psock, FAR struct stat *buf);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -1379,7 +1379,6 @@ int psock_fstat(FAR struct socket *psock, FAR struct stat *buf);
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_SENDFILE
|
#ifdef CONFIG_NET_SENDFILE
|
||||||
struct file;
|
|
||||||
ssize_t psock_sendfile(FAR struct socket *psock, FAR struct file *infile,
|
ssize_t psock_sendfile(FAR struct socket *psock, FAR struct file *infile,
|
||||||
FAR off_t *offset, size_t count);
|
FAR off_t *offset, size_t count);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user