dup() and dup2() support for socket descriptors

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1884 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2009-06-15 18:58:22 +00:00
parent 613d405fd4
commit fdf76b48bc
23 changed files with 948 additions and 126 deletions
+33 -2
View File
@@ -43,6 +43,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <assert.h>
#include <debug.h>
#include "net_internal.h"
@@ -155,13 +156,43 @@ int socket(int domain, int type, int protocol)
{
#ifdef CONFIG_NET_TCP
case SOCK_STREAM:
psock->s_conn = uip_tcpalloc();
{
/* Allocate the TCP connection structure and save in the new
* socket instance.
*/
struct uip_conn *conn = uip_tcpalloc();
psock->s_conn = conn;
/* Set the reference count on the connection structure. This
* reference count will be increment only if the socket is
* dup'ed
*/
DEBUGASSERT(conn->crefs == 0);
conn->crefs = 1;
}
break;
#endif
#ifdef CONFIG_NET_UDP
case SOCK_DGRAM:
psock->s_conn = uip_udpalloc();
{
/* Allocate the UDP connection structure and save in the new
* socket instance.
*/
struct uip_udp_conn *conn = uip_udpalloc();
psock->s_conn = conn;
/* Set the reference count on the connection structure. This
* reference count will be increment only if the socket is
* dup'ed
*/
DEBUGASSERT(conn->crefs == 0);
conn->crefs = 1;
}
break;
#endif