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
This commit is contained in:
patacongo
2009-06-15 19:50:06 +00:00
parent fdf76b48bc
commit e9711ca1a7
9 changed files with 114 additions and 17 deletions
+7
View File
@@ -776,4 +776,11 @@
0.4.8 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> 0.4.8 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* Add strtoll() and strtoull(); Add macros for atol() and atoll(). * 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.
+4 -1
View File
@@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4"> <tr align="center" bgcolor="#e4e4e4">
<td> <td>
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> <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> </td>
</tr> </tr>
</table> </table>
@@ -1471,6 +1471,9 @@ buildroot-0.1.6 2009-xx-xx &lt;spudmonkey@racsa.co.cr&gt;
nuttx-0.4.9 2009-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt; nuttx-0.4.9 2009-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
* Add strtoll() and strtoull(); Add macros for atol() and atoll(). * 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 &lt;spudmonkey@racsa.co.cr&gt; pascal-0.1.3 2009-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
+14 -1
View File
@@ -12,7 +12,7 @@
<h1><big><font color="#3c34ec"> <h1><big><font color="#3c34ec">
<i>NuttX RTOS Porting Guide</i> <i>NuttX RTOS Porting Guide</i>
</font></big></h1> </font></big></h1>
<p>Last Updated: May 28, 2009</p> <p>Last Updated: June 15, 2009</p>
</td> </td>
</tr> </tr>
</table> </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 This value may be set to zero if no more than one thread is expected to
wait for a semaphore. wait for a semaphore.
</li> </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> </ul>
<p> <p>
+9 -6
View File
@@ -17,7 +17,7 @@ NuttX TODO List (Last updated April 12, 2009)
(6) Build system / Toolchains (6) Build system / Toolchains
(2) NuttShell (NSH) (examples/nsh) (2) NuttShell (NSH) (examples/nsh)
(3) Other Applications & Tests (examples/) (3) Other Applications & Tests (examples/)
(1) Linux/Cywgin simulation (arch/sim) (2) Linux/Cywgin simulation (arch/sim)
(3) ARM (arch/arm/) (3) ARM (arch/arm/)
(1) ARM/C5471 (arch/arm/src/c5471/) (1) ARM/C5471 (arch/arm/src/c5471/)
(3) ARM/DM320 (arch/arm/src/dm320/) (3) ARM/DM320 (arch/arm/src/dm320/)
@@ -60,11 +60,6 @@ o Task/Scheduler (sched/)
Priority: Medium, required for standard compliance (but makes the Priority: Medium, required for standard compliance (but makes the
code bigger) code bigger)
Description: socket descriptors are not cloned as are file descriptors
by task_create().
Status: Open
Priority: Medium-to-High
o Dynamic Loader o Dynamic Loader
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
@@ -409,6 +404,14 @@ o Linux/Cywgin simulation (arch/sim)
Status: Open Status: Open
Priority: Low (because the simulator is only a test/development platform) 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/) o ARM (arch/arm/)
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
+7 -1
View File
@@ -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 release a count on a semaphore. This value may be set
to zero if no more than one thread is expected to wait for to zero if no more than one thread is expected to wait for
a semaphore. 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 The following can be used to disable categories of APIs supported
by the OS. If the compiler supports weak functions, then it 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_SIGNALS, CONFIG_DISABLE_MQUEUE, CONFIG_DISABLE_MOUNTPOUNT,
CONFIG_DISABLE_ENVIRON, CONFIG_DISABLE_POLL CONFIG_DISABLE_ENVIRON, CONFIG_DISABLE_POLL
Misc libc settings Misc libc settings
CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a
+21 -2
View File
@@ -164,12 +164,31 @@ EXTERN int net_poll(int sockfd, struct pollfd *fds, boolean setup);
#endif #endif
/* net_dup.c *****************************************************************/ /* net_dup.c *****************************************************************/
/* The standard dup() and dup2() operations redirect operations on socket /* The standard dup() operation redirects operations on socket descriptors to
* descriptors to these function. * this function (when both file and socket descriptors are supported)
*/ */
#if CONFIG_NFILE_DESCRIPTOR > 0
EXTERN int net_dup(int sockfd); 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); 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 *********************************************************/ /* netdev-register.c *********************************************************/
/* This function is called by network interface device drivers to inform the /* This function is called by network interface device drivers to inform the
+2
View File
@@ -85,6 +85,8 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2)
/* Increment the reference count on the connection */ /* Increment the reference count on the connection */
DEBUGASSERT(psock2->s_conn);
#ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_TCP
if (psock2->s_type == SOCK_STREAM) if (psock2->s_type == SOCK_STREAM)
{ {
-4
View File
@@ -156,10 +156,6 @@ EXTERN socktimeo_t net_timeval2dsec(struct timeval *tv);
EXTERN void net_dsec2timeval(uint16 dsec, struct timeval *tv); EXTERN void net_dsec2timeval(uint16 dsec, struct timeval *tv);
#endif #endif
/* net_clone.c ***************************************************************/
EXTERN int net_clone(FAR struct socket *psock1, FAR struct socket *psock2);
/* net_register.c ************************************************************/ /* net_register.c ************************************************************/
#if CONFIG_NSOCKET_DESCRIPTORS > 0 #if CONFIG_NSOCKET_DESCRIPTORS > 0
+50 -2
View File
@@ -49,6 +49,22 @@
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 #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 * Private Functions
****************************************************************************/ ****************************************************************************/
@@ -83,6 +99,7 @@ int sched_setuptaskfiles(FAR _TCB *tcb)
int ret = OK; int ret = OK;
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
/* Allocate file descriptors for the TCB */ /* Allocate file descriptors for the TCB */
tcb->filelist = files_alloclist(); tcb->filelist = files_alloclist();
@@ -91,9 +108,11 @@ int sched_setuptaskfiles(FAR _TCB *tcb)
*get_errno_ptr() = ENOMEM; *get_errno_ptr() = ENOMEM;
return ERROR; return ERROR;
} }
#endif /* CONFIG_NFILE_DESCRIPTORS */ #endif /* CONFIG_NFILE_DESCRIPTORS */
#if CONFIG_NSOCKET_DESCRIPTORS > 0 #if CONFIG_NSOCKET_DESCRIPTORS > 0
/* Allocate socket descriptors for the TCB */ /* Allocate socket descriptors for the TCB */
tcb->sockets = net_alloclist(); tcb->sockets = net_alloclist();
@@ -102,14 +121,21 @@ int sched_setuptaskfiles(FAR _TCB *tcb)
*get_errno_ptr() = ENOMEM; *get_errno_ptr() = ENOMEM;
return ERROR; return ERROR;
} }
#endif /* CONFIG_NSOCKET_DESCRIPTORS */ #endif /* CONFIG_NSOCKET_DESCRIPTORS */
#if CONFIG_NFILE_DESCRIPTORS > 0 #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) if (rtcb->filelist)
{ {
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) for (i = 0; i < NFDS_TOCLONE; i++)
{ {
/* Check if this file is opened */ /* Check if this file is opened */
@@ -120,13 +146,35 @@ int sched_setuptaskfiles(FAR _TCB *tcb)
} }
} }
} }
#endif
#if CONFIG_NFILE_STREAMS > 0 #if CONFIG_NFILE_STREAMS > 0
/* Allocate file streams for the TCB */ /* Allocate file streams for the TCB */
ret = sched_setupstreams(tcb); ret = sched_setupstreams(tcb);
#endif /* CONFIG_NFILE_STREAMS */ #endif /* CONFIG_NFILE_STREAMS */
#endif /* CONFIG_NFILE_DESCRIPTORS */ #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; return ret;
} }