mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 20:44:39 +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 "socket/socket.h"
|
||||
#include "usrsock/usrsock.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 */
|
||||
|
||||
net_dsec2timeval(timeo, (struct timeval *)value);
|
||||
*value_len = sizeof(struct timeval);
|
||||
net_dsec2timeval(timeo, (FAR struct timeval *)value);
|
||||
*value_len = sizeof(struct timeval);
|
||||
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 */
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/* -ENOTTY really mean -ENOPROTOOPT, but skip the default action */
|
||||
|
||||
else if (ret == -ENOTTY)
|
||||
{
|
||||
ret = -ENOPROTOOPT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+12
-4
@@ -38,6 +38,7 @@
|
||||
#include "pkt/pkt.h"
|
||||
#include "bluetooth/bluetooth.h"
|
||||
#include "ieee802154/ieee802154.h"
|
||||
#include "usrsock/usrsock.h"
|
||||
#include "socket/socket.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -75,12 +76,12 @@ net_sockif(sa_family_t family, int type, int protocol)
|
||||
switch (family)
|
||||
{
|
||||
#ifdef HAVE_INET_SOCKETS
|
||||
#ifdef HAVE_PFINET_SOCKETS
|
||||
# ifdef HAVE_PFINET_SOCKETS
|
||||
case PF_INET:
|
||||
#endif
|
||||
#ifdef HAVE_PFINET6_SOCKETS
|
||||
# endif
|
||||
# ifdef HAVE_PFINET6_SOCKETS
|
||||
case PF_INET6:
|
||||
#endif
|
||||
# endif
|
||||
sockif = inet_sockif(family, type, protocol);
|
||||
break;
|
||||
#endif
|
||||
@@ -131,5 +132,12 @@ net_sockif(sa_family_t family, int type, int protocol)
|
||||
nerr("ERROR: Address family unsupported: %d\n", family);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_USRSOCK
|
||||
if (sockif == NULL)
|
||||
{
|
||||
sockif = &g_usrsock_sockif;
|
||||
}
|
||||
#endif
|
||||
|
||||
return sockif;
|
||||
}
|
||||
|
||||
+7
-11
@@ -38,7 +38,6 @@
|
||||
#include <netdev/netdev.h>
|
||||
|
||||
#include "socket/socket.h"
|
||||
#include "usrsock/usrsock.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -134,17 +133,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
||||
|
||||
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_DEBUG: /* Enables recording of debugging information */
|
||||
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);
|
||||
}
|
||||
|
||||
/* -ENOTTY really mean -ENOPROTOOPT, but skip the default action */
|
||||
|
||||
else if (ret == -ENOTTY)
|
||||
{
|
||||
ret = -ENOPROTOOPT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+14
-30
@@ -29,7 +29,6 @@
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "usrsock/usrsock.h"
|
||||
#include "socket/socket.h"
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
@@ -94,38 +93,23 @@ int psock_socket(int domain, int type, int protocol,
|
||||
psock->s_conn = NULL;
|
||||
psock->s_type = type & SOCK_TYPE_MASK;
|
||||
|
||||
#ifdef CONFIG_NET_USRSOCK
|
||||
if (domain != PF_LOCAL && domain != PF_UNSPEC && domain != PF_RPMSG)
|
||||
/* Get the socket interface */
|
||||
|
||||
sockif = net_sockif(domain, psock->s_type, protocol);
|
||||
if (sockif == NULL)
|
||||
{
|
||||
/* Handle special setup for USRSOCK sockets (user-space networking
|
||||
* stack).
|
||||
*/
|
||||
|
||||
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);
|
||||
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);
|
||||
if (ret >= 0)
|
||||
{
|
||||
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||
|
||||
@@ -41,11 +41,6 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Internal socket type/domain for marking usrsock sockets */
|
||||
|
||||
#define SOCK_USRSOCK_TYPE 0x7f
|
||||
#define PF_USRSOCK_DOMAIN 0x7f
|
||||
|
||||
/* Internal event flags */
|
||||
|
||||
#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 */
|
||||
bool connected; /* Socket has been connected */
|
||||
int8_t type; /* Socket type (SOCK_STREAM, etc) */
|
||||
int16_t usockid; /* Connection number used for kernel<->daemon */
|
||||
uint16_t flags; /* Socket state flags */
|
||||
|
||||
|
||||
@@ -409,7 +409,6 @@ int usrsock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
||||
if (ret >= 0)
|
||||
{
|
||||
newconn->connected = true;
|
||||
newconn->type = conn->type;
|
||||
newconn->crefs = 1;
|
||||
|
||||
newsock->s_type = psock->s_type;
|
||||
|
||||
@@ -172,7 +172,7 @@ int usrsock_connect(FAR struct socket *psock,
|
||||
}
|
||||
|
||||
if (conn->connected &&
|
||||
(conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET))
|
||||
(psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET))
|
||||
{
|
||||
/* Already connected. */
|
||||
|
||||
|
||||
@@ -179,20 +179,12 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option,
|
||||
struct iovec inbufs[1];
|
||||
int ret;
|
||||
|
||||
if (level == SOL_SOCKET)
|
||||
{
|
||||
if (option == SO_TYPE)
|
||||
{
|
||||
/* Return the actual socket type */
|
||||
/* SO_[RCV|SND]TIMEO have to be handled locally to break the block i/o */
|
||||
|
||||
*(FAR int *)value = conn->type;
|
||||
*value_len = sizeof(int);
|
||||
return OK;
|
||||
}
|
||||
else if (option == SO_RCVTIMEO || option == SO_SNDTIMEO)
|
||||
{
|
||||
return -ENOPROTOOPT;
|
||||
}
|
||||
if (level == SOL_SOCKET && (option == SO_TYPE ||
|
||||
option == SO_RCVTIMEO || option == SO_SNDTIMEO))
|
||||
{
|
||||
return -ENOPROTOOPT;
|
||||
}
|
||||
|
||||
net_lock();
|
||||
@@ -249,6 +241,13 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option,
|
||||
usrsock_teardown_datain(conn);
|
||||
usrsock_teardown_data_request_callback(&state);
|
||||
|
||||
/* Skip the default socket option handler */
|
||||
|
||||
if (ret == -ENOPROTOOPT)
|
||||
{
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
|
||||
errout_unlock:
|
||||
net_unlock();
|
||||
return ret;
|
||||
|
||||
@@ -200,8 +200,8 @@ static int usrsock_pollsetup(FAR struct socket *psock,
|
||||
|
||||
/* Stream sockets need to be connected or connecting (or listening). */
|
||||
|
||||
else if ((conn->type == SOCK_STREAM ||
|
||||
conn->type == SOCK_SEQPACKET) &&
|
||||
else if ((psock->s_type == SOCK_STREAM ||
|
||||
psock->s_type == SOCK_SEQPACKET) &&
|
||||
!(conn->connected || conn->state ==
|
||||
USRSOCK_CONN_STATE_CONNECTING))
|
||||
{
|
||||
|
||||
@@ -246,7 +246,7 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -225,7 +225,7 @@ ssize_t usrsock_sendmsg(FAR struct socket *psock,
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -168,12 +168,13 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option,
|
||||
int ret;
|
||||
|
||||
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();
|
||||
@@ -215,6 +216,13 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option,
|
||||
|
||||
usrsock_teardown_request_callback(&state);
|
||||
|
||||
/* Skip the default socket option handler */
|
||||
|
||||
if (ret == -ENOPROTOOPT)
|
||||
{
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
|
||||
errout_unlock:
|
||||
net_unlock();
|
||||
return ret;
|
||||
|
||||
@@ -233,9 +233,6 @@ int usrsock_socket(int domain, int type, int protocol,
|
||||
goto errout_teardown_callback;
|
||||
}
|
||||
|
||||
psock->s_type = SOCK_USRSOCK_TYPE;
|
||||
psock->s_domain = PF_USRSOCK_DOMAIN;
|
||||
conn->type = type;
|
||||
psock->s_conn = conn;
|
||||
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)
|
||||
{
|
||||
int domain = psock->s_domain;
|
||||
int type = psock->s_type;
|
||||
int ret;
|
||||
|
||||
psock->s_type = PF_UNSPEC;
|
||||
psock->s_conn = NULL;
|
||||
|
||||
/* Let the user socket logic handle the setup...
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
ret = usrsock_socket(domain, type, protocol, psock);
|
||||
ret = usrsock_socket(psock->s_domain, psock->s_type, protocol, psock);
|
||||
if (ret == -ENETDOWN)
|
||||
{
|
||||
nwarn("WARNING: usrsock daemon is not running\n");
|
||||
|
||||
Reference in New Issue
Block a user