diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-06-15 19:50:06 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-06-15 19:50:06 +0000 |
commit | 8e8a4c5677c081b145768538d9944d817e3985c8 (patch) | |
tree | 2b6a33844e017512f530187deac45579988f248f | |
parent | f2675bf333e0378c842717a94a13c73dabb76a52 (diff) | |
download | nuttx-8e8a4c5677c081b145768538d9944d817e3985c8.tar.gz nuttx-8e8a4c5677c081b145768538d9944d817e3985c8.tar.bz2 nuttx-8e8a4c5677c081b145768538d9944d817e3985c8.zip |
Add logic to clone socket descriptors when a new task is started.
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1885 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/ChangeLog | 7 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 5 | ||||
-rw-r--r-- | nuttx/Documentation/NuttxPortingGuide.html | 15 | ||||
-rw-r--r-- | nuttx/TODO | 15 | ||||
-rw-r--r-- | nuttx/configs/README.txt | 8 | ||||
-rw-r--r-- | nuttx/include/nuttx/net.h | 23 | ||||
-rw-r--r-- | nuttx/net/net_clone.c | 2 | ||||
-rw-r--r-- | nuttx/net/net_internal.h | 4 | ||||
-rw-r--r-- | nuttx/sched/sched_setuptaskfiles.c | 52 |
9 files changed, 114 insertions, 17 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 3fac74613..027d3f90b 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -776,4 +776,11 @@ 0.4.8 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Add strtoll() and strtoull(); Add macros for atol() and atoll(). + * dup() and dup2() will now clone socket descriptors + * All socket descriptors ar now cloned when when a new task is started + via task_create(). + * Add configuration options to suppress or eliminate cloning of file + and/or socket descriptors when a new task is started by task_create(): + CONFIG_FDCLONE_DISABLE, CONFIG_FDCLONE_STDIO, CONFIG_SDCLONE_DISABLE. + diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 044938d8d..f47a76af8 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: June 14, 2009</p> + <p>Last Updated: June 15, 2009</p> </td> </tr> </table> @@ -1471,6 +1471,9 @@ buildroot-0.1.6 2009-xx-xx <spudmonkey@racsa.co.cr> nuttx-0.4.9 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Add strtoll() and strtoull(); Add macros for atol() and atoll(). + * dup() and dup2() will now clone socket descriptors + * All socket descriptors ar now cloned when when a new task is started + via task_create(). pascal-0.1.3 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index 02155fe12..23eeb5cb9 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -12,7 +12,7 @@ <h1><big><font color="#3c34ec"> <i>NuttX RTOS Porting Guide</i> </font></big></h1> - <p>Last Updated: May 28, 2009</p> + <p>Last Updated: June 15, 2009</p> </td> </tr> </table> @@ -2065,6 +2065,19 @@ extern void up_ledoff(int led); This value may be set to zero if no more than one thread is expected to wait for a semaphore. </li> + <li> + <code>CONFIG_FDCLONE_DISABLE</code>: Disable cloning of all file descriptors + by task_create() when a new task is started. + </li> + <li> + <code>CONFIG_FDCLONE_STDIO</code>: Disable cloning of all but the first + three file descriptors (stdin, stdout, stderr) by task_create() + when a new task is started. + </li> + <li> + <code>CONFIG_SDCLONE_DISABLE</code>: Disable cloning of all socket + desciptors by task_create() when a new task is started. + </li> </ul> <p> diff --git a/nuttx/TODO b/nuttx/TODO index 78c687000..2ef600736 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -17,7 +17,7 @@ NuttX TODO List (Last updated April 12, 2009) (6) Build system / Toolchains (2) NuttShell (NSH) (examples/nsh) (3) Other Applications & Tests (examples/) - (1) Linux/Cywgin simulation (arch/sim) + (2) Linux/Cywgin simulation (arch/sim) (3) ARM (arch/arm/) (1) ARM/C5471 (arch/arm/src/c5471/) (3) ARM/DM320 (arch/arm/src/dm320/) @@ -60,11 +60,6 @@ o Task/Scheduler (sched/) Priority: Medium, required for standard compliance (but makes the code bigger) - Description: socket descriptors are not cloned as are file descriptors - by task_create(). - Status: Open - Priority: Medium-to-High - o Dynamic Loader ^^^^^^^^^^^^^^ @@ -409,6 +404,14 @@ o Linux/Cywgin simulation (arch/sim) Status: Open Priority: Low (because the simulator is only a test/development platform) + Description: Simulator does not build correctly on 64-bit machines. Two + issues: + 1) It saves addresses in 32-bit types and these fail when cast + to pointers on a 64-bit host. + 2) up_setjmp.S does not build + Status: Open + Priority: Medium and increasing (as 32-bit hosts gradually disappear) + o ARM (arch/arm/) ^^^^^^^^^^^^^^^ diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index 36c422f46..a5c6ca9d4 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -215,6 +215,13 @@ defconfig -- This is a configuration file similar to the Linux to release a count on a semaphore. This value may be set to zero if no more than one thread is expected to wait for a semaphore. + CONFIG_FDCLONE_DISABLE. Disable cloning of all file descriptors + by task_create() when a new task is started. + CONFIG_FDCLONE_STDIO. Disable cloning of all but the first + three file descriptors (stdin, stdout, stderr) by task_create() + when a new task is started. + CONFIG_SDCLONE_DISABLE. Disable cloning of all socket + desciptors by task_create() when a new task is started. The following can be used to disable categories of APIs supported by the OS. If the compiler supports weak functions, then it @@ -232,7 +239,6 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_DISABLE_SIGNALS, CONFIG_DISABLE_MQUEUE, CONFIG_DISABLE_MOUNTPOUNT, CONFIG_DISABLE_ENVIRON, CONFIG_DISABLE_POLL - Misc libc settings CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a diff --git a/nuttx/include/nuttx/net.h b/nuttx/include/nuttx/net.h index 9b83971df..55ff9885e 100644 --- a/nuttx/include/nuttx/net.h +++ b/nuttx/include/nuttx/net.h @@ -164,12 +164,31 @@ EXTERN int net_poll(int sockfd, struct pollfd *fds, boolean setup); #endif /* net_dup.c *****************************************************************/ -/* The standard dup() and dup2() operations redirect operations on socket - * descriptors to these function. +/* The standard dup() operation redirects operations on socket descriptors to + * this function (when both file and socket descriptors are supported) */ +#if CONFIG_NFILE_DESCRIPTOR > 0 EXTERN int net_dup(int sockfd); +#else +# define net_dup(sockfd) dup(sockfd) +#endif + +/* net_dup2.c ****************************************************************/ +/* The standard dup2() operation redirects operations on socket descriptors to + * this function (when both file and socket descriptors are supported) + */ + +#if CONFIG_NFILE_DESCRIPTOR > 0 EXTERN int net_dup2(int sockfd1, int sockfd2); +#else +# define net_dup2(sockfd1, sockfd2) dup2(sockfd1, sockfd2) +#endif + +/* net_clone.c ***************************************************************/ +/* Performs the low level, common portion of net_dup() and net_dup2() */ + +EXTERN int net_clone(FAR struct socket *psock1, FAR struct socket *psock2); /* netdev-register.c *********************************************************/ /* This function is called by network interface device drivers to inform the diff --git a/nuttx/net/net_clone.c b/nuttx/net/net_clone.c index e23016073..a86e8cb11 100644 --- a/nuttx/net/net_clone.c +++ b/nuttx/net/net_clone.c @@ -85,6 +85,8 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2) /* Increment the reference count on the connection */ + DEBUGASSERT(psock2->s_conn); + #ifdef CONFIG_NET_TCP if (psock2->s_type == SOCK_STREAM) { diff --git a/nuttx/net/net_internal.h b/nuttx/net/net_internal.h index ea3fdd5a6..9afa408be 100644 --- a/nuttx/net/net_internal.h +++ b/nuttx/net/net_internal.h @@ -156,10 +156,6 @@ EXTERN socktimeo_t net_timeval2dsec(struct timeval *tv); EXTERN void net_dsec2timeval(uint16 dsec, struct timeval *tv); #endif -/* net_clone.c ***************************************************************/ - -EXTERN int net_clone(FAR struct socket *psock1, FAR struct socket *psock2); - /* net_register.c ************************************************************/ #if CONFIG_NSOCKET_DESCRIPTORS > 0 diff --git a/nuttx/sched/sched_setuptaskfiles.c b/nuttx/sched/sched_setuptaskfiles.c index e472528fd..23a820a96 100644 --- a/nuttx/sched/sched_setuptaskfiles.c +++ b/nuttx/sched/sched_setuptaskfiles.c @@ -50,6 +50,22 @@ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 /**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Determine how many file descriptors to clone. If CONFIG_FDCLONE_DISABLE + * is set, no file descriptors will be cloned. If CONFIG_FDCLONE_STDIO is + * set, only the first three descriptors (stdin, stdout, and stderr) will + * be cloned. Otherwise all file descriptors will be cloned. + */ + +#if defined(CONFIG_FDCLONE_STDIO) && CONFIG_NFILE_DESCRIPTORS > 3 +# define NFDS_TOCLONE 3 +#else +# define NFDS_TOCLONE CONFIG_NFILE_DESCRIPTORS +#endif + +/**************************************************************************** * Private Functions ****************************************************************************/ @@ -83,6 +99,7 @@ int sched_setuptaskfiles(FAR _TCB *tcb) int ret = OK; #if CONFIG_NFILE_DESCRIPTORS > 0 + /* Allocate file descriptors for the TCB */ tcb->filelist = files_alloclist(); @@ -91,9 +108,11 @@ int sched_setuptaskfiles(FAR _TCB *tcb) *get_errno_ptr() = ENOMEM; return ERROR; } + #endif /* CONFIG_NFILE_DESCRIPTORS */ #if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Allocate socket descriptors for the TCB */ tcb->sockets = net_alloclist(); @@ -102,14 +121,21 @@ int sched_setuptaskfiles(FAR _TCB *tcb) *get_errno_ptr() = ENOMEM; return ERROR; } + #endif /* CONFIG_NSOCKET_DESCRIPTORS */ #if CONFIG_NFILE_DESCRIPTORS > 0 - /* Duplicate the file descriptors */ +#if !defined(CONFIG_FDCLONE_DISABLE) + + /* Duplicate the file descriptors. This will be either all of the + * file descriptors or just the first three (stdin, stdout, and stderr) + * if CONFIG_FDCLONE_STDIO is defined. NFSDS_TOCLONE is set + * accordingly above. + */ if (rtcb->filelist) { - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + for (i = 0; i < NFDS_TOCLONE; i++) { /* Check if this file is opened */ @@ -120,13 +146,35 @@ int sched_setuptaskfiles(FAR _TCB *tcb) } } } +#endif #if CONFIG_NFILE_STREAMS > 0 + /* Allocate file streams for the TCB */ ret = sched_setupstreams(tcb); + #endif /* CONFIG_NFILE_STREAMS */ #endif /* CONFIG_NFILE_DESCRIPTORS */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 && !defined(CONFIG_SDCLONE_DISABLE) + + /* Duplicate the socket descriptors */ + + if (rtcb->sockets) + { + for (i = 0; i < CONFIG_NSOCKET_DESCRIPTORS; i++) + { + /* Check if this socket is allocated */ + + if (rtcb->sockets->sl_sockets[i].s_crefs > 0) + { + (void)net_clone(&rtcb->sockets->sl_sockets[i], + &tcb->sockets->sl_sockets[i]); + } + } + } +#endif return ret; } |