typedef enum {
MYOP_ERROR = -1,
MYOP_NONE = 0,
MYOP_QUIT,
MYOP_WAITCHILD,
} MyOperation_t;
MyOperation_t AnalyseEvent (struct epoll_event *event)
{
if (event->data.fd == sigFD) {
struct signalfd_siginfo info = {0};
read (sigFD, &info, sizeof(info));
switch (info.ssi_signo) {
case SIGINT:
case SIGTERM:
return MYOP_QUIT;
case SIGCHLD:
return MYOP_WAITCHILD;
default:
break;
}
}
else if (event->data.fd == cliFD) {
}
return MYOP_NONE;
}
void DispatchEvent (MyOperation_t mycmd)
{
switch (mycmd) {
case MYOP_QUIT:
done = true;
break;
case MYOP_WAITCHILD:
WaitChild ();
break;
default:
break;
}
return ;
}
void EpollLoop (void)
{
while (!done) {
struct epoll_event ev = {0};
int evnum = epoll_wait (epollFD, &ev, 1, -1);
for (int i=0; i<evnum; ++i) {
MyOperation_t mycmd = AnalyseEvent (&ev);
DispatchEvent (mycmd);
}
}
return ;
}