Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢走~
rt-thread
提交
30c43a09
R
rt-thread
项目概览
慢慢走~
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
2
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,发现更多精彩内容 >>
未验证
提交
30c43a09
编写于
9月 05, 2019
作者:
B
Bernard Xiong
提交者:
GitHub
9月 05, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3030 from enkiller/pr
[components][net][sal]修复多线程访问创建相同fd的问题
上级
03f8762e
4219eb7f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
67 addition
and
39 deletion
+67
-39
components/net/sal_socket/src/sal_socket.c
components/net/sal_socket/src/sal_socket.c
+67
-39
未找到文件。
components/net/sal_socket/src/sal_socket.c
浏览文件 @
30c43a09
...
@@ -148,7 +148,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
...
@@ -148,7 +148,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
char
send_data
[
SAL_INTERNET_BUFF_LEN
],
recv_data
=
0
;
char
send_data
[
SAL_INTERNET_BUFF_LEN
],
recv_data
=
0
;
struct
rt_delayed_work
*
delay_work
=
(
struct
rt_delayed_work
*
)
work
;
struct
rt_delayed_work
*
delay_work
=
(
struct
rt_delayed_work
*
)
work
;
const
char
month
[][
SAL_INTERNET_MONTH_LEN
]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
const
char
month
[][
SAL_INTERNET_MONTH_LEN
]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
char
date
[
SAL_INTERNET_DATE_LEN
];
char
date
[
SAL_INTERNET_DATE_LEN
];
int
moth_num
=
0
;
int
moth_num
=
0
;
...
@@ -175,7 +175,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
...
@@ -175,7 +175,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
}
}
skt_ops
=
pf
->
skt_ops
;
skt_ops
=
pf
->
skt_ops
;
if
((
sockfd
=
skt_ops
->
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
<
0
)
if
((
sockfd
=
skt_ops
->
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
<
0
)
{
{
result
=
-
RT_ERROR
;
result
=
-
RT_ERROR
;
goto
__exit
;
goto
__exit
;
...
@@ -316,10 +316,7 @@ struct sal_socket *sal_get_socket(int socket)
...
@@ -316,10 +316,7 @@ struct sal_socket *sal_get_socket(int socket)
socket
=
socket
-
SAL_SOCKET_OFFSET
;
socket
=
socket
-
SAL_SOCKET_OFFSET
;
/* check socket structure valid or not */
/* check socket structure valid or not */
if
(
st
->
sockets
[
socket
]
->
magic
!=
SAL_SOCKET_MAGIC
)
RT_ASSERT
(
st
->
sockets
[
socket
]
->
magic
==
SAL_SOCKET_MAGIC
);
{
return
RT_NULL
;
}
return
st
->
sockets
[
socket
];
return
st
->
sockets
[
socket
];
}
}
...
@@ -376,7 +373,8 @@ int sal_netdev_cleanup(struct netdev *netdev)
...
@@ -376,7 +373,8 @@ int sal_netdev_cleanup(struct netdev *netdev)
{
{
rt_thread_mdelay
(
rt_tick_from_millisecond
(
100
));
rt_thread_mdelay
(
rt_tick_from_millisecond
(
100
));
}
}
}
while
(
find_dev
);
}
while
(
find_dev
);
return
0
;
return
0
;
}
}
...
@@ -452,8 +450,7 @@ static int socket_alloc(struct sal_socket_table *st, int f_socket)
...
@@ -452,8 +450,7 @@ static int socket_alloc(struct sal_socket_table *st, int f_socket)
/* find an empty socket entry */
/* find an empty socket entry */
for
(
idx
=
f_socket
;
idx
<
(
int
)
st
->
max_socket
;
idx
++
)
for
(
idx
=
f_socket
;
idx
<
(
int
)
st
->
max_socket
;
idx
++
)
{
{
if
(
st
->
sockets
[
idx
]
==
RT_NULL
||
if
(
st
->
sockets
[
idx
]
==
RT_NULL
)
st
->
sockets
[
idx
]
->
netdev
==
RT_NULL
)
{
{
break
;
break
;
}
}
...
@@ -497,6 +494,15 @@ __result:
...
@@ -497,6 +494,15 @@ __result:
return
idx
;
return
idx
;
}
}
static
void
socket_free
(
struct
sal_socket_table
*
st
,
int
idx
)
{
struct
sal_socket
*
sock
;
sock
=
st
->
sockets
[
idx
];
st
->
sockets
[
idx
]
=
RT_NULL
;
rt_free
(
sock
);
}
static
int
socket_new
(
void
)
static
int
socket_new
(
void
)
{
{
struct
sal_socket
*
sock
;
struct
sal_socket
*
sock
;
...
@@ -529,6 +535,26 @@ __result:
...
@@ -529,6 +535,26 @@ __result:
return
idx
+
SAL_SOCKET_OFFSET
;
return
idx
+
SAL_SOCKET_OFFSET
;
}
}
static
void
socket_delete
(
int
socket
)
{
struct
sal_socket
*
sock
;
struct
sal_socket_table
*
st
=
&
socket_table
;
int
idx
;
idx
=
socket
-
SAL_SOCKET_OFFSET
;
if
(
idx
<
0
||
idx
>=
(
int
)
st
->
max_socket
)
{
return
;
}
sal_lock
();
sock
=
sal_get_socket
(
socket
);
RT_ASSERT
(
sock
!=
RT_NULL
);
sock
->
magic
=
0
;
sock
->
netdev
=
RT_NULL
;
socket_free
(
st
,
idx
);
sal_unlock
();
}
int
sal_accept
(
int
socket
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
)
int
sal_accept
(
int
socket
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
)
{
{
int
new_socket
;
int
new_socket
;
...
@@ -550,18 +576,20 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
...
@@ -550,18 +576,20 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
/* allocate a new socket structure and registered socket options */
/* allocate a new socket structure and registered socket options */
new_sal_socket
=
socket_new
();
new_sal_socket
=
socket_new
();
if
(
new_sal_socket
<
0
)
new_sock
=
sal_get_socket
(
new_sal_socket
);
if
(
new_sock
==
RT_NULL
)
{
{
pf
->
skt_ops
->
closesocket
(
new_socket
);
pf
->
skt_ops
->
closesocket
(
new_socket
);
return
-
1
;
return
-
1
;
}
}
new_sock
=
sal_get_socket
(
new_sal_socket
);
retval
=
socket_init
(
sock
->
domain
,
sock
->
type
,
sock
->
protocol
,
&
new_sock
);
retval
=
socket_init
(
sock
->
domain
,
sock
->
type
,
sock
->
protocol
,
&
new_sock
);
if
(
retval
<
0
)
if
(
retval
<
0
)
{
{
pf
->
skt_ops
->
closesocket
(
new_socket
);
pf
->
skt_ops
->
closesocket
(
new_socket
);
rt_memset
(
new_sock
,
0x00
,
sizeof
(
struct
sal_socket
));
rt_memset
(
new_sock
,
0x00
,
sizeof
(
struct
sal_socket
));
/* socket init failed, delete socket */
socket_delete
(
new_sal_socket
);
LOG_E
(
"New socket registered failed, return error %d."
,
retval
);
LOG_E
(
"New socket registered failed, return error %d."
,
retval
);
return
-
1
;
return
-
1
;
}
}
...
@@ -673,9 +701,8 @@ int sal_shutdown(int socket, int how)
...
@@ -673,9 +701,8 @@ int sal_shutdown(int socket, int how)
error
=
-
1
;
error
=
-
1
;
}
}
/* free socket */
/* delete socket */
rt_free
(
sock
);
socket_delete
(
socket
);
socket_table
.
sockets
[
socket
]
=
RT_NULL
;
return
error
;
return
error
;
}
}
...
@@ -907,6 +934,7 @@ int sal_socket(int domain, int type, int protocol)
...
@@ -907,6 +934,7 @@ int sal_socket(int domain, int type, int protocol)
if
(
retval
<
0
)
if
(
retval
<
0
)
{
{
LOG_E
(
"SAL socket protocol family input failed, return error %d."
,
retval
);
LOG_E
(
"SAL socket protocol family input failed, return error %d."
,
retval
);
socket_delete
(
socket
);
return
-
1
;
return
-
1
;
}
}
...
@@ -922,6 +950,7 @@ int sal_socket(int domain, int type, int protocol)
...
@@ -922,6 +950,7 @@ int sal_socket(int domain, int type, int protocol)
sock
->
user_data_tls
=
proto_tls
->
ops
->
socket
(
socket
);
sock
->
user_data_tls
=
proto_tls
->
ops
->
socket
(
socket
);
if
(
sock
->
user_data_tls
==
RT_NULL
)
if
(
sock
->
user_data_tls
==
RT_NULL
)
{
{
socket_delete
(
socket
);
return
-
1
;
return
-
1
;
}
}
}
}
...
@@ -964,9 +993,8 @@ int sal_closesocket(int socket)
...
@@ -964,9 +993,8 @@ int sal_closesocket(int socket)
error
=
-
1
;
error
=
-
1
;
}
}
/* free socket */
/* delete socket */
rt_free
(
sock
);
socket_delete
(
socket
);
socket_table
.
sockets
[
socket
]
=
RT_NULL
;
return
error
;
return
error
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录