Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Keyboard Man_俊
rt-thread
提交
9028cb29
R
rt-thread
项目概览
Keyboard Man_俊
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9028cb29
编写于
8月 28, 2018
作者:
B
Bernard Xiong
提交者:
GitHub
8月 28, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1743 from chenyong111/master
Remove DFS dependencies in the SAL
上级
9fdd46fa
6d702e57
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
88 addition
and
44 deletion
+88
-44
components/net/Kconfig
components/net/Kconfig
+12
-3
components/net/at/at_socket/at_socket.c
components/net/at/at_socket/at_socket.c
+17
-17
components/net/at/at_socket/at_socket.h
components/net/at/at_socket/at_socket.h
+5
-5
components/net/lwip-2.0.2/SConscript
components/net/lwip-2.0.2/SConscript
+1
-1
components/net/sal_socket/SConscript
components/net/sal_socket/SConscript
+3
-2
components/net/sal_socket/impl/af_inet_at.c
components/net/sal_socket/impl/af_inet_at.c
+2
-2
components/net/sal_socket/impl/af_inet_lwip.c
components/net/sal_socket/impl/af_inet_lwip.c
+14
-9
components/net/sal_socket/include/sal.h
components/net/sal_socket/include/sal.h
+8
-1
components/net/sal_socket/include/socket/sys_socket/sys/socket.h
...nts/net/sal_socket/include/socket/sys_socket/sys/socket.h
+24
-4
components/net/sal_socket/src/sal_socket.c
components/net/sal_socket/src/sal_socket.c
+2
-0
未找到文件。
components/net/Kconfig
浏览文件 @
9028cb29
...
...
@@ -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
...
...
components/net/at/at_socket/at_socket.c
浏览文件 @
9028cb29
...
...
@@ -46,7 +46,7 @@
((unsigned char *)&addr)[2], \
((unsigned char *)&addr)[3]
#if
def AT_DEVICE_NOT_SELECTED
#if
!defined(AT_DEVICE_SOCKETS_NUM) || defined(AT_DEVICE_NOT_SELECTED)
#error The AT socket device is not selected, please select it through the env menuconfig.
#endif
...
...
@@ -398,7 +398,7 @@ int at_closesocket(int socket)
if
(
last_state
==
AT_SOCKET_CONNECT
)
{
if
(
at_dev_ops
->
close
(
socket
)
!=
0
)
if
(
at_dev_ops
->
at_closesocket
(
socket
)
!=
0
)
{
LOG_E
(
"AT socket (%d) closesocket failed!"
,
socket
);
}
...
...
@@ -424,7 +424,7 @@ int at_shutdown(int socket, int how)
if
(
sock
->
state
==
AT_SOCKET_CONNECT
)
{
if
(
at_dev_ops
->
close
(
socket
)
!=
0
)
if
(
at_dev_ops
->
at_closesocket
(
socket
)
!=
0
)
{
LOG_E
(
"AT socket (%d) shutdown failed!"
,
socket
);
}
...
...
@@ -535,7 +535,7 @@ int at_connect(int socket, const struct sockaddr *name, socklen_t namelen)
socketaddr_to_ipaddr_port
(
name
,
&
remote_addr
,
&
remote_port
);
ipaddr_to_ipstr
(
name
,
ipstr
);
if
(
at_dev_ops
->
connect
(
socket
,
ipstr
,
remote_port
,
sock
->
type
,
RT_TRUE
)
<
0
)
if
(
at_dev_ops
->
at_
connect
(
socket
,
ipstr
,
remote_port
,
sock
->
type
,
RT_TRUE
)
<
0
)
{
LOG_E
(
"AT socket(%d) connect failed!"
,
socket
);
result
=
-
1
;
...
...
@@ -545,8 +545,8 @@ int at_connect(int socket, const struct sockaddr *name, socklen_t namelen)
sock
->
state
=
AT_SOCKET_CONNECT
;
/* set AT socket receive data callback function */
at_dev_ops
->
set_event_cb
(
AT_SOCKET_EVT_RECV
,
at_recv_notice_cb
);
at_dev_ops
->
set_event_cb
(
AT_SOCKET_EVT_CLOSED
,
at_closed_notice_cb
);
at_dev_ops
->
at_
set_event_cb
(
AT_SOCKET_EVT_RECV
,
at_recv_notice_cb
);
at_dev_ops
->
at_
set_event_cb
(
AT_SOCKET_EVT_CLOSED
,
at_closed_notice_cb
);
__exit:
...
...
@@ -593,7 +593,7 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f
socketaddr_to_ipaddr_port
(
from
,
&
remote_addr
,
&
remote_port
);
ipaddr_to_ipstr
(
from
,
ipstr
);
if
(
at_dev_ops
->
connect
(
socket
,
ipstr
,
remote_port
,
sock
->
type
,
RT_TRUE
)
<
0
)
if
(
at_dev_ops
->
at_
connect
(
socket
,
ipstr
,
remote_port
,
sock
->
type
,
RT_TRUE
)
<
0
)
{
LOG_E
(
"AT socket UDP connect failed!"
);
result
=
-
1
;
...
...
@@ -719,7 +719,7 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct
goto
__exit
;
}
if
((
len
=
at_dev_ops
->
send
(
sock
->
socket
,
(
const
char
*
)
data
,
size
,
sock
->
type
))
<
0
)
if
((
len
=
at_dev_ops
->
at_
send
(
sock
->
socket
,
(
const
char
*
)
data
,
size
,
sock
->
type
))
<
0
)
{
result
=
-
1
;
goto
__exit
;
...
...
@@ -736,7 +736,7 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct
socketaddr_to_ipaddr_port
(
to
,
&
remote_addr
,
&
remote_port
);
ipaddr_to_ipstr
(
to
,
ipstr
);
if
(
at_dev_ops
->
connect
(
socket
,
ipstr
,
remote_port
,
sock
->
type
,
RT_TRUE
)
<
0
)
if
(
at_dev_ops
->
at_
connect
(
socket
,
ipstr
,
remote_port
,
sock
->
type
,
RT_TRUE
)
<
0
)
{
LOG_E
(
"AT socket (%d) UDP connect failed!"
,
socket
);
result
=
-
1
;
...
...
@@ -745,7 +745,7 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct
sock
->
state
=
AT_SOCKET_CONNECT
;
}
if
((
len
=
at_dev_ops
->
send
(
sock
->
socket
,
(
char
*
)
data
,
size
,
sock
->
type
))
<
0
)
if
((
len
=
at_dev_ops
->
at_
send
(
sock
->
socket
,
(
char
*
)
data
,
size
,
sock
->
type
))
<
0
)
{
result
=
-
1
;
goto
__exit
;
...
...
@@ -940,7 +940,7 @@ struct hostent *at_gethostbyname(const char *name)
if
(
idx
<
strlen
(
name
))
{
if
(
at_dev_ops
->
domain_resolve
(
name
,
ipstr
)
<
0
)
if
(
at_dev_ops
->
at_
domain_resolve
(
name
,
ipstr
)
<
0
)
{
LOG_E
(
"AT domain (%s) resolve error!"
,
name
);
return
RT_NULL
;
...
...
@@ -1040,7 +1040,7 @@ int at_getaddrinfo(const char *nodename, const char *servname,
if
(
idx
<
strlen
(
nodename
))
{
if
(
at_dev_ops
->
domain_resolve
((
char
*
)
nodename
,
ip_str
)
!=
0
)
if
(
at_dev_ops
->
at_
domain_resolve
((
char
*
)
nodename
,
ip_str
)
!=
0
)
{
return
EAI_FAIL
;
}
...
...
@@ -1129,10 +1129,10 @@ void at_freeaddrinfo(struct addrinfo *ai)
void
at_scoket_device_register
(
const
struct
at_device_ops
*
ops
)
{
RT_ASSERT
(
ops
);
RT_ASSERT
(
ops
->
connect
);
RT_ASSERT
(
ops
->
close
);
RT_ASSERT
(
ops
->
send
);
RT_ASSERT
(
ops
->
domain_resolve
);
RT_ASSERT
(
ops
->
set_event_cb
);
RT_ASSERT
(
ops
->
at_
connect
);
RT_ASSERT
(
ops
->
at_closesocket
);
RT_ASSERT
(
ops
->
at_
send
);
RT_ASSERT
(
ops
->
at_
domain_resolve
);
RT_ASSERT
(
ops
->
at_
set_event_cb
);
at_dev_ops
=
(
struct
at_device_ops
*
)
ops
;
}
components/net/at/at_socket/at_socket.h
浏览文件 @
9028cb29
...
...
@@ -77,11 +77,11 @@ typedef void (* at_socket_callback)(struct at_socket *conn, int event, uint16_t
/* AT device socket options function */
struct
at_device_ops
{
int
(
*
connect
)(
int
socket
,
char
*
ip
,
int32_t
port
,
enum
at_socket_type
type
,
rt_bool_t
is_client
);
int
(
*
close
)(
int
socket
);
int
(
*
send
)(
int
socket
,
const
char
*
buff
,
size_t
bfsz
,
enum
at_socket_type
type
);
int
(
*
domain_resolve
)(
const
char
*
name
,
char
ip
[
16
]);
void
(
*
set_event_cb
)(
at_socket_evt_t
event
,
at_evt_cb_t
cb
);
int
(
*
at_
connect
)(
int
socket
,
char
*
ip
,
int32_t
port
,
enum
at_socket_type
type
,
rt_bool_t
is_client
);
int
(
*
at_closesocket
)(
int
socket
);
int
(
*
at_
send
)(
int
socket
,
const
char
*
buff
,
size_t
bfsz
,
enum
at_socket_type
type
);
int
(
*
at_
domain_resolve
)(
const
char
*
name
,
char
ip
[
16
]);
void
(
*
at_
set_event_cb
)(
at_socket_evt_t
event
,
at_evt_cb_t
cb
);
};
/* AT receive package list structure */
...
...
components/net/lwip-2.0.2/SConscript
浏览文件 @
9028cb29
...
...
@@ -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'
]):
...
...
components/net/sal_socket/SConscript
浏览文件 @
9028cb29
...
...
@@ -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'
):
...
...
components/net/sal_socket/impl/af_inet_at.c
浏览文件 @
9028cb29
...
...
@@ -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 */
};
...
...
components/net/sal_socket/impl/af_inet_lwip.c
浏览文件 @
9028cb29
...
...
@@ -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
)
...
...
components/net/sal_socket/include/sal.h
浏览文件 @
9028cb29
...
...
@@ -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
...
...
components/net/sal_socket/include/socket/sys_socket/sys/socket.h
浏览文件 @
9028cb29
...
...
@@ -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
}
...
...
components/net/sal_socket/src/sal_socket.c
浏览文件 @
9028cb29
...
...
@@ -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
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录