[net][sal] Remove DFS dependencies in the SAL
This commit is contained in:
parent
2d894b4102
commit
6d702e579f
|
@ -5,7 +5,6 @@ menu "Socket abstraction layer"
|
|||
config RT_USING_SAL
|
||||
bool "Enable socket abstraction layer"
|
||||
default n
|
||||
select RT_USING_DFS
|
||||
|
||||
if RT_USING_SAL
|
||||
|
||||
|
@ -28,14 +27,24 @@ config RT_USING_SAL
|
|||
|
||||
config SAL_USING_POSIX
|
||||
bool "Enable BSD socket operated by file system API"
|
||||
default y if RT_USING_POSIX
|
||||
default n
|
||||
select RT_USING_DFS
|
||||
select RT_USING_LIBC
|
||||
select RT_USING_POSIX
|
||||
default n
|
||||
help
|
||||
Let BSD socket operated by file system API, such as read/write and involveed in select/poll POSIX APIs.
|
||||
|
||||
if !SAL_USING_POSIX
|
||||
|
||||
config SAL_SOCKETS_NUM
|
||||
int "the maximum number of sockets"
|
||||
default 16
|
||||
|
||||
endif
|
||||
|
||||
config SAL_PROTO_FAMILIES_NUM
|
||||
int "the number of protocol family"
|
||||
int "the maximum number of protocol families"
|
||||
default 4
|
||||
|
||||
endif
|
||||
|
|
|
@ -67,7 +67,7 @@ path = [GetCurrentDir() + '/src',
|
|||
GetCurrentDir() + '/src/arch/include',
|
||||
GetCurrentDir() + '/src/include/netif']
|
||||
|
||||
if not GetDepend('RT_USING_POSIX') or not GetDepend('SAL_USING_POSIX'):
|
||||
if not GetDepend('RT_USING_SAL'):
|
||||
path += [GetCurrentDir() + '/src/include/posix']
|
||||
|
||||
if GetDepend(['RT_LWIP_SNMP']):
|
||||
|
|
|
@ -5,10 +5,9 @@ from building import *
|
|||
cwd = GetCurrentDir()
|
||||
|
||||
src = Glob('src/*.c')
|
||||
src += Glob('socket/*.c')
|
||||
src += Glob('socket/net_netdb.c')
|
||||
|
||||
CPPPATH = [cwd + '/include']
|
||||
CPPPATH += [cwd + '/include/dfs_net']
|
||||
CPPPATH += [cwd + '/include/socket']
|
||||
|
||||
if GetDepend('SAL_USING_LWIP'):
|
||||
|
@ -21,6 +20,8 @@ if GetDepend('SAL_USING_LWIP') or GetDepend('SAL_USING_AT'):
|
|||
CPPPATH += [cwd + '/impl']
|
||||
|
||||
if GetDepend('SAL_USING_POSIX'):
|
||||
CPPPATH += [cwd + '/include/dfs_net']
|
||||
src += Glob('socket/net_sockets.c')
|
||||
src += Glob('dfs_net/*.c')
|
||||
|
||||
if not GetDepend('HAVE_SYS_SELECT_H'):
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
* 2018-06-06 ChenYong First version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <netdb.h>
|
||||
#include <sal.h>
|
||||
|
||||
|
@ -91,8 +93,6 @@ static const struct proto_ops at_inet_stream_ops =
|
|||
|
||||
#ifdef SAL_USING_POSIX
|
||||
at_poll,
|
||||
#else
|
||||
NULL,
|
||||
#endif /* SAL_USING_POSIX */
|
||||
};
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
/*
|
||||
* Re-define lwip socket
|
||||
*
|
||||
|
@ -73,9 +74,7 @@ struct lwip_sock {
|
|||
/** counter of how many threads are waiting for this socket using select */
|
||||
SELWAIT_T select_waiting;
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
rt_wqueue_t wait_head;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern struct lwip_sock *lwip_tryget_socket(int s);
|
||||
|
@ -160,14 +159,14 @@ static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len
|
|||
|
||||
if (event)
|
||||
{
|
||||
#ifdef SAL_USING_POSIX
|
||||
rt_wqueue_wakeup(&sock->wait_head, (void*) event);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif /* SAL_USING_POSIX */
|
||||
|
||||
static int inet_socket(int domain, int type, int protocol)
|
||||
{
|
||||
#ifdef SAL_USING_POSIX
|
||||
int socket;
|
||||
|
||||
socket = lwip_socket(domain, type, protocol);
|
||||
|
@ -178,17 +177,18 @@ static int inet_socket(int domain, int type, int protocol)
|
|||
lwsock = lwip_tryget_socket(socket);
|
||||
lwsock->conn->callback = event_callback;
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
rt_wqueue_init(&lwsock->wait_head);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
return socket;
|
||||
#else
|
||||
return lwip_socket(domain, type, protocol);
|
||||
#endif /* SAL_USING_POSIX */
|
||||
}
|
||||
|
||||
static int inet_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
|
||||
{
|
||||
#ifdef SAL_USING_POSIX
|
||||
int new_socket;
|
||||
|
||||
new_socket = lwip_accept(socket, addr, addrlen);
|
||||
|
@ -198,12 +198,13 @@ static int inet_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
|
|||
|
||||
lwsock = lwip_tryget_socket(new_socket);
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
rt_wqueue_init(&lwsock->wait_head);
|
||||
#endif
|
||||
}
|
||||
|
||||
return new_socket;
|
||||
#else
|
||||
return lwip_accept(socket, addr, addrlen);
|
||||
#endif /* SAL_USING_POSIX */
|
||||
}
|
||||
|
||||
static int inet_getsockname(int socket, struct sockaddr *name, socklen_t *namelen)
|
||||
|
@ -216,6 +217,7 @@ static int inet_getsockname(int socket, struct sockaddr *name, socklen_t *namele
|
|||
return lwip_getsockname(socket, name, namelen);
|
||||
}
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
static int inet_poll(struct dfs_fd *file, struct rt_pollreq *req)
|
||||
{
|
||||
int mask = 0;
|
||||
|
@ -253,6 +255,7 @@ static int inet_poll(struct dfs_fd *file, struct rt_pollreq *req)
|
|||
|
||||
return mask;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const struct proto_ops lwip_inet_stream_ops = {
|
||||
inet_socket,
|
||||
|
@ -270,7 +273,9 @@ static const struct proto_ops lwip_inet_stream_ops = {
|
|||
lwip_getpeername,
|
||||
inet_getsockname,
|
||||
lwip_ioctl,
|
||||
#ifdef SAL_USING_POSIX
|
||||
inet_poll,
|
||||
#endif
|
||||
};
|
||||
|
||||
static int inet_create(struct sal_socket *socket, int type, int protocol)
|
||||
|
|
|
@ -25,9 +25,12 @@
|
|||
#ifndef SAL_H__
|
||||
#define SAL_H__
|
||||
|
||||
#include <dfs_file.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
#include <dfs_file.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -40,7 +43,9 @@ typedef uint32_t socklen_t;
|
|||
#define SAL_SOCKET_MAGIC 0x5A10
|
||||
|
||||
/* The maximum number of sockets structure */
|
||||
#ifndef SAL_SOCKETS_NUM
|
||||
#define SAL_SOCKETS_NUM DFS_FD_MAX
|
||||
#endif
|
||||
|
||||
/* The maximum number of protocol families */
|
||||
#ifndef SAL_PROTO_FAMILIES_NUM
|
||||
|
@ -68,7 +73,9 @@ struct proto_ops
|
|||
int (*getpeername)(int s, struct sockaddr *name, socklen_t *namelen);
|
||||
int (*getsockname)(int s, struct sockaddr *name, socklen_t *namelen);
|
||||
int (*ioctlsocket)(int s, long cmd, void *arg);
|
||||
#ifdef SAL_USING_POSIX
|
||||
int (*poll) (struct dfs_fd *file, struct rt_pollreq *req);
|
||||
#endif
|
||||
};
|
||||
|
||||
struct sal_socket
|
||||
|
|
|
@ -26,19 +26,21 @@
|
|||
#ifndef SYS_SOCKET_H_
|
||||
#define SYS_SOCKET_H_
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <sal_socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
|
||||
int bind(int s, const struct sockaddr *name, socklen_t namelen);
|
||||
int shutdown(int s, int how);
|
||||
int getpeername (int s, struct sockaddr *name, socklen_t *namelen);
|
||||
int getsockname (int s, struct sockaddr *name, socklen_t *namelen);
|
||||
int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
|
||||
int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
|
||||
int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
|
||||
int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
|
||||
int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen);
|
||||
int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen);
|
||||
int connect(int s, const struct sockaddr *name, socklen_t namelen);
|
||||
int listen(int s, int backlog);
|
||||
int recv(int s, void *mem, size_t len, int flags);
|
||||
|
@ -50,6 +52,24 @@ int sendto(int s, const void *dataptr, size_t size, int flags,
|
|||
int socket(int domain, int type, int protocol);
|
||||
int closesocket(int s);
|
||||
int ioctlsocket(int s, long cmd, void *arg);
|
||||
#else
|
||||
#define accept(s, addr, addrlen) sal_accept(s, addr, addrlen)
|
||||
#define bind(s, name, namelen) sal_bind(s, name, namelen)
|
||||
#define shutdown(s, how) sal_shutdown(s, how)
|
||||
#define getpeername(s, name, namelen) sal_getpeername(s, name, namelen)
|
||||
#define getsockname(s, name, namelen) sal_getsockname(s, name, namelen)
|
||||
#define getsockopt(s, level, optname, optval, optlen) sal_getsockopt(s, level, optname, optval, optlen)
|
||||
#define setsockopt(s, level, optname, optval, optlen) sal_setsockopt(s, level, optname, optval, optlen)
|
||||
#define connect(s, name, namelen) sal_connect(s, name, namelen)
|
||||
#define listen(s, backlog) sal_listen(s, backlog)
|
||||
#define recv(s, mem, len, flags) sal_recvfrom(s, mem, len, flags, NULL, NULL)
|
||||
#define recvfrom(s, mem, len, flags, from, fromlen) sal_recvfrom(s, mem, len, flags, from, fromlen)
|
||||
#define send(s, dataptr, size, flags) sal_sendto(s, dataptr, size, flags, NULL, NULL)
|
||||
#define sendto(s, dataptr, size, flags, to, tolen) sal_sendto(s, dataptr, size, flags, to, tolen)
|
||||
#define socket(domain, type, protocol) sal_socket(domain, type, protocol)
|
||||
#define closesocket(s) sal_closesocket(s)
|
||||
#define ioctlsocket(s, cmd, arg) sal_ioctlsocket(s, cmd, arg)
|
||||
#endif /* SAL_USING_POSIX */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -705,6 +705,7 @@ int sal_ioctlsocket(int socket, long cmd, void *arg)
|
|||
return sock->ops->ioctlsocket((int) sock->user_data, cmd, arg);
|
||||
}
|
||||
|
||||
#ifdef SAL_USING_POSIX
|
||||
int sal_poll(struct dfs_fd *file, struct rt_pollreq *req)
|
||||
{
|
||||
struct sal_socket *sock;
|
||||
|
@ -723,6 +724,7 @@ int sal_poll(struct dfs_fd *file, struct rt_pollreq *req)
|
|||
|
||||
return sock->ops->poll(file, req);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct hostent *sal_gethostbyname(const char *name)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue