// File: /workspace/github_cpp_makefile_star2_O1/JianjiaoSQ[P]MyPoorWebServer/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);
        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))
            {
                //服务器端关闭连接，移除对应的定时器
                tw_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)
                    LOG_ERROR("%s", "dealclientdata failure");
            }
            //处理客户连接上接收到的数据
            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 0x1d588(%rdi), %rax
movq %rax, 0x10(%rsp)
movl 0x24(%rbx), %edi
movq %r12, %rsi
movl $0x2710, %edx           # imm = 0x2710
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x3190
movl %eax, %r13d
testl %eax, %eax
jns 0x80ca
callq 0x3050
cmpl $0x4, (%rax)
jne 0x8205
testl %r13d, %r13d
jle 0x81a0
movl %r13d, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %r13
xorl %ebp, %ebp
movslq 0xb0(%rbx,%rbp), %rdx
cmpl 0x1d56c(%rbx), %edx
jne 0x80fa
movq %rbx, %rdi
callq 0x7c7a
jmp 0x8123
movl 0xac(%rbx,%rbp), %eax
testl $0x2018, %eax           # imm = 0x2018
je 0x812e
movq 0x1d580(%rbx), %rax
movq %rdx, %rcx
shlq $0x5, %rcx
movq 0x18(%rax,%rcx), %rsi
movq %rbx, %rdi
callq 0x7c02
addq $0xc, %rbp
cmpq %rbp, %r13
jne 0x80e0
jmp 0x81a0
testb $0x1, %al
je 0x8180
cmpl 0x1c(%rbx), %edx
jne 0x8180
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7dc2
testb %al, %al
jne 0x8123
cmpl $0x0, 0x14(%rbx)
jne 0x8123
callq 0x594a
movq %rax, %rdi
movl $0x3, %esi
leaq 0x1165(%rip), %rdx      # 0x92c8
leaq 0x1426(%rip), %rcx      # 0x9590
xorl %eax, %eax
callq 0x64a0
callq 0x594a
movq %rax, %rdi
callq 0x68c2
jmp 0x8123
testb $0x1, %al
jne 0x8194
testb $0x4, %al
je 0x8123
movq %rbx, %rdi
movl %edx, %esi
callq 0x7f52
jmp 0x8123
movq %rbx, %rdi
movl %edx, %esi
callq 0x7e2a
jmp 0x8123
cmpb $0x0, 0xe(%rsp)
je 0x81eb
movq 0x10(%rsp), %rdi
callq 0x41e4
cmpl $0x0, 0x14(%rbx)
jne 0x81e6
callq 0x594a
movq %rax, %rdi
movl $0x1, %esi
leaq 0x10fd(%rip), %rdx      # 0x92c8
leaq 0x13d5(%rip), %rcx      # 0x95a7
xorl %eax, %eax
callq 0x64a0
callq 0x594a
movq %rax, %rdi
callq 0x68c2
movb $0x0, 0xe(%rsp)
cmpb $0x1, 0xf(%rsp)
jne 0x80a0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x14(%rbx)
jne 0x81f6
callq 0x594a
leaq 0x10b1(%rip), %rdx      # 0x92c8
leaq 0x1364(%rip), %rcx      # 0x9582
movq %rax, %rdi
movl $0x3, %esi
xorl %eax, %eax
callq 0x64a0
callq 0x594a
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x68c2