tcp:add net_lock to protect tcp resource

add net_lock in the tcp_callback_cleanup & Set the devif_callback_s of
tcp_callback_s to a two-dimensional pointer.

Signed-off-by: wangchen <wangchen41@xiaomi.com>
This commit is contained in:
wangchen
2024-09-03 15:39:51 +08:00
committed by Xiang Xiao
parent 02e7ed7cc4
commit 6196550f8f
6 changed files with 8 additions and 6 deletions
+1 -1
View File
@@ -442,7 +442,7 @@ struct tcp_backlog_s
struct tcp_callback_s
{
FAR struct tcp_conn_s *tc_conn;
FAR struct devif_callback_s *tc_cb;
FAR struct devif_callback_s **tc_cb;
FAR sem_t *tc_sem;
};
+3 -1
View File
@@ -437,8 +437,10 @@ void tcp_callback_cleanup(FAR void *arg)
{
FAR struct tcp_callback_s *cb = (FAR struct tcp_callback_s *)arg;
net_lock();
nerr("ERROR: pthread is being canceled, need to cleanup cb\n");
tcp_callback_free(cb->tc_conn, cb->tc_cb);
tcp_callback_free(cb->tc_conn, *(cb->tc_cb));
nxsem_destroy(cb->tc_sem);
net_unlock();
}
#endif /* NET_TCP_HAVE_STACK */
+1 -1
View File
@@ -375,7 +375,7 @@ int psock_tcp_connect(FAR struct socket *psock,
*/
info.tc_conn = conn;
info.tc_cb = state.tc_cb;
info.tc_cb = &state.tc_cb;
info.tc_sem = &state.tc_sem;
tls_cleanup_push(tls_get_info(), tcp_callback_cleanup, &info);
+1 -1
View File
@@ -803,7 +803,7 @@ static ssize_t tcp_recvfrom_one(FAR struct tcp_conn_s *conn, FAR void *buf,
*/
info.tc_conn = conn;
info.tc_cb = state.ir_cb;
info.tc_cb = &state.ir_cb;
info.tc_sem = &state.ir_sem;
tls_cleanup_push(tls_get_info(), tcp_callback_cleanup, &info);
+1 -1
View File
@@ -1467,7 +1467,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
*/
info.tc_conn = conn;
info.tc_cb = conn->sndcb;
info.tc_cb = &conn->sndcb;
info.tc_sem = &conn->snd_sem;
tls_cleanup_push(tls_get_info(), tcp_callback_cleanup, &info);
+1 -1
View File
@@ -611,7 +611,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
*/
info.tc_conn = conn;
info.tc_cb = state.snd_cb;
info.tc_cb = &state.snd_cb;
info.tc_sem = &state.snd_sem;
tls_cleanup_push(tls_get_info(), tcp_callback_cleanup, &info);