summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-09-16 20:27:00 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-09-16 20:27:00 +0000
commitaf1a02c3618bf83b692d799a7ce1f21eabf5b72d (patch)
tree2ad780bb6261e59f7317ec3fcb34c0d7028c3fec
parenta4c7a908019d77373ca4e0f8fe052298c34aa3d1 (diff)
downloadpx4-nuttx-af1a02c3618bf83b692d799a7ce1f21eabf5b72d.tar.gz
px4-nuttx-af1a02c3618bf83b692d799a7ce1f21eabf5b72d.tar.bz2
px4-nuttx-af1a02c3618bf83b692d799a7ce1f21eabf5b72d.zip
Fix some errno reporting
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2068 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/net/socket.c51
1 files changed, 27 insertions, 24 deletions
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;
}