Unix domain: A few fixes from early integration

This commit is contained in:
Gregory Nutt 2015-01-27 16:39:30 -06:00
parent 55d94b6748
commit ca2102febb
10 changed files with 103 additions and 40 deletions

View file

@ -1,3 +1,4 @@
accept NXaccept
calloc NXcalloc
clock_gettime NXclock_gettime
close NXclose
@ -13,6 +14,7 @@ fsync NXfsync
gettimeofday NXgettimeofday
ioctl NXioctl
isatty NXisatty
listen NXlisten
lseek NXlseek
malloc NXmalloc
malloc_init NXmalloc_init

View file

@ -128,7 +128,7 @@ struct local_conn_s
/* Fields common to SOCK_STREAM and SOCK_DGRAM */
uint8_t lc_crefs; /* Reference counts on this instance */
uint8_t lc_family; /* SOCK_STREAM or SOCK_DGRAM */
uint8_t lc_proto; /* SOCK_STREAM or SOCK_DGRAM */
uint8_t lc_type; /* See enum local_type_e */
uint8_t lc_state; /* See enum local_state_e */
int16_t lc_infd; /* File descriptor of read-only FIFO (peers) */
@ -228,7 +228,7 @@ FAR struct local_conn_s *local_alloc(void);
void local_free(FAR struct local_conn_s *conn);
/****************************************************************************
* Name: local_bind
* Name: psock_local_bind
*
* Description:
* This function implements the low-level parts of the standard local
@ -236,8 +236,8 @@ void local_free(FAR struct local_conn_s *conn);
*
****************************************************************************/
int local_bind(FAR struct local_conn_s *conn,
FAR const struct sockaddr *addr, socklen_t addrlen);
int psock_local_bind(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
/****************************************************************************
* Name: local_connect
@ -246,7 +246,7 @@ int local_bind(FAR struct local_conn_s *conn,
* This function sets up a new local connection. The function will
* automatically allocate an unused local port for the new
* connection. However, another port can be chosen by using the
* local_bind() call, after the local_connect() function has been
* psock_local_bind() call, after the local_connect() function has been
* called.
*
* This function is called as part of the implementation of sendto

View file

@ -92,9 +92,9 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
DEBUGASSERT(psock && psock->s_conn);
server = (FAR struct local_conn_s *)psock->s_conn;
if (server->lc_family != SOCK_STREAM ||
if (server->lc_proto != SOCK_STREAM ||
server->lc_state != LOCAL_STATE_LISTENING ||
server->lc_type != LOCAL_TYPE_PATHNAME)
server->lc_type != LOCAL_TYPE_PATHNAME)
{
return -EOPNOTSUPP;
}
@ -132,9 +132,9 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
/* Initialize the new connection structure */
conn->lc_crefs = 1;
conn->lc_family = SOCK_STREAM;
conn->lc_proto = SOCK_STREAM;
conn->lc_type = LOCAL_TYPE_PATHNAME;
conn->lc_state = LOCAL_STATE_CONNECTED;
conn->lc_state = LOCAL_STATE_CONNECTED;
strncpy(conn->lc_path, client->lc_path, UNIX_PATH_MAX-1);
conn->lc_path[UNIX_PATH_MAX-1] = '\0';

View file

@ -44,6 +44,8 @@
#include <string.h>
#include <assert.h>
#include <nuttx/net/net.h>
#include "local/local.h"
/****************************************************************************
@ -59,19 +61,23 @@
*
****************************************************************************/
int local_bind(FAR struct local_conn_s *conn,
FAR const struct sockaddr *addr, socklen_t addrlen)
int psock_local_bind(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen)
{
FAR struct local_conn_s *conn;
FAR const struct sockaddr_un *unaddr =
(FAR const struct sockaddr_un *)addr;
int namelen;
DEBUGASSERT(conn && unaddr && unaddr->sun_family == AF_LOCAL &&
DEBUGASSERT(psock && psock->s_conn && unaddr &&
unaddr->sun_family == AF_LOCAL &&
addrlen >= sizeof(sa_family_t));
conn = (FAR struct local_conn_s *)psock->s_conn;
/* Save the address family */
conn->lc_family = unaddr->sun_family;
conn->lc_proto = psock->s_type;
/* No determine the type of the Unix domain socket by comparing the size
* of the address description.

View file

@ -225,6 +225,7 @@ errout_with_fifos:
int local_connect(FAR struct local_conn_s *client,
FAR const struct sockaddr *addr)
{
FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
FAR struct local_conn_s *conn;
net_lock_t state;
@ -243,20 +244,16 @@ int local_connect(FAR struct local_conn_s *client,
conn;
conn = (FAR struct local_conn_s *)dq_next(&conn->lc_node))
{
/* Skip over connections that that have not yet been bound,
* are or a different address family, or are of a different type.
/* Anything in the listener list should be a stream socket in the
* istening state
*/
if (conn->lc_state == LOCAL_STATE_UNBOUND ||
conn->lc_family != client->lc_family ||
conn->lc_type != client->lc_type)
{
continue;
}
DEBUGASSERT(conn->lc_state == LOCAL_STATE_LISTENING &&
conn->lc_proto == SOCK_STREAM);
/* Handle according to the connection type */
/* Handle according to the server connection type */
switch (client->lc_type)
switch (conn->lc_type)
{
case LOCAL_TYPE_UNNAMED: /* A Unix socket that is not bound to any name */
case LOCAL_TYPE_ABSTRACT: /* lc_path is length zero */
@ -269,11 +266,17 @@ int local_connect(FAR struct local_conn_s *client,
case LOCAL_TYPE_PATHNAME: /* lc_path holds a null terminated string */
{
if (strncmp(client->lc_path, conn->lc_path, UNIX_PATH_MAX-1) == 0)
if (strncmp(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1) == 0)
{
/* Bind the address and protocol */
client->lc_proto = conn->lc_proto;
strncpy(client->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1);
client->lc_path[UNIX_PATH_MAX-1] = '\0';
/* We have to do more for the SOCK_STREAM family */
if (conn->lc_family == SOCK_STREAM)
if (conn->lc_proto == SOCK_STREAM)
{
return local_stream_connect(client, conn, state);
}

View file

@ -89,7 +89,7 @@ int local_listen(FAR struct local_conn_s *server, int backlog)
DEBUGASSERT(server);
if (server->lc_family != SOCK_STREAM ||
if (server->lc_proto != SOCK_STREAM ||
server->lc_state == LOCAL_STATE_UNBOUND ||
server->lc_type != LOCAL_TYPE_PATHNAME)
{

View file

@ -85,7 +85,7 @@ int local_release(FAR struct local_conn_s *conn)
if (conn->lc_state == LOCAL_STATE_CONNECTED ||
conn->lc_state == LOCAL_STATE_DISCONNECTED)
{
DEBUGASSERT(conn->lc_family == SOCK_STREAM);
DEBUGASSERT(conn->lc_proto == SOCK_STREAM);
/* Just free the connection structure */
}
@ -96,7 +96,7 @@ int local_release(FAR struct local_conn_s *conn)
{
FAR struct local_conn_s *client;
DEBUGASSERT(conn->lc_family == SOCK_STREAM);
DEBUGASSERT(conn->lc_proto == SOCK_STREAM);
/* Are there still clients waiting for a connection to the server? */

View file

@ -228,7 +228,7 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
{
/* Bind the Unix domain connection structure */
ret = local_bind(psock->s_conn, addr, addrlen);
ret = psock_local_bind(psock, addr, addrlen);
}
#endif /* CONFIG_NET_LOCAL */
@ -269,7 +269,7 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
{
/* Bind the Unix domain connection structure */
ret = local_bind(psock->s_conn, addr, addrlen);
ret = psock_local_bind(psock, addr, addrlen);
}
#endif /* CONFIG_NET_LOCAL */

View file

@ -503,6 +503,18 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
break;
#endif
#ifdef CONFIG_NET_LOCAL
case AF_LOCAL:
{
if (addrlen < sizeof(sa_family_t))
{
err = EBADF;
goto errout;
}
}
break;
#endif
default:
DEBUGPANIC();
err = EAFNOSUPPORT;

View file

@ -292,27 +292,67 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock)
switch (type)
{
#ifdef CONFIG_NET_TCP
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_LOCAL)
case SOCK_STREAM:
if ((protocol != 0 && protocol != IPPROTO_TCP) || !dgramok)
#ifdef CONFIG_NET_TCP
#ifdef CONFIG_NET_LOCAL
if (ipdomain)
#endif
{
err = EPROTONOSUPPORT;
goto errout;
if ((protocol != 0 && protocol != IPPROTO_TCP) || !dgramok)
{
err = EPROTONOSUPPORT;
goto errout;
}
}
#endif /* CONFIG_NET_TCP */
#ifdef CONFIG_NET_LOCAL
#ifdef CONFIG_NET_TCP
else
#endif
{
if (protocol != 0 || !dgramok)
{
err = EPROTONOSUPPORT;
goto errout;
}
}
#endif /* CONFIG_NET_LOCAL */
break;
#endif
#endif /* CONFIG_NET_TCP || CONFIG_NET_LOCAL */
#ifdef CONFIG_NET_UDP
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_LOCAL)
case SOCK_DGRAM:
if ((protocol != 0 && protocol != IPPROTO_UDP) || !dgramok)
#ifdef CONFIG_NET_UDP
#ifdef CONFIG_NET_LOCAL
if (ipdomain)
#endif
{
err = EPROTONOSUPPORT;
goto errout;
if ((protocol != 0 && protocol != IPPROTO_UDP) || !dgramok)
{
err = EPROTONOSUPPORT;
goto errout;
}
}
#endif /* CONFIG_NET_UDP */
#ifdef CONFIG_NET_LOCAL
#ifdef CONFIG_NET_UDP
else
#endif
{
if (protocol != 0 || !dgramok)
{
err = EPROTONOSUPPORT;
goto errout;
}
}
#endif /* CONFIG_NET_LOCAL */
break;
#endif
#endif /* CONFIG_NET_UDP || CONFIG_NET_LOCAL */
#ifdef CONFIG_NET_PKT
case SOCK_RAW: