summaryrefslogtreecommitdiff
path: root/nuttx/net/net_dup.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-07-19 00:14:46 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-07-19 00:14:46 +0000
commit17553d10657c2a395a2ab1f7d6629453fc5ed342 (patch)
treea32ae4f4d40e07e38093273770ff0989b50935db /nuttx/net/net_dup.c
parent3f09faeeeb7c23c496df9e3790fd3425429adddc (diff)
downloadpx4-nuttx-17553d10657c2a395a2ab1f7d6629453fc5ed342.tar.gz
px4-nuttx-17553d10657c2a395a2ab1f7d6629453fc5ed342.tar.bz2
px4-nuttx-17553d10657c2a395a2ab1f7d6629453fc5ed342.zip
Add fcntl(F_DUPFD)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1995 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/net_dup.c')
-rw-r--r--nuttx/net/net_dup.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/nuttx/net/net_dup.c b/nuttx/net/net_dup.c
index f4ee15abe..e935e4749 100644
--- a/nuttx/net/net_dup.c
+++ b/nuttx/net/net_dup.c
@@ -50,11 +50,15 @@
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
* Global Functions
****************************************************************************/
/****************************************************************************
- * Function: net_dup OR dup
+ * Function: net_dup
*
* Description:
* Clone a socket descriptor to an arbitray descriptor number. If file
@@ -64,11 +68,7 @@
*
****************************************************************************/
-#if CONFIG_NFILE_DESCRIPTOR > 0
-int net_dup(int sockfd)
-#else
-int dup(int sockfd)
-#endif
+int net_dup(int sockfd, int minsd)
{
FAR struct socket *psock1 = sockfd_socket(sockfd);
FAR struct socket *psock2;
@@ -76,6 +76,22 @@ int dup(int sockfd)
int err;
int ret;
+ /* Make sure that the minimum socket descriptor is within the legal range.
+ * the minimum value we receive is relative to file descriptor 0; we need
+ * map it relative of the first socket descriptor.
+ */
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+ if (minsd >= CONFIG_NFILE_DESCRIPTORS)
+ {
+ minsd -= CONFIG_NFILE_DESCRIPTORS;
+ }
+ else
+ {
+ minsd = 0;
+ }
+#endif
+
/* Lock the scheduler throughout the following */
sched_lock();
@@ -94,7 +110,7 @@ int dup(int sockfd)
/* Allocate a new socket descriptor */
- sockfd2 = sockfd_allocate();
+ sockfd2 = sockfd_allocate(minsd);
if (sockfd2 < 0)
{
err = ENFILE;