diff --git a/net/socket/net_sockif.c b/net/socket/net_sockif.c index ec9024111c3d2..e2bfc4736e162 100644 --- a/net/socket/net_sockif.c +++ b/net/socket/net_sockif.c @@ -38,7 +38,6 @@ #include "pkt/pkt.h" #include "bluetooth/bluetooth.h" #include "ieee802154/ieee802154.h" -#include "usrsock/usrsock.h" #include "socket/socket.h" /**************************************************************************** @@ -132,12 +131,5 @@ 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; } diff --git a/net/socket/socket.c b/net/socket/socket.c index e4a43cb49f1e4..964274b6e03b0 100644 --- a/net/socket/socket.c +++ b/net/socket/socket.c @@ -29,6 +29,7 @@ #include #include +#include "usrsock/usrsock.h" #include "socket/socket.h" #ifdef CONFIG_NET @@ -93,6 +94,25 @@ int psock_socket(int domain, int type, int protocol, psock->s_conn = NULL; psock->s_type = type & SOCK_TYPE_MASK; +#ifdef CONFIG_NET_USRSOCK + /* Get the usrsock interface */ + + sockif = &g_usrsock_sockif; + psock->s_sockif = sockif; + + ret = sockif->si_setup(psock); + + /* When usrsock daemon returns -ENOSYS or -ENOTSUP, it means to use + * kernel's network stack, so fallback to kernel socket. + */ + + if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP)) + { + return ret; + } + +#endif + /* Get the socket interface */ sockif = net_sockif(domain, psock->s_type, psock->s_proto);