mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
net: Remove usrsock specific process from common code as much as possible
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
committed by
Masayuki Ishikawa
parent
699e3e8291
commit
c38d6f1ae4
+9
-13
@@ -33,7 +33,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "socket/socket.h"
|
#include "socket/socket.h"
|
||||||
#include "usrsock/usrsock.h"
|
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -122,21 +121,11 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
|||||||
|
|
||||||
/* Then return the timeout value to the caller */
|
/* Then return the timeout value to the caller */
|
||||||
|
|
||||||
net_dsec2timeval(timeo, (struct timeval *)value);
|
net_dsec2timeval(timeo, (FAR struct timeval *)value);
|
||||||
*value_len = sizeof(struct timeval);
|
*value_len = sizeof(struct timeval);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_USRSOCK
|
|
||||||
if (psock->s_type == SOCK_USRSOCK_TYPE)
|
|
||||||
{
|
|
||||||
return -ENOPROTOOPT;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (option)
|
|
||||||
{
|
|
||||||
case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */
|
case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */
|
||||||
{
|
{
|
||||||
if (*value_len < sizeof(int))
|
if (*value_len < sizeof(int))
|
||||||
@@ -297,6 +286,13 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option,
|
|||||||
ret = psock_socketlevel_option(psock, option, value, value_len);
|
ret = psock_socketlevel_option(psock, option, value, value_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -ENOTTY really mean -ENOPROTOOPT, but skip the default action */
|
||||||
|
|
||||||
|
else if (ret == -ENOTTY)
|
||||||
|
{
|
||||||
|
ret = -ENOPROTOOPT;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-4
@@ -38,6 +38,7 @@
|
|||||||
#include "pkt/pkt.h"
|
#include "pkt/pkt.h"
|
||||||
#include "bluetooth/bluetooth.h"
|
#include "bluetooth/bluetooth.h"
|
||||||
#include "ieee802154/ieee802154.h"
|
#include "ieee802154/ieee802154.h"
|
||||||
|
#include "usrsock/usrsock.h"
|
||||||
#include "socket/socket.h"
|
#include "socket/socket.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -75,12 +76,12 @@ net_sockif(sa_family_t family, int type, int protocol)
|
|||||||
switch (family)
|
switch (family)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_INET_SOCKETS
|
#ifdef HAVE_INET_SOCKETS
|
||||||
#ifdef HAVE_PFINET_SOCKETS
|
# ifdef HAVE_PFINET_SOCKETS
|
||||||
case PF_INET:
|
case PF_INET:
|
||||||
#endif
|
# endif
|
||||||
#ifdef HAVE_PFINET6_SOCKETS
|
# ifdef HAVE_PFINET6_SOCKETS
|
||||||
case PF_INET6:
|
case PF_INET6:
|
||||||
#endif
|
# endif
|
||||||
sockif = inet_sockif(family, type, protocol);
|
sockif = inet_sockif(family, type, protocol);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@@ -131,5 +132,12 @@ net_sockif(sa_family_t family, int type, int protocol)
|
|||||||
nerr("ERROR: Address family unsupported: %d\n", family);
|
nerr("ERROR: Address family unsupported: %d\n", family);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_USRSOCK
|
||||||
|
if (sockif == NULL)
|
||||||
|
{
|
||||||
|
sockif = &g_usrsock_sockif;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return sockif;
|
return sockif;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-11
@@ -38,7 +38,6 @@
|
|||||||
#include <netdev/netdev.h>
|
#include <netdev/netdev.h>
|
||||||
|
|
||||||
#include "socket/socket.h"
|
#include "socket/socket.h"
|
||||||
#include "usrsock/usrsock.h"
|
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -134,17 +133,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
|||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_USRSOCK
|
|
||||||
if (psock->s_type == SOCK_USRSOCK_TYPE)
|
|
||||||
{
|
|
||||||
return -ENOPROTOOPT;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (option)
|
|
||||||
{
|
|
||||||
case SO_BROADCAST: /* Permits sending of broadcast messages */
|
case SO_BROADCAST: /* Permits sending of broadcast messages */
|
||||||
case SO_DEBUG: /* Enables recording of debugging information */
|
case SO_DEBUG: /* Enables recording of debugging information */
|
||||||
case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */
|
case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */
|
||||||
@@ -329,6 +318,13 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option,
|
|||||||
ret = psock_socketlevel_option(psock, option, value, value_len);
|
ret = psock_socketlevel_option(psock, option, value, value_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -ENOTTY really mean -ENOPROTOOPT, but skip the default action */
|
||||||
|
|
||||||
|
else if (ret == -ENOTTY)
|
||||||
|
{
|
||||||
|
ret = -ENOPROTOOPT;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-30
@@ -29,7 +29,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include "usrsock/usrsock.h"
|
|
||||||
#include "socket/socket.h"
|
#include "socket/socket.h"
|
||||||
|
|
||||||
#ifdef CONFIG_NET
|
#ifdef CONFIG_NET
|
||||||
@@ -94,38 +93,23 @@ int psock_socket(int domain, int type, int protocol,
|
|||||||
psock->s_conn = NULL;
|
psock->s_conn = NULL;
|
||||||
psock->s_type = type & SOCK_TYPE_MASK;
|
psock->s_type = type & SOCK_TYPE_MASK;
|
||||||
|
|
||||||
#ifdef CONFIG_NET_USRSOCK
|
/* Get the socket interface */
|
||||||
if (domain != PF_LOCAL && domain != PF_UNSPEC && domain != PF_RPMSG)
|
|
||||||
|
sockif = net_sockif(domain, psock->s_type, protocol);
|
||||||
|
if (sockif == NULL)
|
||||||
{
|
{
|
||||||
/* Handle special setup for USRSOCK sockets (user-space networking
|
nerr("ERROR: socket address family unsupported: %d\n", domain);
|
||||||
* stack).
|
return -EAFNOSUPPORT;
|
||||||
*/
|
|
||||||
|
|
||||||
ret = g_usrsock_sockif.si_setup(psock, protocol);
|
|
||||||
psock->s_sockif = &g_usrsock_sockif;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif /* CONFIG_NET_USRSOCK */
|
|
||||||
{
|
|
||||||
/* Get the socket interface */
|
|
||||||
|
|
||||||
sockif = net_sockif(domain, psock->s_type, protocol);
|
|
||||||
if (sockif == NULL)
|
|
||||||
{
|
|
||||||
nerr("ERROR: socket address family unsupported: %d\n", domain);
|
|
||||||
return -EAFNOSUPPORT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The remaining of the socket initialization depends on the address
|
|
||||||
* family.
|
|
||||||
*/
|
|
||||||
|
|
||||||
DEBUGASSERT(sockif->si_setup != NULL);
|
|
||||||
psock->s_sockif = sockif;
|
|
||||||
|
|
||||||
ret = sockif->si_setup(psock, protocol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The remaining of the socket initialization depends on the address
|
||||||
|
* family.
|
||||||
|
*/
|
||||||
|
|
||||||
|
DEBUGASSERT(sockif->si_setup != NULL);
|
||||||
|
psock->s_sockif = sockif;
|
||||||
|
|
||||||
|
ret = sockif->si_setup(psock, protocol);
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
FAR struct socket_conn_s *conn = psock->s_conn;
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|||||||
@@ -41,11 +41,6 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Internal socket type/domain for marking usrsock sockets */
|
|
||||||
|
|
||||||
#define SOCK_USRSOCK_TYPE 0x7f
|
|
||||||
#define PF_USRSOCK_DOMAIN 0x7f
|
|
||||||
|
|
||||||
/* Internal event flags */
|
/* Internal event flags */
|
||||||
|
|
||||||
#define USRSOCK_EVENT_CONNECT_READY (1 << 0)
|
#define USRSOCK_EVENT_CONNECT_READY (1 << 0)
|
||||||
@@ -84,7 +79,6 @@ struct usrsock_conn_s
|
|||||||
|
|
||||||
enum usrsock_conn_state_e state; /* State of kernel<->daemon link for conn */
|
enum usrsock_conn_state_e state; /* State of kernel<->daemon link for conn */
|
||||||
bool connected; /* Socket has been connected */
|
bool connected; /* Socket has been connected */
|
||||||
int8_t type; /* Socket type (SOCK_STREAM, etc) */
|
|
||||||
int16_t usockid; /* Connection number used for kernel<->daemon */
|
int16_t usockid; /* Connection number used for kernel<->daemon */
|
||||||
uint16_t flags; /* Socket state flags */
|
uint16_t flags; /* Socket state flags */
|
||||||
|
|
||||||
|
|||||||
@@ -409,7 +409,6 @@ int usrsock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
newconn->connected = true;
|
newconn->connected = true;
|
||||||
newconn->type = conn->type;
|
|
||||||
newconn->crefs = 1;
|
newconn->crefs = 1;
|
||||||
|
|
||||||
newsock->s_type = psock->s_type;
|
newsock->s_type = psock->s_type;
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ int usrsock_connect(FAR struct socket *psock,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (conn->connected &&
|
if (conn->connected &&
|
||||||
(conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET))
|
(psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET))
|
||||||
{
|
{
|
||||||
/* Already connected. */
|
/* Already connected. */
|
||||||
|
|
||||||
|
|||||||
@@ -179,20 +179,12 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option,
|
|||||||
struct iovec inbufs[1];
|
struct iovec inbufs[1];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (level == SOL_SOCKET)
|
/* SO_[RCV|SND]TIMEO have to be handled locally to break the block i/o */
|
||||||
{
|
|
||||||
if (option == SO_TYPE)
|
|
||||||
{
|
|
||||||
/* Return the actual socket type */
|
|
||||||
|
|
||||||
*(FAR int *)value = conn->type;
|
if (level == SOL_SOCKET && (option == SO_TYPE ||
|
||||||
*value_len = sizeof(int);
|
option == SO_RCVTIMEO || option == SO_SNDTIMEO))
|
||||||
return OK;
|
{
|
||||||
}
|
return -ENOPROTOOPT;
|
||||||
else if (option == SO_RCVTIMEO || option == SO_SNDTIMEO)
|
|
||||||
{
|
|
||||||
return -ENOPROTOOPT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
net_lock();
|
net_lock();
|
||||||
@@ -249,6 +241,13 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option,
|
|||||||
usrsock_teardown_datain(conn);
|
usrsock_teardown_datain(conn);
|
||||||
usrsock_teardown_data_request_callback(&state);
|
usrsock_teardown_data_request_callback(&state);
|
||||||
|
|
||||||
|
/* Skip the default socket option handler */
|
||||||
|
|
||||||
|
if (ret == -ENOPROTOOPT)
|
||||||
|
{
|
||||||
|
ret = -ENOTTY;
|
||||||
|
}
|
||||||
|
|
||||||
errout_unlock:
|
errout_unlock:
|
||||||
net_unlock();
|
net_unlock();
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -200,8 +200,8 @@ static int usrsock_pollsetup(FAR struct socket *psock,
|
|||||||
|
|
||||||
/* Stream sockets need to be connected or connecting (or listening). */
|
/* Stream sockets need to be connected or connecting (or listening). */
|
||||||
|
|
||||||
else if ((conn->type == SOCK_STREAM ||
|
else if ((psock->s_type == SOCK_STREAM ||
|
||||||
conn->type == SOCK_SEQPACKET) &&
|
psock->s_type == SOCK_SEQPACKET) &&
|
||||||
!(conn->connected || conn->state ==
|
!(conn->connected || conn->state ==
|
||||||
USRSOCK_CONN_STATE_CONNECTING))
|
USRSOCK_CONN_STATE_CONNECTING))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||||||
goto errout_unlock;
|
goto errout_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET)
|
if (psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET)
|
||||||
{
|
{
|
||||||
if (!conn->connected)
|
if (!conn->connected)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ ssize_t usrsock_sendmsg(FAR struct socket *psock,
|
|||||||
goto errout_unlock;
|
goto errout_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET)
|
if (psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET)
|
||||||
{
|
{
|
||||||
if (!conn->connected)
|
if (!conn->connected)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -168,12 +168,13 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(conn);
|
DEBUGASSERT(conn);
|
||||||
if (level == SOL_SOCKET)
|
|
||||||
|
/* SO_[RCV|SND]TIMEO have to be handled locally to break the block i/o */
|
||||||
|
|
||||||
|
if (level == SOL_SOCKET && (option == SO_TYPE ||
|
||||||
|
option == SO_RCVTIMEO || option == SO_SNDTIMEO))
|
||||||
{
|
{
|
||||||
if (option == SO_RCVTIMEO || option == SO_SNDTIMEO)
|
return -ENOPROTOOPT;
|
||||||
{
|
|
||||||
return -ENOPROTOOPT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
net_lock();
|
net_lock();
|
||||||
@@ -215,6 +216,13 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option,
|
|||||||
|
|
||||||
usrsock_teardown_request_callback(&state);
|
usrsock_teardown_request_callback(&state);
|
||||||
|
|
||||||
|
/* Skip the default socket option handler */
|
||||||
|
|
||||||
|
if (ret == -ENOPROTOOPT)
|
||||||
|
{
|
||||||
|
ret = -ENOTTY;
|
||||||
|
}
|
||||||
|
|
||||||
errout_unlock:
|
errout_unlock:
|
||||||
net_unlock();
|
net_unlock();
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -233,9 +233,6 @@ int usrsock_socket(int domain, int type, int protocol,
|
|||||||
goto errout_teardown_callback;
|
goto errout_teardown_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
psock->s_type = SOCK_USRSOCK_TYPE;
|
|
||||||
psock->s_domain = PF_USRSOCK_DOMAIN;
|
|
||||||
conn->type = type;
|
|
||||||
psock->s_conn = conn;
|
psock->s_conn = conn;
|
||||||
conn->crefs = 1;
|
conn->crefs = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -99,13 +99,8 @@ const struct sock_intf_s g_usrsock_sockif =
|
|||||||
|
|
||||||
static int usrsock_sockif_setup(FAR struct socket *psock, int protocol)
|
static int usrsock_sockif_setup(FAR struct socket *psock, int protocol)
|
||||||
{
|
{
|
||||||
int domain = psock->s_domain;
|
|
||||||
int type = psock->s_type;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
psock->s_type = PF_UNSPEC;
|
|
||||||
psock->s_conn = NULL;
|
|
||||||
|
|
||||||
/* Let the user socket logic handle the setup...
|
/* Let the user socket logic handle the setup...
|
||||||
*
|
*
|
||||||
* A return value of zero means that the operation was
|
* A return value of zero means that the operation was
|
||||||
@@ -115,7 +110,7 @@ static int usrsock_sockif_setup(FAR struct socket *psock, int protocol)
|
|||||||
* to open socket with kernel networking stack in this case.
|
* to open socket with kernel networking stack in this case.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = usrsock_socket(domain, type, protocol, psock);
|
ret = usrsock_socket(psock->s_domain, psock->s_type, protocol, psock);
|
||||||
if (ret == -ENETDOWN)
|
if (ret == -ENETDOWN)
|
||||||
{
|
{
|
||||||
nwarn("WARNING: usrsock daemon is not running\n");
|
nwarn("WARNING: usrsock daemon is not running\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user