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 file *filep;
|
||||
@ -196,12 +206,7 @@ FAR struct socket *sockfd_socket(int sockfd)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (INODE_IS_SOCKET(filep->f_inode))
|
||||
{
|
||||
return filep->f_priv;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return file_socket(filep);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -56,6 +56,20 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
|
||||
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)
|
||||
{
|
||||
case F_DUPFD:
|
||||
@ -239,27 +253,11 @@ static int nx_vfcntl(int fd, int cmd, va_list ap)
|
||||
{
|
||||
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
|
||||
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);
|
||||
}
|
||||
ret = file_vfcntl(filep, cmd, ap);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -191,6 +191,15 @@ int file_fstat(FAR struct file *filep, FAR struct stat *buf)
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
|
||||
#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 */
|
||||
|
||||
ret = file_fstat(filep, buf);
|
||||
|
@ -168,6 +168,7 @@ typedef uint8_t sockcaps_t;
|
||||
*/
|
||||
|
||||
struct file; /* Forward reference */
|
||||
struct stat; /* Forward reference */
|
||||
struct socket; /* 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);
|
||||
|
||||
/****************************************************************************
|
||||
@ -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);
|
||||
|
||||
/****************************************************************************
|
||||
@ -1379,7 +1379,6 @@ int psock_fstat(FAR struct socket *psock, FAR struct stat *buf);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
struct file;
|
||||
ssize_t psock_sendfile(FAR struct socket *psock, FAR struct file *infile,
|
||||
FAR off_t *offset, size_t count);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user