优化退出流程,统一注册到on_exit(
This commit is contained in:
@ -1,14 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "quit.h"
|
||||
#include "tem/ctl.h"
|
||||
|
||||
void *quit_all(void *self_p)
|
||||
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);
|
||||
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);
|
||||
//清理日志
|
||||
}
|
||||
|
||||
|
||||
int server_quit(netm *self)
|
||||
{
|
||||
|
||||
}
|
@ -1,9 +1,19 @@
|
||||
#ifndef QUIT
|
||||
#define QUIT
|
||||
#ifndef QUIT_LIB
|
||||
#define QUIT_LIB
|
||||
|
||||
#include "network/network.h"
|
||||
void *quitall(void *self_p);
|
||||
#include "tem/ctl.h"
|
||||
#include "tools/log/log.h"
|
||||
typedef struct all_resources
|
||||
{
|
||||
Ctl *tem;
|
||||
netm *network;
|
||||
log_manager *loger;
|
||||
|
||||
}alres;
|
||||
|
||||
|
||||
void quit_all(int status,void *self_p);
|
||||
|
||||
int server_quit(netm *self);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user