From afe70e6d172aee0c54943c54820874e1c63227d6 Mon Sep 17 00:00:00 2001 From: jianf <2198972886@qq.com> Date: Sun, 28 Sep 2025 14:26:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=80=E5=87=BA=E4=BF=A1?= =?UTF-8?q?=E5=8F=B7=E4=BC=A0=E9=80=92=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- c/CMakeLists.txt | 3 ++- c/interpreter/interpreter.c | 1 + c/main.c | 9 +++++++++ c/network/network.c | 20 +++++++++++++++++--- c/network/network.h | 2 +- c/tem/ctl.c | 6 ++++++ c/tools/pkgmanager/update_pkg.c | 0 c/tools/pkgmanager/update_pkg.h | 0 c/tools/quit/quit.c | 9 ++++++++- c/tools/quit/quit.h | 5 ++++- 10 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 c/tools/pkgmanager/update_pkg.c create mode 100644 c/tools/pkgmanager/update_pkg.h diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index bdb8f86..2ebd08b 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -9,7 +9,8 @@ add_library(Swmem SHARED network/swap.c) add_library(Interpre SHARED interpreter/interpreter.c tools/pkgmanager/pkginstall.c) add_library(Log SHARED tools/log/log.c) add_library(Toml SHARED tools/toml/toml.c) +add_library(Quit SHARED tools/quit/quit.c) -target_link_libraries(Start_Onebot_back Network Swmem Interpre Log Toml) +target_link_libraries(Start_Onebot_back Network Swmem Interpre Log Toml Quit) include_directories(${PROJECT_SOURCE_DIR}) \ No newline at end of file diff --git a/c/interpreter/interpreter.c b/c/interpreter/interpreter.c index 434bf2b..74e622d 100644 --- a/c/interpreter/interpreter.c +++ b/c/interpreter/interpreter.c @@ -151,6 +151,7 @@ int exce(const int command,ctx *all_ctx) case QUIT: printf("shuting down\n"); all_ctx->statue = -1; + write(all_ctx->fifofd[1],"q",1); return 1; } diff --git a/c/main.c b/c/main.c index fe83c04..965c572 100644 --- a/c/main.c +++ b/c/main.c @@ -49,6 +49,15 @@ int main() //启动终端 pthread_join(network_id,NULL); //等待网络管理器进程结束 + logs *log = logsmanager->log; + while(log != NULL) + { + logs *buf = log; + if(log->next !=NULL) + log = log->next; + free(buf); + } + //释放日志内存 free(teml); free(networkmanager); diff --git a/c/network/network.c b/c/network/network.c index 19188ee..0b13a6d 100644 --- a/c/network/network.c +++ b/c/network/network.c @@ -5,6 +5,7 @@ #include "http_rel.h" #include "cJSON.h" #include "tools/log/log.h" +#include "tools/quit/quit.h" #include #include #include @@ -183,7 +184,7 @@ int shutdown_pool(netm *self) { for(int i = 0;ipool[i].fifo_fd[0]); + close(self->pool[i].fifo_fd[1]); } } @@ -194,8 +195,15 @@ int server_run(int port,int fifo_fd,netm *self) perror("epoll_create1"); exit(EXIT_FAILURE); } + struct epoll_event ev; + ev.events = EPOLLIN; + ev.data.fd = fifo_fd; + epoll_ctl(epfd, EPOLL_CTL_ADD, fifo_fd, &ev); char iss_buf[256]; int http_fd = init_network(port); + + ev.data.fd = http_fd; + epoll_ctl(epfd, EPOLL_CTL_ADD, http_fd, &ev); struct epoll_event events; for(;;) { @@ -206,7 +214,10 @@ int server_run(int port,int fifo_fd,netm *self) } if(events.data.fd ==http_fd) { - sprintf(iss_buf,"s/%d/e",accept4(http_fd,NULL,NULL,SOCK_NONBLOCK | SOCK_CLOEXEC)); + int nt_fd = accept4(http_fd,NULL,NULL,SOCK_NONBLOCK | SOCK_CLOEXEC); + if(nt_fd == -1) + continue; + sprintf(iss_buf,"s/%d/e",nt_fd); self->iss_work(self,iss_buf); } if(events.data.fd == fifo_fd) @@ -217,9 +228,12 @@ int server_run(int port,int fifo_fd,netm *self) switch(command){ case 'q': //退出逻辑 + server_quit(self); + return 1; break; case 'u': //插件更新逻辑 + break; } } @@ -231,7 +245,7 @@ void *run_network(void *self_d) { netm *self = (netm*)self_d; self->start_pool(self); - server_run(self->port,self->fifo_fd[1],self); + server_run(self->port,self->fifo_fd[0],self); self->shutdown_pool(self); } diff --git a/c/network/network.h b/c/network/network.h index 217f48e..24498c8 100644 --- a/c/network/network.h +++ b/c/network/network.h @@ -1,7 +1,7 @@ #ifndef NETWORK #define NETWORK -#define MAX_POOL 24 +#define MAX_POOL 10 #define MAX_MESSAGE_BUF 10240 #include #include diff --git a/c/tem/ctl.c b/c/tem/ctl.c index 9344f70..098f420 100644 --- a/c/tem/ctl.c +++ b/c/tem/ctl.c @@ -5,7 +5,11 @@ #include #include #include +#include +#include + #include "ctl.h" + #include "interpreter/interpreter.h" #include "tools/log/log.h" @@ -248,6 +252,8 @@ int teml(Ctl *self,int fifo[2]) const char fexp[256] = {'\0'}; memcpy(&input,&fexp,MAX_BUF); }while(command->statue == 0); + pthread_kill(self->logwathcher,SIGUSR1); + //关闭log定期清理程序 close(fifo[0]); close(fifo[1]); free_history(self); diff --git a/c/tools/pkgmanager/update_pkg.c b/c/tools/pkgmanager/update_pkg.c new file mode 100644 index 0000000..e69de29 diff --git a/c/tools/pkgmanager/update_pkg.h b/c/tools/pkgmanager/update_pkg.h new file mode 100644 index 0000000..e69de29 diff --git a/c/tools/quit/quit.c b/c/tools/quit/quit.c index 7defe9e..4abef47 100644 --- a/c/tools/quit/quit.c +++ b/c/tools/quit/quit.c @@ -1,7 +1,14 @@ #include #include +#include "quit.h" -void *quit_all(void *self_d) +void *quit_all(void *self_p) { +} + + +int server_quit(netm *self) +{ + } \ No newline at end of file diff --git a/c/tools/quit/quit.h b/c/tools/quit/quit.h index 7ce7da3..4618014 100644 --- a/c/tools/quit/quit.h +++ b/c/tools/quit/quit.h @@ -1,6 +1,9 @@ #ifndef QUIT #define QUIT -void *quitall(int status,void *arg); +#include "network/network.h" +void *quitall(void *self_p); + +int server_quit(netm *self); #endif \ No newline at end of file