优化退出信号传递流程
This commit is contained in:
@ -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})
|
@ -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;
|
||||
}
|
||||
|
||||
|
9
c/main.c
9
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);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "http_rel.h"
|
||||
#include "cJSON.h"
|
||||
#include "tools/log/log.h"
|
||||
#include "tools/quit/quit.h"
|
||||
#include <semaphore.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
@ -183,7 +184,7 @@ int shutdown_pool(netm *self)
|
||||
{
|
||||
for(int i = 0;i<MAX_POOL;i++)
|
||||
{
|
||||
close(self->pool[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);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef NETWORK
|
||||
#define NETWORK
|
||||
|
||||
#define MAX_POOL 24
|
||||
#define MAX_POOL 10
|
||||
#define MAX_MESSAGE_BUF 10240
|
||||
#include <pthread.h>
|
||||
#include<tools/log/log.h>
|
||||
|
@ -5,7 +5,11 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
#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);
|
||||
|
0
c/tools/pkgmanager/update_pkg.c
Normal file
0
c/tools/pkgmanager/update_pkg.c
Normal file
0
c/tools/pkgmanager/update_pkg.h
Normal file
0
c/tools/pkgmanager/update_pkg.h
Normal file
@ -1,7 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "quit.h"
|
||||
|
||||
void *quit_all(void *self_d)
|
||||
void *quit_all(void *self_p)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int server_quit(netm *self)
|
||||
{
|
||||
|
||||
}
|
@ -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
|
Reference in New Issue
Block a user