Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逝缘~
rt-thread
提交
192b1775
R
rt-thread
项目概览
逝缘~
/
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,发现更多精彩内容 >>
提交
192b1775
编写于
8月 24, 2018
作者:
Lawlieta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[at][sal] Add query and unregistered protocol family functions
上级
0d737de8
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
159 addition
and
32 deletion
+159
-32
components/net/sal_socket/SConscript
components/net/sal_socket/SConscript
+3
-0
components/net/sal_socket/impl/af_inet.h
components/net/sal_socket/impl/af_inet.h
+40
-0
components/net/sal_socket/impl/af_inet_at.c
components/net/sal_socket/impl/af_inet_at.c
+2
-0
components/net/sal_socket/impl/af_inet_lwip.c
components/net/sal_socket/impl/af_inet_lwip.c
+2
-0
components/net/sal_socket/include/sal.h
components/net/sal_socket/include/sal.h
+9
-4
components/net/sal_socket/socket/net_netdb.c
components/net/sal_socket/socket/net_netdb.c
+1
-0
components/net/sal_socket/src/sal_socket.c
components/net/sal_socket/src/sal_socket.c
+102
-28
未找到文件。
components/net/sal_socket/SConscript
浏览文件 @
192b1775
...
@@ -16,6 +16,9 @@ if GetDepend('SAL_USING_LWIP'):
...
@@ -16,6 +16,9 @@ if GetDepend('SAL_USING_LWIP'):
if
GetDepend
(
'SAL_USING_AT'
):
if
GetDepend
(
'SAL_USING_AT'
):
src
+=
Glob
(
'impl/af_inet_at.c'
)
src
+=
Glob
(
'impl/af_inet_at.c'
)
if
GetDepend
(
'SAL_USING_LWIP'
)
or
GetDepend
(
'SAL_USING_AT'
):
CPPPATH
+=
[
cwd
+
'/impl'
]
if
GetDepend
(
'SAL_USING_POSIX'
):
if
GetDepend
(
'SAL_USING_POSIX'
):
src
+=
Glob
(
'dfs_net/*.c'
)
src
+=
Glob
(
'dfs_net/*.c'
)
...
...
components/net/sal_socket/impl/af_inet.h
0 → 100644
浏览文件 @
192b1775
/*
* File : af_inet.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2018-08-25 ChenYong First version
*/
#ifndef __AF_INET_H__
#define __AF_INET_H__
#include <rtthread.h>
#ifdef SAL_USING_LWIP
/* lwIP protocol family register */
int
lwip_inet_init
(
void
);
#endif
#ifdef SAL_USING_AT
/* AT protocol family register */
int
at_inet_init
(
void
);
#endif
#endif
/* __AF_INET_H__ */
components/net/sal_socket/impl/af_inet_at.c
浏览文件 @
192b1775
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include <sal.h>
#include <sal.h>
#include <at_socket.h>
#include <at_socket.h>
#include <af_inet.h>
#ifdef SAL_USING_POSIX
#ifdef SAL_USING_POSIX
#include <dfs_poll.h>
#include <dfs_poll.h>
...
@@ -107,6 +108,7 @@ static int at_create(struct sal_socket *socket, int type, int protocol)
...
@@ -107,6 +108,7 @@ static int at_create(struct sal_socket *socket, int type, int protocol)
}
}
static
const
struct
proto_family
at_inet_family_ops
=
{
static
const
struct
proto_family
at_inet_family_ops
=
{
"at"
,
AF_AT
,
AF_AT
,
AF_INET
,
AF_INET
,
at_create
,
at_create
,
...
...
components/net/sal_socket/impl/af_inet_lwip.c
浏览文件 @
192b1775
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#endif
#endif
#include <sal.h>
#include <sal.h>
#include <af_inet.h>
#if LWIP_VERSION < 0x2000000
#if LWIP_VERSION < 0x2000000
#define SELWAIT_T int
#define SELWAIT_T int
...
@@ -284,6 +285,7 @@ static int inet_create(struct sal_socket *socket, int type, int protocol)
...
@@ -284,6 +285,7 @@ static int inet_create(struct sal_socket *socket, int type, int protocol)
}
}
static
const
struct
proto_family
lwip_inet_family_ops
=
{
static
const
struct
proto_family
lwip_inet_family_ops
=
{
"lwip"
,
AF_INET
,
AF_INET
,
AF_INET
,
AF_INET
,
inet_create
,
inet_create
,
...
...
components/net/sal_socket/include/sal.h
浏览文件 @
192b1775
...
@@ -82,8 +82,9 @@ struct sal_socket
...
@@ -82,8 +82,9 @@ struct sal_socket
struct
proto_family
struct
proto_family
{
{
int
family
;
/* primary protocol families type*/
char
name
[
RT_NAME_MAX
];
int
sec_family
;
/* secondary protocol families type*/
int
family
;
/* primary protocol families type */
int
sec_family
;
/* secondary protocol families type */
int
(
*
create
)(
struct
sal_socket
*
sal_socket
,
int
type
,
int
protocol
);
/* register socket options */
int
(
*
create
)(
struct
sal_socket
*
sal_socket
,
int
type
,
int
protocol
);
/* register socket options */
struct
hostent
*
(
*
gethostbyname
)
(
const
char
*
name
);
struct
hostent
*
(
*
gethostbyname
)
(
const
char
*
name
);
...
@@ -92,10 +93,14 @@ struct proto_family
...
@@ -92,10 +93,14 @@ struct proto_family
int
(
*
getaddrinfo
)
(
const
char
*
nodename
,
const
char
*
servname
,
const
struct
addrinfo
*
hints
,
struct
addrinfo
**
res
);
int
(
*
getaddrinfo
)
(
const
char
*
nodename
,
const
char
*
servname
,
const
struct
addrinfo
*
hints
,
struct
addrinfo
**
res
);
};
};
/* SAL
socket initialization
*/
/* SAL
(Socket Abstraction Layer) initialize
*/
int
sal_init
(
void
);
int
sal_init
(
void
);
int
sal_proto_family_register
(
const
struct
proto_family
*
pf
);
struct
sal_socket
*
sal_get_socket
(
int
sock
);
struct
sal_socket
*
sal_get_socket
(
int
sock
);
/* protocol family register and unregister operate */
int
sal_proto_family_register
(
const
struct
proto_family
*
pf
);
int
sal_proto_family_unregister
(
const
struct
proto_family
*
pf
);
struct
proto_family
*
sal_proto_family_find
(
const
char
*
name
);
#endif
/* SAL_H__ */
#endif
/* SAL_H__ */
components/net/sal_socket/socket/net_netdb.c
浏览文件 @
192b1775
...
@@ -38,6 +38,7 @@ int gethostbyname_r(const char *name, struct hostent *ret, char *buf,
...
@@ -38,6 +38,7 @@ int gethostbyname_r(const char *name, struct hostent *ret, char *buf,
{
{
return
sal_gethostbyname_r
(
name
,
ret
,
buf
,
buflen
,
result
,
h_errnop
);
return
sal_gethostbyname_r
(
name
,
ret
,
buf
,
buflen
,
result
,
h_errnop
);
}
}
RTM_EXPORT
(
gethostbyname_r
);
void
freeaddrinfo
(
struct
addrinfo
*
ai
)
void
freeaddrinfo
(
struct
addrinfo
*
ai
)
{
{
...
...
components/net/sal_socket/src/sal_socket.c
浏览文件 @
192b1775
...
@@ -50,7 +50,7 @@ static struct rt_mutex sal_core_lock;
...
@@ -50,7 +50,7 @@ static struct rt_mutex sal_core_lock;
static
rt_bool_t
init_ok
=
RT_FALSE
;
static
rt_bool_t
init_ok
=
RT_FALSE
;
/**
/**
* SAL (Socket Abstraction Layer) initializ
ation
.
* SAL (Socket Abstraction Layer) initializ
e
.
*
*
* @return result
* @return result
* >= 0: initialize success
* >= 0: initialize success
...
@@ -64,7 +64,7 @@ int sal_init(void)
...
@@ -64,7 +64,7 @@ int sal_init(void)
}
}
/* clean sal socket table */
/* clean sal socket table */
memset
(
&
socket_table
,
0
,
sizeof
(
socket_table
));
rt_
memset
(
&
socket_table
,
0
,
sizeof
(
socket_table
));
/* create sal socket lock */
/* create sal socket lock */
rt_mutex_init
(
&
sal_core_lock
,
"sal_lock"
,
RT_IPC_FLAG_FIFO
);
rt_mutex_init
(
&
sal_core_lock
,
"sal_lock"
,
RT_IPC_FLAG_FIFO
);
...
@@ -76,12 +76,12 @@ int sal_init(void)
...
@@ -76,12 +76,12 @@ int sal_init(void)
INIT_COMPONENT_EXPORT
(
sal_init
);
INIT_COMPONENT_EXPORT
(
sal_init
);
/**
/**
*
this function will register the current
protocol family to the global array of protocol families.
*
This function will register
protocol family to the global array of protocol families.
*
*
* @param pf protocol famil
ies structure
* @param pf protocol famil
y object
*
*
* @return
0 : protocol families structure
index
* @return
>=0 : protocol family object
index
* -1 : the global array of available protocol families is full
*
-1 : the global array of available protocol families is full
*/
*/
int
sal_proto_family_register
(
const
struct
proto_family
*
pf
)
int
sal_proto_family_register
(
const
struct
proto_family
*
pf
)
{
{
...
@@ -91,6 +91,18 @@ int sal_proto_family_register(const struct proto_family *pf)
...
@@ -91,6 +91,18 @@ int sal_proto_family_register(const struct proto_family *pf)
/* disable interrupt */
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
level
=
rt_hw_interrupt_disable
();
/* check protocol family is already registered */
for
(
idx
=
0
;
idx
<
SAL_PROTO_FAMILIES_NUM
;
idx
++
)
{
if
(
rt_strcmp
(
proto_families
[
idx
].
name
,
pf
->
name
)
==
0
)
{
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
LOG_E
(
"%s protocol family is already registered!"
,
pf
->
name
);
return
-
1
;
}
}
/* find an empty protocol family entry */
/* find an empty protocol family entry */
for
(
idx
=
0
;
idx
<
SAL_PROTO_FAMILIES_NUM
&&
proto_families
[
idx
].
create
;
idx
++
);
for
(
idx
=
0
;
idx
<
SAL_PROTO_FAMILIES_NUM
&&
proto_families
[
idx
].
create
;
idx
++
);
...
@@ -99,10 +111,10 @@ int sal_proto_family_register(const struct proto_family *pf)
...
@@ -99,10 +111,10 @@ int sal_proto_family_register(const struct proto_family *pf)
{
{
/* enable interrupt */
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
rt_hw_interrupt_enable
(
level
);
return
-
1
;
return
-
1
;
}
}
rt_strncpy
(
proto_families
[
idx
].
name
,
pf
->
name
,
rt_strlen
(
pf
->
name
));
proto_families
[
idx
].
family
=
pf
->
family
;
proto_families
[
idx
].
family
=
pf
->
family
;
proto_families
[
idx
].
sec_family
=
pf
->
sec_family
;
proto_families
[
idx
].
sec_family
=
pf
->
sec_family
;
proto_families
[
idx
].
create
=
pf
->
create
;
proto_families
[
idx
].
create
=
pf
->
create
;
...
@@ -119,11 +131,62 @@ int sal_proto_family_register(const struct proto_family *pf)
...
@@ -119,11 +131,62 @@ int sal_proto_family_register(const struct proto_family *pf)
}
}
/**
/**
* this function will get socket structure by sal socket descriptor
* This function removes a previously registered protocol family object.
*
* @param pf protocol family object
*
* @return >=0 : unregister protocol family index
* -1 : unregister failed
*/
int
sal_proto_family_unregister
(
const
struct
proto_family
*
pf
)
{
int
idx
=
0
;
RT_ASSERT
(
pf
!=
RT_NULL
);
for
(
idx
=
0
;
idx
<
SAL_PROTO_FAMILIES_NUM
;
idx
++
)
{
if
(
rt_strcmp
(
proto_families
[
idx
].
name
,
pf
->
name
)
==
0
)
{
rt_memset
(
&
proto_families
[
idx
],
0x00
,
sizeof
(
struct
proto_family
));
return
idx
;
}
}
return
-
1
;
}
/**
* This function will get protocol family by name.
*
* @param name protocol family name
*
* @return protocol family object
*/
struct
proto_family
*
sal_proto_family_find
(
const
char
*
name
)
{
int
idx
=
0
;
RT_ASSERT
(
name
!=
RT_NULL
);
for
(
idx
=
0
;
idx
<
SAL_PROTO_FAMILIES_NUM
;
idx
++
)
{
if
(
rt_strcmp
(
proto_families
[
idx
].
name
,
name
)
==
0
)
{
return
&
proto_families
[
idx
];
}
}
return
RT_NULL
;
}
/**
* This function will get sal socket object by sal socket descriptor.
*
*
* @param socket sal socket index
* @param socket sal socket index
*
*
* @return s
ocket structure
of the current sal socket index
* @return s
al socket object
of the current sal socket index
*/
*/
struct
sal_socket
*
sal_get_socket
(
int
socket
)
struct
sal_socket
*
sal_get_socket
(
int
socket
)
{
{
...
@@ -145,7 +208,7 @@ struct sal_socket *sal_get_socket(int socket)
...
@@ -145,7 +208,7 @@ struct sal_socket *sal_get_socket(int socket)
}
}
/**
/**
*
t
his function will lock sal socket.
*
T
his function will lock sal socket.
*
*
* @note please don't invoke it on ISR.
* @note please don't invoke it on ISR.
*/
*/
...
@@ -161,7 +224,7 @@ static void sal_lock(void)
...
@@ -161,7 +224,7 @@ static void sal_lock(void)
}
}
/**
/**
*
t
his function will lock sal socket.
*
T
his function will lock sal socket.
*
*
* @note please don't invoke it on ISR.
* @note please don't invoke it on ISR.
*/
*/
...
@@ -171,7 +234,7 @@ static void sal_unlock(void)
...
@@ -171,7 +234,7 @@ static void sal_unlock(void)
}
}
/**
/**
*
t
his function will get protocol family structure by family type
*
T
his function will get protocol family structure by family type
*
*
* @param family protocol family
* @param family protocol family
*
*
...
@@ -201,17 +264,17 @@ static struct proto_family *get_proto_family(int family)
...
@@ -201,17 +264,17 @@ static struct proto_family *get_proto_family(int family)
}
}
/**
/**
*
this function will initialize socket structure
and set socket options
*
This function will initialize sal socket object
and set socket options
*
*
* @param family protocol family
* @param family protocol family
* @param type socket type
* @param type socket type
* @param protocol transfer Protocol
* @param protocol transfer Protocol
* @param res s
ocket structure
address
* @param res s
al socket object
address
*
*
* @return 0 : socket initialize success
* @return 0 : socket initialize success
* -1 : input the wrong family
* -1 : input the wrong family
* -2 : input the wrong socket type
* -2 : input the wrong socket type
* -3 : get protocol family
structure
failed
* -3 : get protocol family
object
failed
* -4 : set socket options failed
* -4 : set socket options failed
*/
*/
static
int
socket_init
(
int
family
,
int
type
,
int
protocol
,
struct
sal_socket
**
res
)
static
int
socket_init
(
int
family
,
int
type
,
int
protocol
,
struct
sal_socket
**
res
)
...
@@ -234,7 +297,7 @@ static int socket_init(int family, int type, int protocol, struct sal_socket **r
...
@@ -234,7 +297,7 @@ static int socket_init(int family, int type, int protocol, struct sal_socket **r
sock
->
type
=
type
;
sock
->
type
=
type
;
sock
->
protocol
=
protocol
;
sock
->
protocol
=
protocol
;
/* get socket protocol family
structure
*/
/* get socket protocol family
object
*/
if
((
pf
=
get_proto_family
(
family
))
==
RT_NULL
)
if
((
pf
=
get_proto_family
(
family
))
==
RT_NULL
)
{
{
return
-
3
;
return
-
3
;
...
@@ -301,11 +364,6 @@ __result:
...
@@ -301,11 +364,6 @@ __result:
}
}
/**
* this function will return a empty sal socket structure address
*
* @return sal socket structure address
*/
static
int
socket_new
(
void
)
static
int
socket_new
(
void
)
{
{
struct
sal_socket
*
sock
;
struct
sal_socket
*
sock
;
...
@@ -415,7 +473,7 @@ int sal_shutdown(int socket, int how)
...
@@ -415,7 +473,7 @@ int sal_shutdown(int socket, int how)
if
(
sock
->
ops
->
shutdown
((
int
)
sock
->
user_data
,
how
)
==
0
)
if
(
sock
->
ops
->
shutdown
((
int
)
sock
->
user_data
,
how
)
==
0
)
{
{
memset
(
sock
,
0x00
,
sizeof
(
struct
sal_socket
));
rt_
memset
(
sock
,
0x00
,
sizeof
(
struct
sal_socket
));
return
0
;
return
0
;
}
}
...
@@ -622,7 +680,7 @@ int sal_closesocket(int socket)
...
@@ -622,7 +680,7 @@ int sal_closesocket(int socket)
if
(
sock
->
ops
->
closesocket
((
int
)
sock
->
user_data
)
==
0
)
if
(
sock
->
ops
->
closesocket
((
int
)
sock
->
user_data
)
==
0
)
{
{
memset
(
sock
,
0x00
,
sizeof
(
struct
sal_socket
));
rt_
memset
(
sock
,
0x00
,
sizeof
(
struct
sal_socket
));
return
0
;
return
0
;
}
}
...
@@ -669,12 +727,18 @@ int sal_poll(struct dfs_fd *file, struct rt_pollreq *req)
...
@@ -669,12 +727,18 @@ int sal_poll(struct dfs_fd *file, struct rt_pollreq *req)
struct
hostent
*
sal_gethostbyname
(
const
char
*
name
)
struct
hostent
*
sal_gethostbyname
(
const
char
*
name
)
{
{
int
i
;
int
i
;
struct
hostent
*
hst
;
for
(
i
=
0
;
i
<
SAL_PROTO_FAMILIES_NUM
;
++
i
)
for
(
i
=
0
;
i
<
SAL_PROTO_FAMILIES_NUM
;
++
i
)
{
{
if
(
proto_families
[
i
].
gethostbyname
)
if
(
proto_families
[
i
].
gethostbyname
)
{
{
return
proto_families
[
i
].
gethostbyname
(
name
);
hst
=
proto_families
[
i
].
gethostbyname
(
name
);
if
(
hst
!=
RT_NULL
)
{
return
hst
;
}
continue
;
}
}
}
}
...
@@ -684,13 +748,18 @@ struct hostent *sal_gethostbyname(const char *name)
...
@@ -684,13 +748,18 @@ struct hostent *sal_gethostbyname(const char *name)
int
sal_gethostbyname_r
(
const
char
*
name
,
struct
hostent
*
ret
,
char
*
buf
,
int
sal_gethostbyname_r
(
const
char
*
name
,
struct
hostent
*
ret
,
char
*
buf
,
size_t
buflen
,
struct
hostent
**
result
,
int
*
h_errnop
)
size_t
buflen
,
struct
hostent
**
result
,
int
*
h_errnop
)
{
{
int
i
;
int
i
,
res
;
for
(
i
=
0
;
i
<
SAL_PROTO_FAMILIES_NUM
;
++
i
)
for
(
i
=
0
;
i
<
SAL_PROTO_FAMILIES_NUM
;
++
i
)
{
{
if
(
proto_families
[
i
].
gethostbyname_r
)
if
(
proto_families
[
i
].
gethostbyname_r
)
{
{
return
proto_families
[
i
].
gethostbyname_r
(
name
,
ret
,
buf
,
buflen
,
result
,
h_errnop
);
res
=
proto_families
[
i
].
gethostbyname_r
(
name
,
ret
,
buf
,
buflen
,
result
,
h_errnop
);
if
(
res
==
0
)
{
return
res
;
}
continue
;
}
}
}
}
...
@@ -716,13 +785,18 @@ int sal_getaddrinfo(const char *nodename,
...
@@ -716,13 +785,18 @@ int sal_getaddrinfo(const char *nodename,
const
struct
addrinfo
*
hints
,
const
struct
addrinfo
*
hints
,
struct
addrinfo
**
res
)
struct
addrinfo
**
res
)
{
{
int
i
;
int
i
,
ret
;
for
(
i
=
0
;
i
<
SAL_PROTO_FAMILIES_NUM
;
++
i
)
for
(
i
=
0
;
i
<
SAL_PROTO_FAMILIES_NUM
;
++
i
)
{
{
if
(
proto_families
[
i
].
getaddrinfo
)
if
(
proto_families
[
i
].
getaddrinfo
)
{
{
return
proto_families
[
i
].
getaddrinfo
(
nodename
,
servname
,
hints
,
res
);
ret
=
proto_families
[
i
].
getaddrinfo
(
nodename
,
servname
,
hints
,
res
);
if
(
ret
==
0
)
{
return
ret
;
}
continue
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录