Fix some errno reporting

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2068 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2009-09-16 20:27:00 +00:00
parent 6abf781fa1
commit 5b5b170f0f

View File

@ -92,7 +92,7 @@ int socket(int domain, int type, int protocol)
{ {
FAR struct socket *psock; FAR struct socket *psock;
int sockfd; int sockfd;
int err; int err = ENFILE;
/* Only PF_INET or PF_INET6 domains supported */ /* Only PF_INET or PF_INET6 domains supported */
@ -129,8 +129,7 @@ int socket(int domain, int type, int protocol)
sockfd = sockfd_allocate(0); sockfd = sockfd_allocate(0);
if (sockfd < 0) if (sockfd < 0)
{ {
err = ENFILE; goto errout; /* with err == ENFILE */
goto errout;
} }
/* Initialize the socket structure */ /* 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. * not actually be initialized until the socket is connected.
*/ */
err = ENOMEM; /* Assume failure to allocate connection instance */
switch (type) switch (type)
{ {
#ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_TCP
@ -162,15 +162,17 @@ int socket(int domain, int type, int protocol)
*/ */
struct uip_conn *conn = uip_tcpalloc(); struct uip_conn *conn = uip_tcpalloc();
psock->s_conn = conn; if (conn)
{
/* Set the reference count on the connection structure. This
* reference count will be increment only if the socket is
* dup'ed
*/
/* Set the reference count on the connection structure. This DEBUGASSERT(conn->crefs == 0);
* reference count will be increment only if the socket is psock->s_conn = conn;
* dup'ed conn->crefs = 1;
*/ }
DEBUGASSERT(conn->crefs == 0);
conn->crefs = 1;
} }
break; break;
#endif #endif
@ -183,15 +185,17 @@ int socket(int domain, int type, int protocol)
*/ */
struct uip_udp_conn *conn = uip_udpalloc(); struct uip_udp_conn *conn = uip_udpalloc();
psock->s_conn = conn; if (conn)
{
/* Set the reference count on the connection structure. This
* reference count will be increment only if the socket is
* dup'ed
*/
/* Set the reference count on the connection structure. This DEBUGASSERT(conn->crefs == 0);
* reference count will be increment only if the socket is psock->s_conn = conn;
* dup'ed conn->crefs = 1;
*/ }
DEBUGASSERT(conn->crefs == 0);
conn->crefs = 1;
} }
break; break;
#endif #endif
@ -207,14 +211,13 @@ int socket(int domain, int type, int protocol)
/* Failed to reserve a connection structure */ /* Failed to reserve a connection structure */
sockfd_release(sockfd); sockfd_release(sockfd);
err = ENFILE; goto errout; /* With err == ENFILE or ENOMEM */
goto errout;
} }
return sockfd; return sockfd;
errout: errout:
*get_errno_ptr() = err; errno = err;
return ERROR; return ERROR;
} }