修复端口绑定取消异常

This commit is contained in:
2026-01-29 14:03:43 +08:00
parent 3673b10942
commit 674f611d07
4 changed files with 30 additions and 8 deletions

View File

@ -58,13 +58,15 @@ int main()
teml->run(teml,fifo); teml->run(teml,fifo);
//启动终端 //启动终端
log_manager_stop(logsmanager);
pthread_join(logsmanager->pid,NULL);
logsmanager->pid = -1;
//等待网络管理器进程结束 //等待网络管理器进程结束
pthread_join(networkmanager->pid,NULL); pthread_join(networkmanager->pid,NULL);
networkmanager->pid = -1;
close(fifo[1]); close(fifo[1]);
log_manager_stop(logsmanager);
pthread_join(logsmanager->pid,NULL);
logsmanager->pid = -1;
return 1; return 1;
} }

View File

@ -217,6 +217,7 @@ int shutdown_pool(netm *self)
self->pool[i].status = -1; self->pool[i].status = -1;
close(self->pool[i].fifo_fd[1]); close(self->pool[i].fifo_fd[1]);
} }
self->statue = ALL_STOP;
return 1; return 1;
} }
@ -239,6 +240,7 @@ int server_run(int port,int fifo_fd,netm *self)
epoll_ctl(epfd, EPOLL_CTL_ADD, self->http_fd, &ev); epoll_ctl(epfd, EPOLL_CTL_ADD, self->http_fd, &ev);
struct epoll_event events[10]; struct epoll_event events[10];
self->epoll_fd = epfd; self->epoll_fd = epfd;
self->statue = SERVER_ON;
for(;;) for(;;)
{ {
/*工作循环-----------------------------*/ /*工作循环-----------------------------*/
@ -306,6 +308,7 @@ void *run_network(void *self_d)
{ {
netm *self = (netm*)self_d; netm *self = (netm*)self_d;
self->start_pool(self); self->start_pool(self);
self->statue = POOL_ON;
server_run(self->port,self->fifo_fd[0],self); server_run(self->port,self->fifo_fd[0],self);
self->shutdown_pool(self); self->shutdown_pool(self);
} }
@ -324,5 +327,6 @@ int init_networkmanager(netm *self,int *fifo,log_manager *logmanager,int port)
//初始化参数 //初始化参数
self->logmanager = logmanager; self->logmanager = logmanager;
self->err_indictor = (indiector*)malloc(sizeof(indiector)); self->err_indictor = (indiector*)malloc(sizeof(indiector));
self->statue = ALL_STOP;
return 0; return 0;
} }

View File

@ -1,6 +1,9 @@
#ifndef NETWORK #ifndef NETWORK
#define NETWORK #define NETWORK
#define POOL_ON 1
#define SERVER_ON 2
#define ALL_STOP 0
#include <pthread.h> #include <pthread.h>
#include "tools/log/log.h" #include "tools/log/log.h"
@ -36,6 +39,7 @@ typedef struct network_manager//网络管理器
int port; int port;
int epoll_fd; int epoll_fd;
int http_fd; int http_fd;
int statue;
}netm; }netm;
typedef struct rebot_message typedef struct rebot_message

View File

@ -15,28 +15,32 @@ int quit_server(netm *self)
{ {
if(self ==NULL) if(self ==NULL)
return -1; return -1;
//关闭epoll监听
if(self->epoll_fd != -1) if(self->epoll_fd != -1)
{ {
epoll_ctl(self->epoll_fd,EPOLL_CTL_DEL,self->http_fd,NULL); epoll_ctl(self->epoll_fd,EPOLL_CTL_DEL,self->http_fd,NULL);
epoll_ctl(self->epoll_fd,EPOLL_CTL_DEL,self->fifo_fd[0],NULL); epoll_ctl(self->epoll_fd,EPOLL_CTL_DEL,self->fifo_fd[0],NULL);
self->epoll_fd = -1; self->epoll_fd = -1;
} }
//关闭epoll监听 //关闭socket监听
if(self->http_fd != -1) if(self->http_fd != -1)
{ {
shutdown(self->http_fd, SHUT_RDWR);
if(close(self->http_fd)==-1) if(close(self->http_fd)==-1)
return -1; perror("http");
self->http_fd =-1; self->http_fd =-1;
} }
//关闭socket监听 //关闭管道监听
if(self->fifo_fd[1] != -1) if(self->fifo_fd[1] != -1)
{ {
if(close(self->fifo_fd[1])==-1) if(close(self->fifo_fd[1])==-1)
return -1; return -1;
self->fifo_fd[1] = -1; self->fifo_fd[1] = -1;
} }
//关闭管道监听
free(self->err_indictor); free(self->err_indictor);
self->statue = POOL_ON;
return 0; return 0;
} }
@ -49,7 +53,15 @@ void quit_all(int status,void *self_p)
logs *netlog = (logs*)malloc(sizeof(logs)); logs *netlog = (logs*)malloc(sizeof(logs));
netlog->next = NULL; netlog->next = NULL;
memcpy(netlog->log,"shuting down networkserver",27); memcpy(netlog->log,"shuting down networkserver",27);
quit_server(resouce->network);
if(resouce->network->statue == SERVER_ON)
{
quit_server(resouce->network);
}
if(resouce->network->statue == POOL_ON)
{
resouce->network->shutdown_pool(resouce->network);
}
resouce->loger->in_log(netlog,resouce->loger); resouce->loger->in_log(netlog,resouce->loger);
free(resouce->network); free(resouce->network);
//释放网络资源 //释放网络资源