mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 01:05:54 +08:00
Revert "net: unify socket info file descriptor"
This reverts commit 27b332283e.
This commit is contained in:
+1
-1
@@ -128,7 +128,7 @@ struct aiocb
|
||||
FAR volatile void *aio_buf; /* Location of buffer */
|
||||
off_t aio_offset; /* File offset */
|
||||
size_t aio_nbytes; /* Length of transfer */
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 127
|
||||
#if (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) > 127
|
||||
int16_t aio_fildes; /* File descriptor (should be int) */
|
||||
#else
|
||||
int8_t aio_fildes; /* File descriptor (should be int) */
|
||||
|
||||
@@ -114,7 +114,6 @@
|
||||
#define FSNODEFLAG_TYPE_SHM 0x00000006 /* Shared memory region */
|
||||
#define FSNODEFLAG_TYPE_MTD 0x00000007 /* Named MTD driver */
|
||||
#define FSNODEFLAG_TYPE_SOFTLINK 0x00000008 /* Soft link */
|
||||
#define FSNODEFLAG_TYPE_SOCKET 0x00000009 /* Socket */
|
||||
#define FSNODEFLAG_DELETED 0x00000010 /* Unlinked */
|
||||
|
||||
#define INODE_IS_TYPE(i,t) \
|
||||
@@ -129,7 +128,6 @@
|
||||
#define INODE_IS_SHM(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_SHM)
|
||||
#define INODE_IS_MTD(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_MTD)
|
||||
#define INODE_IS_SOFTLINK(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_SOFTLINK)
|
||||
#define INODE_IS_SOCKET(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_SOCKET)
|
||||
|
||||
#define INODE_GET_TYPE(i) ((i)->i_flags & FSNODEFLAG_TYPE_MASK)
|
||||
#define INODE_SET_TYPE(i,t) \
|
||||
@@ -147,7 +145,6 @@
|
||||
#define INODE_SET_SHM(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_SHM)
|
||||
#define INODE_SET_MTD(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_MTD)
|
||||
#define INODE_SET_SOFTLINK(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_SOFTLINK)
|
||||
#define INODE_SET_SOCKET(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_SOCKET)
|
||||
|
||||
/* Mountpoint fd_flags values */
|
||||
|
||||
|
||||
+194
-20
@@ -96,6 +96,7 @@
|
||||
/* Definitions of 8-bit socket flags */
|
||||
|
||||
#define _SF_INITD 0x01 /* Bit 0: Socket structure is initialized */
|
||||
#define _SF_CLOEXEC 0x04 /* Bit 2: Close on execute */
|
||||
#define _SF_NONBLOCK 0x08 /* Bit 3: Don't block if no data (TCP/READ only) */
|
||||
#define _SF_LISTENING 0x10 /* Bit 4: SOCK_STREAM is listening */
|
||||
#define _SF_BOUND 0x20 /* Bit 5: SOCK_STREAM is bound to an address */
|
||||
@@ -114,6 +115,7 @@
|
||||
/* Macro to manage the socket state and flags */
|
||||
|
||||
#define _SS_INITD(s) (((s) & _SF_INITD) != 0)
|
||||
#define _SS_ISCLOEXEC(s) (((s) & _SF_CLOEXEC) != 0)
|
||||
#define _SS_ISNONBLOCK(s) (((s) & _SF_NONBLOCK) != 0)
|
||||
#define _SS_ISLISTENING(s) (((s) & _SF_LISTENING) != 0)
|
||||
#define _SS_ISBOUND(s) (((s) & _SF_BOUND) != 0)
|
||||
@@ -123,7 +125,7 @@
|
||||
/* Determine if a socket is valid. Valid means both (1) allocated and (2)
|
||||
* successfully initialized:
|
||||
*
|
||||
* Allocated: psock->s_conn != NULL
|
||||
* Allocated: psock->s_crefs > 0
|
||||
* Initialized: _SF_INITD bit set in psock->s_flags
|
||||
*
|
||||
* This logic is used within the OS to pick the sockets to be cloned when a
|
||||
@@ -132,7 +134,7 @@
|
||||
* pthread.
|
||||
*/
|
||||
|
||||
#define _PS_ALLOCD(psock) ((psock)->s_conn != NULL)
|
||||
#define _PS_ALLOCD(psock) ((psock)->s_crefs > 0)
|
||||
#define _PS_INITD(psock) (_SS_INITD((psock)->s_flags))
|
||||
#define _PS_VALID(psock) (_PS_ALLOCD(psock) && _PS_INITD(psock))
|
||||
|
||||
@@ -260,6 +262,7 @@ struct devif_callback_s; /* Forward reference */
|
||||
|
||||
struct socket
|
||||
{
|
||||
int16_t s_crefs; /* Reference count on the socket */
|
||||
uint8_t s_domain; /* IP domain */
|
||||
uint8_t s_type; /* Protocol type */
|
||||
uint8_t s_proto; /* Socket Protocol */
|
||||
@@ -294,6 +297,16 @@ struct socket
|
||||
#endif
|
||||
};
|
||||
|
||||
/* This defines a list of sockets indexed by the socket descriptor */
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
struct socketlist
|
||||
{
|
||||
sem_t sl_sem; /* Manage access to the socket list */
|
||||
struct socket sl_sockets[CONFIG_NSOCKET_DESCRIPTORS];
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
@@ -511,21 +524,51 @@ FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sockfd_allocate
|
||||
* Name: net_checksd
|
||||
*
|
||||
* Description:
|
||||
* Allocate a socket descriptor
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A double pointer to socket structure to be allocated.
|
||||
*
|
||||
* Returned Value:
|
||||
* Allocate a struct files instance and associate it with an socket
|
||||
* instance. Returns the file descriptor == index into the files array.
|
||||
* Check if the socket descriptor is valid for the provided TCB and if it
|
||||
* supports the requested access. This trivial operation is part of the
|
||||
* fdopen() operation when the fdopen() is performed on a socket
|
||||
* descriptor. It simply performs some sanity checking before permitting
|
||||
* the socket descriptor to be wrapped as a C FILE stream.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sockfd_allocate(FAR struct socket **psock);
|
||||
int net_checksd(int fd, int oflags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_initlist
|
||||
*
|
||||
* Description:
|
||||
* Initialize a list of sockets for a new task
|
||||
*
|
||||
* Input Parameters:
|
||||
* list -- A reference to the pre-alloated socket list to be initialized.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void net_initlist(FAR struct socketlist *list);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_releaselist
|
||||
*
|
||||
* Description:
|
||||
* Release resources held by the socket list
|
||||
*
|
||||
* Input Parameters:
|
||||
* list -- A reference to the pre-allocated socket list to be un-
|
||||
* initialized.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void net_releaselist(FAR struct socketlist *list);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sockfd_socket
|
||||
@@ -587,6 +630,25 @@ FAR struct socket *sockfd_socket(int sockfd);
|
||||
int psock_socket(int domain, int type, int protocol,
|
||||
FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_close
|
||||
*
|
||||
* Description:
|
||||
* Performs the close operation on socket descriptors
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd Socket descriptor of socket
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns zero (OK) on success. On failure, it returns a negated errno
|
||||
* value to indicate the nature of the error.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_close(int sockfd);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_close
|
||||
*
|
||||
@@ -1229,6 +1291,39 @@ int psock_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
|
||||
int psock_vioctl(FAR struct socket *psock, int cmd, va_list ap);
|
||||
int psock_ioctl(FAR struct socket *psock, int cmd, ...);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_vioctl
|
||||
*
|
||||
* Description:
|
||||
* Perform network device specific operations.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd Socket descriptor of device
|
||||
* cmd The ioctl command
|
||||
* ap The argument of the ioctl cmd
|
||||
*
|
||||
* Returned Value:
|
||||
* A non-negative value is returned on success; a negated errno value is
|
||||
* returned on any failure to indicate the nature of the failure:
|
||||
*
|
||||
* EBADF
|
||||
* 'sockfd' is not a valid socket descriptor.
|
||||
* EFAULT
|
||||
* 'arg' references an inaccessible memory area.
|
||||
* ENOTTY
|
||||
* 'cmd' not valid.
|
||||
* EINVAL
|
||||
* 'arg' is not valid.
|
||||
* ENOTTY
|
||||
* 'sockfd' is not associated with a network device.
|
||||
* ENOTTY
|
||||
* The specified request does not apply to the kind of object that the
|
||||
* descriptor 'sockfd' references.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int netdev_vioctl(int sockfd, int cmd, va_list ap);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_poll
|
||||
*
|
||||
@@ -1252,10 +1347,32 @@ struct pollfd; /* Forward reference -- see poll.h */
|
||||
int psock_poll(FAR struct socket *psock, struct pollfd *fds, bool setup);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_dup2
|
||||
* Name: net_poll
|
||||
*
|
||||
* Description:
|
||||
* Clone a socket instance to an new instance.
|
||||
* The standard poll() operation redirects operations on socket descriptors
|
||||
* to this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The socket descriptor of interest
|
||||
* fds - The structure describing the events to be monitored, OR NULL if
|
||||
* this is a request to stop monitoring events.
|
||||
* setup - true: Setup up the poll; false: Teardown the poll
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: Success; Negated errno on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct pollfd; /* Forward reference -- see poll.h */
|
||||
|
||||
int net_poll(int sockfd, struct pollfd *fds, bool setup);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_dup
|
||||
*
|
||||
* Description:
|
||||
* Clone a socket descriptor to an arbitrary descriptor number.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of new socket. On any error,
|
||||
@@ -1263,16 +1380,54 @@ int psock_poll(FAR struct socket *psock, struct pollfd *fds, bool setup);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int psock_dup(FAR struct socket *psock, int minsd);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_dup
|
||||
*
|
||||
* Description:
|
||||
* Clone a socket descriptor to an arbitrary descriptor number.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of new socket. On any error,
|
||||
* a negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_dup(int sockfd, int minsd);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_dup2
|
||||
*
|
||||
* Description:
|
||||
* Performs the low level, common portion of net_dup() and net_dup2()
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_fstat
|
||||
* Name: net_dup2
|
||||
*
|
||||
* Description:
|
||||
* Clone a socket descriptor to an arbitrary descriptor number.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_dup2(int sockfd1, int sockfd2);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_fstat
|
||||
*
|
||||
* Description:
|
||||
* Performs fstat operations on socket
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* sockfd - Socket descriptor of the socket to operate on
|
||||
* buf - Caller-provided location in which to return the fstat data
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -1283,10 +1438,10 @@ 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 net_fstat(int sockfd, FAR struct stat *buf);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_sendfile
|
||||
* Name: net_sendfile
|
||||
*
|
||||
* Description:
|
||||
* The send() call may be used only when the socket is in a connected state
|
||||
@@ -1349,8 +1504,8 @@ 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);
|
||||
ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset,
|
||||
size_t count);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -1393,6 +1548,25 @@ int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap);
|
||||
|
||||
int psock_fcntl(FAR struct socket *psock, int cmd, ...);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_vfcntl
|
||||
*
|
||||
* Description:
|
||||
* Performs fcntl operations on socket
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of the socket to operate on
|
||||
* cmd - The fcntl command.
|
||||
* ap - Command-specific arguments
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* any failure to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_vfcntl(int sockfd, int cmd, va_list ap);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_register
|
||||
*
|
||||
|
||||
@@ -594,6 +594,12 @@ struct task_group_s
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
/* Sockets ********************************************************************/
|
||||
|
||||
struct socketlist tg_socketlist; /* Maps socket descriptor to socket */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
/* Address Environment ********************************************************/
|
||||
|
||||
@@ -904,6 +910,10 @@ FAR struct filelist *nxsched_get_files(void);
|
||||
FAR struct streamlist *nxsched_get_streams(void);
|
||||
#endif /* CONFIG_FILE_STREAM */
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
FAR struct socketlist *nxsched_get_sockets(void);
|
||||
#endif
|
||||
|
||||
/********************************************************************************
|
||||
* Name: nxtask_init
|
||||
*
|
||||
|
||||
+2
-1
@@ -93,7 +93,8 @@
|
||||
|
||||
#define POLLFD (0x00)
|
||||
#define POLLFILE (0x40)
|
||||
#define POLLMASK (0x40)
|
||||
#define POLLSOCK (0x80)
|
||||
#define POLLMASK (0xC0)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
|
||||
@@ -52,7 +52,11 @@
|
||||
|
||||
/* Get the total number of descriptors that we will have to support */
|
||||
|
||||
#define FD_SETSIZE CONFIG_NFILE_DESCRIPTORS
|
||||
#ifdef CONFIG_NSOCKET_DESCRIPTORS
|
||||
# define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)
|
||||
#else
|
||||
# define FD_SETSIZE CONFIG_NFILE_DESCRIPTORS
|
||||
#endif
|
||||
|
||||
/* We will use a 32-bit bitsets to represent the set of descriptors. How
|
||||
* many uint32_t's do we need to span all descriptors?
|
||||
|
||||
Reference in New Issue
Block a user