Skip to content

Commit 9028cb2

Browse files
authored
Merge pull request #1743 from chenyong111/master
Remove DFS dependencies in the SAL
2 parents 9fdd46f + 6d702e5 commit 9028cb2

File tree

10 files changed

+88
-44
lines changed

10 files changed

+88
-44
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/at/at_socket/at_socket.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
((unsigned char *)&addr)[2], \
4747
((unsigned char *)&addr)[3]
4848

49-
#ifdef AT_DEVICE_NOT_SELECTED
49+
#if !defined(AT_DEVICE_SOCKETS_NUM) || defined(AT_DEVICE_NOT_SELECTED)
5050
#error The AT socket device is not selected, please select it through the env menuconfig.
5151
#endif
5252

@@ -398,7 +398,7 @@ int at_closesocket(int socket)
398398

399399
if (last_state == AT_SOCKET_CONNECT)
400400
{
401-
if (at_dev_ops->close(socket) != 0)
401+
if (at_dev_ops->at_closesocket(socket) != 0)
402402
{
403403
LOG_E("AT socket (%d) closesocket failed!", socket);
404404
}
@@ -424,7 +424,7 @@ int at_shutdown(int socket, int how)
424424

425425
if (sock->state == AT_SOCKET_CONNECT)
426426
{
427-
if (at_dev_ops->close(socket) != 0)
427+
if (at_dev_ops->at_closesocket(socket) != 0)
428428
{
429429
LOG_E("AT socket (%d) shutdown failed!", socket);
430430
}
@@ -535,7 +535,7 @@ int at_connect(int socket, const struct sockaddr *name, socklen_t namelen)
535535
socketaddr_to_ipaddr_port(name, &remote_addr, &remote_port);
536536
ipaddr_to_ipstr(name, ipstr);
537537

538-
if (at_dev_ops->connect(socket, ipstr, remote_port, sock->type, RT_TRUE) < 0)
538+
if (at_dev_ops->at_connect(socket, ipstr, remote_port, sock->type, RT_TRUE) < 0)
539539
{
540540
LOG_E("AT socket(%d) connect failed!", socket);
541541
result = -1;
@@ -545,8 +545,8 @@ int at_connect(int socket, const struct sockaddr *name, socklen_t namelen)
545545
sock->state = AT_SOCKET_CONNECT;
546546

547547
/* set AT socket receive data callback function */
548-
at_dev_ops->set_event_cb(AT_SOCKET_EVT_RECV, at_recv_notice_cb);
549-
at_dev_ops->set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb);
548+
at_dev_ops->at_set_event_cb(AT_SOCKET_EVT_RECV, at_recv_notice_cb);
549+
at_dev_ops->at_set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb);
550550

551551
__exit:
552552

@@ -593,7 +593,7 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f
593593
socketaddr_to_ipaddr_port(from, &remote_addr, &remote_port);
594594
ipaddr_to_ipstr(from, ipstr);
595595

596-
if (at_dev_ops->connect(socket, ipstr, remote_port, sock->type, RT_TRUE) < 0)
596+
if (at_dev_ops->at_connect(socket, ipstr, remote_port, sock->type, RT_TRUE) < 0)
597597
{
598598
LOG_E("AT socket UDP connect failed!");
599599
result = -1;
@@ -719,7 +719,7 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct
719719
goto __exit;
720720
}
721721

722-
if ((len = at_dev_ops->send(sock->socket, (const char *) data, size, sock->type)) < 0)
722+
if ((len = at_dev_ops->at_send(sock->socket, (const char *) data, size, sock->type)) < 0)
723723
{
724724
result = -1;
725725
goto __exit;
@@ -736,7 +736,7 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct
736736
socketaddr_to_ipaddr_port(to, &remote_addr, &remote_port);
737737
ipaddr_to_ipstr(to, ipstr);
738738

739-
if (at_dev_ops->connect(socket, ipstr, remote_port, sock->type, RT_TRUE) < 0)
739+
if (at_dev_ops->at_connect(socket, ipstr, remote_port, sock->type, RT_TRUE) < 0)
740740
{
741741
LOG_E("AT socket (%d) UDP connect failed!", socket);
742742
result = -1;
@@ -745,7 +745,7 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct
745745
sock->state = AT_SOCKET_CONNECT;
746746
}
747747

748-
if ((len = at_dev_ops->send(sock->socket, (char *) data, size, sock->type)) < 0)
748+
if ((len = at_dev_ops->at_send(sock->socket, (char *) data, size, sock->type)) < 0)
749749
{
750750
result = -1;
751751
goto __exit;
@@ -940,7 +940,7 @@ struct hostent *at_gethostbyname(const char *name)
940940

941941
if (idx < strlen(name))
942942
{
943-
if (at_dev_ops->domain_resolve(name, ipstr) < 0)
943+
if (at_dev_ops->at_domain_resolve(name, ipstr) < 0)
944944
{
945945
LOG_E("AT domain (%s) resolve error!", name);
946946
return RT_NULL;
@@ -1040,7 +1040,7 @@ int at_getaddrinfo(const char *nodename, const char *servname,
10401040

10411041
if(idx < strlen(nodename))
10421042
{
1043-
if (at_dev_ops->domain_resolve((char *) nodename, ip_str) != 0)
1043+
if (at_dev_ops->at_domain_resolve((char *) nodename, ip_str) != 0)
10441044
{
10451045
return EAI_FAIL;
10461046
}
@@ -1129,10 +1129,10 @@ void at_freeaddrinfo(struct addrinfo *ai)
11291129
void at_scoket_device_register(const struct at_device_ops *ops)
11301130
{
11311131
RT_ASSERT(ops);
1132-
RT_ASSERT(ops->connect);
1133-
RT_ASSERT(ops->close);
1134-
RT_ASSERT(ops->send);
1135-
RT_ASSERT(ops->domain_resolve);
1136-
RT_ASSERT(ops->set_event_cb);
1132+
RT_ASSERT(ops->at_connect);
1133+
RT_ASSERT(ops->at_closesocket);
1134+
RT_ASSERT(ops->at_send);
1135+
RT_ASSERT(ops->at_domain_resolve);
1136+
RT_ASSERT(ops->at_set_event_cb);
11371137
at_dev_ops = (struct at_device_ops *) ops;
11381138
}

components/net/at/at_socket/at_socket.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ typedef void (* at_socket_callback)(struct at_socket *conn, int event, uint16_t
7777
/* AT device socket options function */
7878
struct at_device_ops
7979
{
80-
int (*connect)(int socket, char *ip, int32_t port, enum at_socket_type type, rt_bool_t is_client);
81-
int (*close)(int socket);
82-
int (*send)(int socket, const char *buff, size_t bfsz, enum at_socket_type type);
83-
int (*domain_resolve)(const char *name, char ip[16]);
84-
void (*set_event_cb)(at_socket_evt_t event, at_evt_cb_t cb);
80+
int (*at_connect)(int socket, char *ip, int32_t port, enum at_socket_type type, rt_bool_t is_client);
81+
int (*at_closesocket)(int socket);
82+
int (*at_send)(int socket, const char *buff, size_t bfsz, enum at_socket_type type);
83+
int (*at_domain_resolve)(const char *name, char ip[16]);
84+
void (*at_set_event_cb)(at_socket_evt_t event, at_evt_cb_t cb);
8585
};
8686

8787
/* AT receive package list structure */

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

0 commit comments

Comments
 (0)