Skip to content

Commit 6d702e5

Browse files
committed
[net][sal] Remove DFS dependencies in the SAL
1 parent 2d894b4 commit 6d702e5

File tree

8 files changed

+66
-22
lines changed

8 files changed

+66
-22
lines changed

components/net/Kconfig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ menu "Socket abstraction layer"
55
config RT_USING_SAL
66
bool "Enable socket abstraction layer"
77
default n
8-
select RT_USING_DFS
98

109
if RT_USING_SAL
1110

@@ -28,14 +27,24 @@ config RT_USING_SAL
2827

2928
config SAL_USING_POSIX
3029
bool "Enable BSD socket operated by file system API"
30+
default y if RT_USING_POSIX
31+
default n
32+
select RT_USING_DFS
3133
select RT_USING_LIBC
3234
select RT_USING_POSIX
33-
default n
3435
help
3536
Let BSD socket operated by file system API, such as read/write and involveed in select/poll POSIX APIs.
37+
38+
if !SAL_USING_POSIX
39+
40+
config SAL_SOCKETS_NUM
41+
int "the maximum number of sockets"
42+
default 16
43+
44+
endif
3645

3746
config SAL_PROTO_FAMILIES_NUM
38-
int "the number of protocol family"
47+
int "the maximum number of protocol families"
3948
default 4
4049

4150
endif

components/net/lwip-2.0.2/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ path = [GetCurrentDir() + '/src',
6767
GetCurrentDir() + '/src/arch/include',
6868
GetCurrentDir() + '/src/include/netif']
6969

70-
if not GetDepend('RT_USING_POSIX') or not GetDepend('SAL_USING_POSIX'):
70+
if not GetDepend('RT_USING_SAL'):
7171
path += [GetCurrentDir() + '/src/include/posix']
7272

7373
if GetDepend(['RT_LWIP_SNMP']):

components/net/sal_socket/SConscript

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ from building import *
55
cwd = GetCurrentDir()
66

77
src = Glob('src/*.c')
8-
src += Glob('socket/*.c')
8+
src += Glob('socket/net_netdb.c')
99

1010
CPPPATH = [cwd + '/include']
11-
CPPPATH += [cwd + '/include/dfs_net']
1211
CPPPATH += [cwd + '/include/socket']
1312

1413
if GetDepend('SAL_USING_LWIP'):
@@ -21,6 +20,8 @@ if GetDepend('SAL_USING_LWIP') or GetDepend('SAL_USING_AT'):
2120
CPPPATH += [cwd + '/impl']
2221

2322
if GetDepend('SAL_USING_POSIX'):
23+
CPPPATH += [cwd + '/include/dfs_net']
24+
src += Glob('socket/net_sockets.c')
2425
src += Glob('dfs_net/*.c')
2526

2627
if not GetDepend('HAVE_SYS_SELECT_H'):

components/net/sal_socket/impl/af_inet_at.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* 2018-06-06 ChenYong First version
2323
*/
2424

25+
#include <rtthread.h>
26+
2527
#include <netdb.h>
2628
#include <sal.h>
2729

@@ -91,8 +93,6 @@ static const struct proto_ops at_inet_stream_ops =
9193

9294
#ifdef SAL_USING_POSIX
9395
at_poll,
94-
#else
95-
NULL,
9696
#endif /* SAL_USING_POSIX */
9797
};
9898

components/net/sal_socket/impl/af_inet_lwip.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#endif
4545
#endif
4646

47+
#ifdef SAL_USING_POSIX
4748
/*
4849
* Re-define lwip socket
4950
*
@@ -73,9 +74,7 @@ struct lwip_sock {
7374
/** counter of how many threads are waiting for this socket using select */
7475
SELWAIT_T select_waiting;
7576

76-
#ifdef SAL_USING_POSIX
7777
rt_wqueue_t wait_head;
78-
#endif
7978
};
8079

8180
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
160159

161160
if (event)
162161
{
163-
#ifdef SAL_USING_POSIX
164162
rt_wqueue_wakeup(&sock->wait_head, (void*) event);
165-
#endif
166163
}
167164
}
165+
#endif /* SAL_USING_POSIX */
168166

169167
static int inet_socket(int domain, int type, int protocol)
170168
{
169+
#ifdef SAL_USING_POSIX
171170
int socket;
172171

173172
socket = lwip_socket(domain, type, protocol);
@@ -178,17 +177,18 @@ static int inet_socket(int domain, int type, int protocol)
178177
lwsock = lwip_tryget_socket(socket);
179178
lwsock->conn->callback = event_callback;
180179

181-
#ifdef SAL_USING_POSIX
182180
rt_wqueue_init(&lwsock->wait_head);
183-
#endif
184-
185181
}
186182

187183
return socket;
184+
#else
185+
return lwip_socket(domain, type, protocol);
186+
#endif /* SAL_USING_POSIX */
188187
}
189188

190189
static int inet_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
191190
{
191+
#ifdef SAL_USING_POSIX
192192
int new_socket;
193193

194194
new_socket = lwip_accept(socket, addr, addrlen);
@@ -198,12 +198,13 @@ static int inet_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
198198

199199
lwsock = lwip_tryget_socket(new_socket);
200200

201-
#ifdef SAL_USING_POSIX
202201
rt_wqueue_init(&lwsock->wait_head);
203-
#endif
204202
}
205203

206204
return new_socket;
205+
#else
206+
return lwip_accept(socket, addr, addrlen);
207+
#endif /* SAL_USING_POSIX */
207208
}
208209

209210
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
216217
return lwip_getsockname(socket, name, namelen);
217218
}
218219

220+
#ifdef SAL_USING_POSIX
219221
static int inet_poll(struct dfs_fd *file, struct rt_pollreq *req)
220222
{
221223
int mask = 0;
@@ -253,6 +255,7 @@ static int inet_poll(struct dfs_fd *file, struct rt_pollreq *req)
253255

254256
return mask;
255257
}
258+
#endif
256259

257260
static const struct proto_ops lwip_inet_stream_ops = {
258261
inet_socket,
@@ -270,7 +273,9 @@ static const struct proto_ops lwip_inet_stream_ops = {
270273
lwip_getpeername,
271274
inet_getsockname,
272275
lwip_ioctl,
276+
#ifdef SAL_USING_POSIX
273277
inet_poll,
278+
#endif
274279
};
275280

276281
static int inet_create(struct sal_socket *socket, int type, int protocol)

components/net/sal_socket/include/sal.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
#ifndef SAL_H__
2626
#define SAL_H__
2727

28-
#include <dfs_file.h>
2928
#include <rtdevice.h>
3029

30+
#ifdef SAL_USING_POSIX
31+
#include <dfs_file.h>
32+
#endif
33+
3134
#ifdef __cplusplus
3235
extern "C" {
3336
#endif
@@ -40,7 +43,9 @@ typedef uint32_t socklen_t;
4043
#define SAL_SOCKET_MAGIC 0x5A10
4144

4245
/* The maximum number of sockets structure */
46+
#ifndef SAL_SOCKETS_NUM
4347
#define SAL_SOCKETS_NUM DFS_FD_MAX
48+
#endif
4449

4550
/* The maximum number of protocol families */
4651
#ifndef SAL_PROTO_FAMILIES_NUM
@@ -68,7 +73,9 @@ struct proto_ops
6873
int (*getpeername)(int s, struct sockaddr *name, socklen_t *namelen);
6974
int (*getsockname)(int s, struct sockaddr *name, socklen_t *namelen);
7075
int (*ioctlsocket)(int s, long cmd, void *arg);
76+
#ifdef SAL_USING_POSIX
7177
int (*poll) (struct dfs_fd *file, struct rt_pollreq *req);
78+
#endif
7279
};
7380

7481
struct sal_socket

components/net/sal_socket/include/socket/sys_socket/sys/socket.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@
2626
#ifndef SYS_SOCKET_H_
2727
#define SYS_SOCKET_H_
2828

29+
#include <rtthread.h>
2930
#include <sal_socket.h>
3031

3132
#ifdef __cplusplus
3233
extern "C" {
3334
#endif
3435

36+
#ifdef SAL_USING_POSIX
3537
int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
3638
int bind(int s, const struct sockaddr *name, socklen_t namelen);
3739
int shutdown(int s, int how);
38-
int getpeername (int s, struct sockaddr *name, socklen_t *namelen);
39-
int getsockname (int s, struct sockaddr *name, socklen_t *namelen);
40-
int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
41-
int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
40+
int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
41+
int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
42+
int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen);
43+
int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen);
4244
int connect(int s, const struct sockaddr *name, socklen_t namelen);
4345
int listen(int s, int backlog);
4446
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,
5052
int socket(int domain, int type, int protocol);
5153
int closesocket(int s);
5254
int ioctlsocket(int s, long cmd, void *arg);
55+
#else
56+
#define accept(s, addr, addrlen) sal_accept(s, addr, addrlen)
57+
#define bind(s, name, namelen) sal_bind(s, name, namelen)
58+
#define shutdown(s, how) sal_shutdown(s, how)
59+
#define getpeername(s, name, namelen) sal_getpeername(s, name, namelen)
60+
#define getsockname(s, name, namelen) sal_getsockname(s, name, namelen)
61+
#define getsockopt(s, level, optname, optval, optlen) sal_getsockopt(s, level, optname, optval, optlen)
62+
#define setsockopt(s, level, optname, optval, optlen) sal_setsockopt(s, level, optname, optval, optlen)
63+
#define connect(s, name, namelen) sal_connect(s, name, namelen)
64+
#define listen(s, backlog) sal_listen(s, backlog)
65+
#define recv(s, mem, len, flags) sal_recvfrom(s, mem, len, flags, NULL, NULL)
66+
#define recvfrom(s, mem, len, flags, from, fromlen) sal_recvfrom(s, mem, len, flags, from, fromlen)
67+
#define send(s, dataptr, size, flags) sal_sendto(s, dataptr, size, flags, NULL, NULL)
68+
#define sendto(s, dataptr, size, flags, to, tolen) sal_sendto(s, dataptr, size, flags, to, tolen)
69+
#define socket(domain, type, protocol) sal_socket(domain, type, protocol)
70+
#define closesocket(s) sal_closesocket(s)
71+
#define ioctlsocket(s, cmd, arg) sal_ioctlsocket(s, cmd, arg)
72+
#endif /* SAL_USING_POSIX */
5373

5474
#ifdef __cplusplus
5575
}

components/net/sal_socket/src/sal_socket.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ int sal_ioctlsocket(int socket, long cmd, void *arg)
705705
return sock->ops->ioctlsocket((int) sock->user_data, cmd, arg);
706706
}
707707

708+
#ifdef SAL_USING_POSIX
708709
int sal_poll(struct dfs_fd *file, struct rt_pollreq *req)
709710
{
710711
struct sal_socket *sock;
@@ -723,6 +724,7 @@ int sal_poll(struct dfs_fd *file, struct rt_pollreq *req)
723724

724725
return sock->ops->poll(file, req);
725726
}
727+
#endif
726728

727729
struct hostent *sal_gethostbyname(const char *name)
728730
{

0 commit comments

Comments
 (0)