优化退出信号传递流程

This commit is contained in:
2025-09-28 14:26:09 +08:00
parent a0ccc964bc
commit afe70e6d17
10 changed files with 48 additions and 7 deletions

View File

@ -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);
}

View File

@ -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>