diff --git a/c/interpreter/interpreter.c b/c/interpreter/interpreter.c index 74e622d..010140f 100644 --- a/c/interpreter/interpreter.c +++ b/c/interpreter/interpreter.c @@ -145,11 +145,11 @@ int exce(const int command,ctx *all_ctx) return 1; case RUN: - printf("runing\n"); + printf("SYS:runing\n"); return 1; case QUIT: - printf("shuting down\n"); + printf("SYS:shuting down\n"); all_ctx->statue = -1; write(all_ctx->fifofd[1],"q",1); return 1; diff --git a/c/network/network.c b/c/network/network.c index 04e037d..6122323 100644 --- a/c/network/network.c +++ b/c/network/network.c @@ -206,21 +206,23 @@ int server_run(int port,int fifo_fd,netm *self) ev.data.fd = fifo_fd; epoll_ctl(epfd, EPOLL_CTL_ADD, fifo_fd, &ev); char iss_buf[256]; - int http_fd = init_network(port); + self->http_fd = init_network(port); - ev.data.fd = http_fd; - epoll_ctl(epfd, EPOLL_CTL_ADD, http_fd, &ev); + ev.data.fd = self->http_fd; + epoll_ctl(epfd, EPOLL_CTL_ADD, self->http_fd, &ev); struct epoll_event events; + self->epoll_fd = epfd; for(;;) { + /*工作循环-----------------------------*/ int nf = epoll_wait(epfd,&events,1,-1); if (nf == -1) { perror("epoll_wait"); break; } - if(events.data.fd ==http_fd) + if(events.data.fd ==self->http_fd) { - int nt_fd = accept4(http_fd,NULL,NULL,SOCK_NONBLOCK | SOCK_CLOEXEC); + int nt_fd = accept4(self->http_fd,NULL,NULL,SOCK_NONBLOCK | SOCK_CLOEXEC); if(nt_fd == -1) continue; sprintf(iss_buf,"s/%d/e",nt_fd); @@ -234,6 +236,7 @@ int server_run(int port,int fifo_fd,netm *self) switch(command){ case 'q': //退出逻辑 + quit_server(self); return 1; break; case 'u': @@ -243,6 +246,7 @@ int server_run(int port,int fifo_fd,netm *self) } } } + /*工作循环----------------------------*/ } } diff --git a/c/network/network.h b/c/network/network.h index 574f958..ac5c72f 100644 --- a/c/network/network.h +++ b/c/network/network.h @@ -31,6 +31,8 @@ typedef struct network_manager log_manager *logmanager; int last_alc; int port; + int epoll_fd; + int http_fd; }netm; typedef struct rebot_message diff --git a/c/tools/log/log.c b/c/tools/log/log.c index 4920981..4d92e31 100644 --- a/c/tools/log/log.c +++ b/c/tools/log/log.c @@ -98,9 +98,9 @@ void log_manager_stop(log_manager *self) pthread_mutex_lock(&self->mtx); self->stop = 1; /* 置退出标志 */ pthread_cond_broadcast(&self->cond); /* 唤醒所有等待线程 */ - printf("stopping loger\n"); + printf("SYS:stopping loger\n"); pthread_mutex_unlock(&self->mtx); - printf("done\n"); + printf("SYS:done\n"); } //定期清理函数 diff --git a/c/tools/quit/quit.c b/c/tools/quit/quit.c index 082e346..08b840a 100644 --- a/c/tools/quit/quit.c +++ b/c/tools/quit/quit.c @@ -1,9 +1,40 @@ +#define _GNU_SOURCE + #include #include #include +#include +#include +#include +#include #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; @@ -13,6 +44,7 @@ void quit_all(int status,void *self_p) 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); //释放网络资源 diff --git a/c/tools/quit/quit.h b/c/tools/quit/quit.h index 12e2dd0..18feff8 100644 --- a/c/tools/quit/quit.h +++ b/c/tools/quit/quit.h @@ -14,6 +14,7 @@ typedef struct all_resources void quit_all(int status,void *self_p); +int quit_server(netm *self); #endif \ No newline at end of file