From af1a02c3618bf83b692d799a7ce1f21eabf5b72d Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 16 Sep 2009 20:27:00 +0000 Subject: Fix some errno reporting git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2068 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/net/socket.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'nuttx/net/socket.c') diff --git a/nuttx/net/socket.c b/nuttx/net/socket.c index f8de67f9e..23555c7ea 100644 --- a/nuttx/net/socket.c +++ b/nuttx/net/socket.c @@ -92,7 +92,7 @@ int socket(int domain, int type, int protocol) { FAR struct socket *psock; int sockfd; - int err; + int err = ENFILE; /* Only PF_INET or PF_INET6 domains supported */ @@ -129,8 +129,7 @@ int socket(int domain, int type, int protocol) sockfd = sockfd_allocate(0); if (sockfd < 0) { - err = ENFILE; - goto errout; + goto errout; /* with err == ENFILE */ } /* Initialize the socket structure */ @@ -152,6 +151,7 @@ int socket(int domain, int type, int protocol) * not actually be initialized until the socket is connected. */ + err = ENOMEM; /* Assume failure to allocate connection instance */ switch (type) { #ifdef CONFIG_NET_TCP @@ -162,15 +162,17 @@ int socket(int domain, int type, int protocol) */ 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; + if (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); + psock->s_conn = conn; + conn->crefs = 1; + } } break; #endif @@ -183,15 +185,17 @@ int socket(int domain, int type, int protocol) */ 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; + if (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); + psock->s_conn = conn; + conn->crefs = 1; + } } break; #endif @@ -207,14 +211,13 @@ int socket(int domain, int type, int protocol) /* Failed to reserve a connection structure */ sockfd_release(sockfd); - err = ENFILE; - goto errout; + goto errout; /* With err == ENFILE or ENOMEM */ } return sockfd; errout: - *get_errno_ptr() = err; + errno = err; return ERROR; } -- cgit v1.2.3