// File: /workspace/github_cpp_makefile_star2_O1/lszp[P]SmallWebServer/webserver.cpp
// Function: WebServer::eventLoop()
void WebServer::eventLoop()
{
    bool timeout = false;
    bool stop_server = false;

    while (!stop_server)
    {
        int number = epoll_wait(m_epollfd, events, MAX_EVENT_NUMBER, -1);  // 轮询I/O事件的发生, event 用于回传代处理事件的数组，-1 阻塞，等待I/O事件发生的超时值。
        if (number < 0 && errno != EINTR)
        {
            LOG_ERROR("%s", "epoll failure");
            break;
        }

        for (int i = 0; i < number; i++)
        {
            int sockfd = events[i].data.fd;

            //处理新到的客户连接
            if (sockfd == m_listenfd)
            {
                bool flag = dealclinetdata();
                if (false == flag)
                    continue;
            }
            else if (events[i].events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR))
            {
                //服务器端关闭连接，移除对应的定时器
                util_timer *timer = users_timer[sockfd].timer;
                deal_timer(timer, sockfd);
            }
            //处理信号
            else if ((sockfd == m_pipefd[0]) && (events[i].events & EPOLLIN))
            {
                bool flag = dealwithsignal(timeout, stop_server);
                if (false == flag)
                    continue;
            }
            //处理客户连接上接收到的数据
            else if (events[i].events & EPOLLIN)
            {
                dealwithread(sockfd);
            }
            else if (events[i].events & EPOLLOUT)
            {
                dealwithwrite(sockfd);
            }
        }
        if (timeout)
        {
            utils.timer_handler();

            LOG_INFO("%s", "timer tick");

            timeout = false;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
xorl %eax, %eax
leaq 0xe(%rsp), %r14
movb %al, (%r14)
leaq 0xf(%rsp), %r15
movb %al, (%r15)
leaq 0xac(%rdi), %r12
leaq 0x1d590(%rdi), %rax
movq %rax, 0x10(%rsp)
movl 0x24(%rbx), %edi
movq %r12, %rsi
movl $0x2710, %edx           # imm = 0x2710
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x31c0
movl %eax, %ebp
testl %eax, %eax
jns 0x8aa5
callq 0x3060
cmpl $0x4, (%rax)
jne 0x8ba9
testl %ebp, %ebp
jle 0x8b44
movl %ebp, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rbp
xorl %r13d, %r13d
movslq 0xb0(%rbx,%r13), %rdx
cmpl 0x1d56c(%rbx), %edx
jne 0x8ad4
movq %rbx, %rdi
callq 0x8656
jmp 0x8b37
movl 0xac(%rbx,%r13), %eax
testl $0x2018, %eax           # imm = 0x2018
je 0x8b00
movq 0x1d588(%rbx), %rax
movq %rdx, %rcx
shlq $0x5, %rcx
movq 0x18(%rax,%rcx), %rsi
movq %rbx, %rdi
callq 0x85de
jmp 0x8b37
testb $0x1, %al
je 0x8b19
cmpl 0x1c(%rbx), %edx
jne 0x8b19
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x879e
jmp 0x8b37
testb $0x1, %al
jne 0x8b2d
testb $0x4, %al
je 0x8b37
movq %rbx, %rdi
movl %edx, %esi
callq 0x892e
jmp 0x8b37
movq %rbx, %rdi
movl %edx, %esi
callq 0x8806
addq $0xc, %r13
cmpq %r13, %rbp
jne 0x8aba
cmpb $0x0, 0xe(%rsp)
je 0x8b8f
movq 0x10(%rsp), %rdi
callq 0x42bc
cmpl $0x0, 0x14(%rbx)
jne 0x8b8a
callq 0x629e
movq %rax, %rdi
movl $0x1, %esi
leaq 0x1772(%rip), %rdx      # 0xa2e1
leaq 0x1a8a(%rip), %rcx      # 0xa600
xorl %eax, %eax
callq 0x6df4
callq 0x629e
movq %rax, %rdi
callq 0x7216
movb $0x0, 0xe(%rsp)
cmpb $0x1, 0xf(%rsp)
jne 0x8a7c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x14(%rbx)
jne 0x8b9a
callq 0x629e
leaq 0x1726(%rip), %rdx      # 0xa2e1
leaq 0x1a30(%rip), %rcx      # 0xa5f2
movq %rax, %rdi
movl $0x3, %esi
xorl %eax, %eax
callq 0x6df4
callq 0x629e
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7216