修复日志处理,优化磁盘io,优化退出流程
This commit is contained in:
@ -243,7 +243,6 @@ int server_run(int port,int fifo_fd,netm *self)
|
||||
{
|
||||
/*工作循环-----------------------------*/
|
||||
int nf = epoll_wait(epfd,events,10,-1);
|
||||
printf("%d\n",nf);
|
||||
if (nf == -1) {
|
||||
perror("epoll_wait");
|
||||
break;
|
||||
@ -259,21 +258,43 @@ int server_run(int port,int fifo_fd,netm *self)
|
||||
sprintf(iss_buf,"s/%d/e",nt_fd);
|
||||
self->iss_work(self,iss_buf);
|
||||
}
|
||||
if(events[i].data.fd == fifo_fd)
|
||||
{
|
||||
char command;
|
||||
while(read(fifo_fd,&command,1)==1)
|
||||
{
|
||||
switch(command){
|
||||
case 'q':
|
||||
//退出逻辑
|
||||
quit_server(self);
|
||||
return 1;
|
||||
break;
|
||||
case 'u':
|
||||
//插件更新逻辑
|
||||
break;
|
||||
if(events[i].data.fd == fifo_fd) {
|
||||
char buffer[256];
|
||||
ssize_t bytes_read;
|
||||
|
||||
// 一次性读取所有可用数据
|
||||
bytes_read = read(fifo_fd, buffer, sizeof(buffer));
|
||||
|
||||
if (bytes_read > 0) {
|
||||
printf("DEBUG: Read %zd bytes from pipe: ", bytes_read);
|
||||
for (int j = 0; j < bytes_read; j++) {
|
||||
printf("%c ", buffer[j]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// 处理每个命令(按接收顺序)
|
||||
for (int j = 0; j < bytes_read; j++) {
|
||||
printf("Processing command[%d]: %c\n", j, buffer[j]);
|
||||
|
||||
switch(buffer[j]) {
|
||||
case 'q':
|
||||
printf("Quit command found at position %d\n", j);
|
||||
quit_server(self);
|
||||
return 1; // 立即退出,不处理后续命令
|
||||
case 'u':
|
||||
printf("Update command\n");
|
||||
// 更新逻辑
|
||||
break;
|
||||
default:
|
||||
printf("Unknown command: %c (ASCII: %d)\n",
|
||||
buffer[j], buffer[j]);
|
||||
}
|
||||
}
|
||||
} else if (bytes_read == 0) {
|
||||
printf("Pipe closed by writer\n");
|
||||
close(fifo_fd);
|
||||
} else if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
perror("Error reading from pipe");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user