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:
parent
fdf76b48bc
commit
e9711ca1a7
9 changed files with 114 additions and 17 deletions
|
@ -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.
|
||||
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
15
TODO
15
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/)
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -49,6 +49,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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue