77 lines
1.9 KiB
C
77 lines
1.9 KiB
C
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include<unistd.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <sys/epoll.h>
|
|
#include "quit.h"
|
|
#include "tem/ctl.h"
|
|
|
|
int quit_server(netm *self)
|
|
{
|
|
if(self ==NULL)
|
|
return -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->fifo_fd[0],NULL);
|
|
self->epoll_fd = -1;
|
|
}
|
|
//关闭epoll监听
|
|
if(self->http_fd != -1)
|
|
{
|
|
close(self->http_fd);
|
|
self->http_fd =-1;
|
|
}
|
|
//关闭socket监听
|
|
if(self->fifo_fd[0] != -1)
|
|
{
|
|
close(self->fifo_fd[0]);
|
|
self->fifo_fd[0] = -1;
|
|
}
|
|
//关闭管道监听
|
|
}
|
|
|
|
void quit_all(int status,void *self_p)
|
|
{
|
|
alres *resouce =(alres*)self_p;
|
|
//转换参数
|
|
|
|
resouce->network->shutdown_pool(resouce->network);
|
|
logs *netlog = (logs*)malloc(sizeof(logs));
|
|
netlog->next = NULL;
|
|
memcpy(netlog->log,"shuting down networkserver",27);
|
|
quit_server(resouce->network);
|
|
resouce->loger->in_log(netlog,resouce->loger);
|
|
free(resouce->network);
|
|
//释放网络资源
|
|
if(resouce->tem->command !=NULL){
|
|
free_history(resouce->tem);
|
|
if(resouce->tem->command->arg != NULL)
|
|
{
|
|
args* arg = resouce->tem->command->arg;
|
|
if(arg->next !=NULL)
|
|
{
|
|
while(arg->next != NULL){
|
|
args* tobefree = arg;
|
|
arg = arg->next;
|
|
free(tobefree);
|
|
}
|
|
free(arg);
|
|
}
|
|
}
|
|
free(resouce->tem->command);
|
|
}
|
|
//释放终端资源
|
|
pthread_mutex_destroy(&resouce->loger->mtx);
|
|
resouce->loger->cleanup(resouce->loger);
|
|
sem_destroy(&resouce->loger->log_sem);
|
|
//销毁信号量
|
|
|
|
free(resouce->loger);
|
|
//清理日志
|
|
}
|