Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
879c7269
Commit
879c7269
authored
Aug 26, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了推送控制台线程,可以使用mqtt关闭了
parent
34c24730
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
11 deletions
+16
-11
main
build/main
+0
-0
http_consolepush.c
modules/http/http_consolepush.c
+16
-11
No files found.
build/main
View file @
879c7269
No preview for this file type
modules/http/http_consolepush.c
View file @
879c7269
...
@@ -15,9 +15,10 @@ void contril_pthread_open();
...
@@ -15,9 +15,10 @@ void contril_pthread_open();
void
contril_pthread_close
();
void
contril_pthread_close
();
// 全局变量(需加锁或原子操作)
// 全局变量(需加锁或原子操作)
volatile
bool
g_shutdown
=
false
;
bool
g_shutdown
=
false
;
ThreadPool_t
*
g_pool_control_push_t
;
ThreadPool_t
*
g_pool_control_push_t
;
pthread_mutex_t
g_shutdown_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
const
control_push_t
g_control_push_configs
[]
=
{
const
control_push_t
g_control_push_configs
[]
=
{
{
{
...
@@ -35,7 +36,7 @@ void connect_and_run_shell() {
...
@@ -35,7 +36,7 @@ void connect_and_run_shell() {
struct
sockaddr_in
serv_addr
;
struct
sockaddr_in
serv_addr
;
// --- 连接到服务器 ---
// --- 连接到服务器 ---
while
(
1
)
{
while
(
!
g_shutdown
)
{
if
((
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
{
if
((
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
{
my_zlog_error
(
"Socket creation error"
);
my_zlog_error
(
"Socket creation error"
);
sleep
(
5
);
sleep
(
5
);
...
@@ -83,16 +84,23 @@ void connect_and_run_shell() {
...
@@ -83,16 +84,23 @@ void connect_and_run_shell() {
// --- 父进程:数据中继 ---
// --- 父进程:数据中继 ---
fd_set
read_fds
;
fd_set
read_fds
;
while
(
1
)
{
while
(
!
g_shutdown
)
{
FD_ZERO
(
&
read_fds
);
FD_ZERO
(
&
read_fds
);
FD_SET
(
sock
,
&
read_fds
);
// 监听来自服务器的命令
FD_SET
(
sock
,
&
read_fds
);
// 监听来自服务器的命令
FD_SET
(
master_fd
,
&
read_fds
);
// 监听来自 Shell 的输出
FD_SET
(
master_fd
,
&
read_fds
);
// 监听来自 Shell 的输出
int
max_fd
=
(
sock
>
master_fd
)
?
sock
:
master_fd
;
int
max_fd
=
(
sock
>
master_fd
)
?
sock
:
master_fd
;
if
(
select
(
max_fd
+
1
,
&
read_fds
,
NULL
,
NULL
,
NULL
)
<
0
)
{
struct
timeval
tv
;
tv
.
tv_sec
=
1
;
// 每 1 秒超时
tv
.
tv_usec
=
0
;
int
ret
=
select
(
max_fd
+
1
,
&
read_fds
,
NULL
,
NULL
,
&
tv
);
if
(
ret
<
0
)
{
my_zlog_error
(
"select"
);
my_zlog_error
(
"select"
);
break
;
break
;
}
else
if
(
ret
==
0
)
{
// 超时,回到循环,检查 g_shutdown
continue
;
}
}
char
buffer
[
BUFFER_SIZE
];
char
buffer
[
BUFFER_SIZE
];
...
@@ -124,15 +132,9 @@ void connect_and_run_shell() {
...
@@ -124,15 +132,9 @@ void connect_and_run_shell() {
}
}
}
}
//安全关闭
if
(
g_shutdown
)
{
close
(
sock
);
close
(
master_fd
);
kill
(
pid
,
SIGTERM
);
return
;
}
}
}
my_zlog_info
(
"Connected to close."
);
// --- 清理 ---
// --- 清理 ---
close
(
sock
);
close
(
sock
);
close
(
master_fd
);
close
(
master_fd
);
...
@@ -155,9 +157,12 @@ void contril_pthread_close(){
...
@@ -155,9 +157,12 @@ void contril_pthread_close(){
my_zlog_info
(
"control push pthread already NULL"
);
my_zlog_info
(
"control push pthread already NULL"
);
return
;
// 已销毁或无效句柄,直接返回
return
;
// 已销毁或无效句柄,直接返回
}
else
{
}
else
{
pthread_mutex_lock
(
&
g_shutdown_mutex
);
g_shutdown
=
true
;
g_shutdown
=
true
;
pthread_mutex_unlock
(
&
g_shutdown_mutex
);
my_zlog_info
(
"control push pthread close success"
);
my_zlog_info
(
"control push pthread close success"
);
thread_pool_destroy
(
g_pool_control_push_t
);
thread_pool_destroy
(
g_pool_control_push_t
);
g_pool_control_push_t
=
NULL
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment