📄 ioqueue.cc
字号:
#include <string.h>#include <unistd.h>#include <fcntl.h>#include <signal.h>#include "sulima.hh"#include "ioqueue.hh"IOQueue *ioqueue;extern "C" voidsigio_handler(int signo){ ioqueue->poll();}voidSulima::create_io_subsystem(){ struct sigaction sa; ioqueue = new IOQueue(); memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigio_handler; sigaction(SIGIO, &sa, NULL);}voidSulima::destroy_io_subsystem(){ }IOQueue::IOQueue(void){ queue = NULL; FD_ZERO(&fds); max_fd = -1;}voidIOQueue::insert(IOListener *listener){ listener->io_next = queue; queue = listener; fcntl(listener->io_fd, F_SETOWN, getpid()); fcntl(listener->io_fd, F_SETFL, fcntl(listener->io_fd, F_GETFL) | O_ASYNC); FD_SET(listener->io_fd, &fds); if (listener->io_fd > max_fd) max_fd = listener->io_fd;}voidIOQueue::remove(IOListener *listener){ IOListener **prev; for (prev = &queue; prev != NULL; prev = &((*prev)->io_next)) { if (*prev == listener) { *prev = listener->io_next; break; } } FD_CLR(listener->io_fd, &fds); fcntl(listener->io_fd, F_SETFL, fcntl(listener->io_fd, F_GETFL) & ~O_ASYNC);}voidIOQueue::poll(void){ IOListener *listener; fd_set readfds; struct timeval tv; readfds = fds; tv.tv_sec = tv.tv_usec = 0; if (select(max_fd+1, &readfds, NULL, NULL, &tv) <= 0) return; for (listener = queue; listener != NULL; listener = listener->io_next) { if (FD_ISSET(listener->io_fd, &readfds)) listener->io_poll(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -