// File: /workspace/github_cpp_makefile_star2_O2/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)
xorl %eax, %eax
testb $0x1, %al
jne 0x79ad
movl 0x24(%rbx), %edi
movq %r12, %rsi
movl $0x2710, %edx           # imm = 0x2710
pushq $-0x1
popq %rcx
callq 0x31b0
movl %eax, %r13d
testl %eax, %eax
jns 0x7882
callq 0x3050
cmpl $0x4, (%rax)
jne 0x79a7
testl %r13d, %r13d
movl $0x0, %eax
cmovlel %eax, %r13d
imulq $0xc, %r13, %r13
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0x7955
movslq 0xb0(%rbx,%rbp), %rdx
cmpl 0x1d56c(%rbx), %edx
jne 0x78b7
movq %rbx, %rdi
callq 0x744c
jmp 0x78df
movl 0xac(%rbx,%rbp), %eax
testw $0x2018, %ax            # imm = 0x2018
je 0x78e5
movq 0x1d580(%rbx), %rax
movq %rdx, %rcx
shlq $0x5, %rcx
movq 0x18(%rax,%rcx), %rsi
movq %rbx, %rdi
callq 0x73da
addq $0xc, %rbp
jmp 0x7894
testb $0x1, %al
je 0x7935
cmpl 0x1c(%rbx), %edx
jne 0x7935
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x758a
testb %al, %al
jne 0x78df
cmpl $0x0, 0x14(%rbx)
jne 0x78df
callq 0x53e8
movq %rax, %rdi
pushq $0x3
popq %rsi
leaq 0x988(%rip), %rdx       # 0x82a0
leaq 0xc6a(%rip), %rcx       # 0x8589
xorl %eax, %eax
callq 0x5e86
callq 0x53e8
movq %rax, %rdi
callq 0x6246
jmp 0x78df
testb $0x1, %al
jne 0x7949
testb $0x4, %al
je 0x78df
movq %rbx, %rdi
movl %edx, %esi
callq 0x7710
jmp 0x78df
movq %rbx, %rdi
movl %edx, %esi
callq 0x75f4
jmp 0x78df
cmpb $0x0, 0xe(%rsp)
je 0x799e
movq 0x10(%rsp), %rdi
callq 0x3fc4
cmpl $0x0, 0x14(%rbx)
jne 0x7999
callq 0x53e8
movq %rax, %rdi
pushq $0x1
popq %rsi
leaq 0x922(%rip), %rdx       # 0x82a0
leaq 0xc1b(%rip), %rcx       # 0x85a0
xorl %eax, %eax
callq 0x5e86
callq 0x53e8
movq %rax, %rdi
callq 0x6246
movb $0x0, 0xe(%rsp)
movb 0xf(%rsp), %al
jmp 0x7852
cmpl $0x0, 0x14(%rbx)
je 0x79bc
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x53e8
leaq 0x8d8(%rip), %rdx       # 0x82a0
leaq 0xbac(%rip), %rcx       # 0x857b
pushq $0x3
popq %rsi
movq %rax, %rdi
xorl %eax, %eax
callq 0x5e86
callq 0x53e8
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6246
nop