// File: /workspace/github_cpp_makefile_star2_O1/JianjiaoSQ[P]MyPoorWebServer/webserver.cpp
// Function: WebServer::eventListen()
void WebServer::eventListen() {
    //网络编程基础步骤
    m_listenfd = socket(PF_INET, SOCK_STREAM, 0);
    assert(m_listenfd >= 0);

    //优雅关闭连接
    if (0 == m_OPT_LINGER) {
        struct linger tmp = {0, 1};
        setsockopt(m_listenfd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
    }
    else if (1 == m_OPT_LINGER) {
        struct linger tmp = {1, 1};
        setsockopt(m_listenfd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
    }

    int ret = 0;
    struct sockaddr_in address;
    bzero(&address, sizeof(address));
    address.sin_family = AF_INET;
    address.sin_addr.s_addr = htonl(INADDR_ANY);
    address.sin_port = htons(m_port);

    int flag = 1;
    // 设置为可重复绑定
    setsockopt(m_listenfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
    // 绑定
    ret = bind(m_listenfd, (struct sockaddr *)&address, sizeof(address));
    assert(ret >= 0);
    ret = listen(m_listenfd, 5); // 5 等待连接队列的最大长度
    assert(ret >= 0);

    // 定时器
    utils.init(TIMESLOT); 

    //epoll创建内核事件表
    epoll_event events[MAX_EVENT_NUMBER];
    m_epollfd = epoll_create(5);
    assert(m_epollfd != -1);

    utils.addfd(m_epollfd, m_listenfd, false, m_LISTENTrigmode);
    http_conn::m_epollfd = m_epollfd;

    // 创建管道套接字
    ret = socketpair(PF_UNIX, SOCK_STREAM, 0, m_pipefd);
    assert(ret != -1);
    utils.setnonblocking(m_pipefd[1]); // 写端非阻塞    
    //send是将信息发送给套接字缓冲区，如果缓冲区满了，则会阻塞，
    //这时候会进一步增加信号处理函数的执行时间，为此，将其修改为非阻塞。
    utils.addfd(m_epollfd, m_pipefd[0], false, 0); 

    // 传递给主循环的信号值
    utils.addsig(SIGPIPE, SIG_IGN);
    utils.addsig(SIGALRM, utils.sig_handler, false);
    utils.addsig(SIGTERM, utils.sig_handler, false);

    //每隔TIMESLOT时间触发SIGALRM信号
    alarm(TIMESLOT);

    //工具类,信号和描述符基础操作
    Utils::u_pipefd = m_pipefd;
    Utils::u_epollfd = m_epollfd;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x30b0
movl %eax, 0x1d56c(%rbx)
testl %eax, %eax
js 0x7905
movl 0x1d570(%rbx), %ecx
cmpl $0x1, %ecx
je 0x775e
testl %ecx, %ecx
jne 0x778a
movabsq $0x100000000, %rdx      # imm = 0x100000000
jmp 0x776b
movabsq $0x100000000, %rdx      # imm = 0x100000000
incq %rdx
leaq 0x10(%rsp), %rcx
movq %rdx, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0xd, %edx
movl $0x8, %r8d
callq 0x3610
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
movw $0x2, (%r14)
movl $0x0, 0x4(%r14)
movzwl (%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r14)
leaq 0xc(%rsp), %rcx
movl $0x1, (%rcx)
movl 0x1d56c(%rbx), %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x3610
movl 0x1d56c(%rbx), %edi
movq %r14, %rsi
movl $0x10, %edx
callq 0x3080
testl %eax, %eax
js 0x7924
movl 0x1d56c(%rbx), %edi
movl $0x5, %esi
callq 0x3410
testl %eax, %eax
js 0x7943
leaq 0x1d588(%rbx), %r14
movq %r14, %rdi
movl $0x4, %esi
callq 0x408a
movl $0x5, %edi
callq 0x3660
movl %eax, 0x24(%rbx)
cmpl $-0x1, %eax
je 0x7962
movl 0x1d56c(%rbx), %edx
movl 0x1d578(%rbx), %r8d
movq %r14, %rdi
movl %eax, %esi
xorl %ecx, %ecx
callq 0x40c6
movl 0x24(%rbx), %eax
leaq 0x5b6a(%rip), %rcx      # 0xd3c0
movl %eax, (%rcx)
leaq 0x1c(%rbx), %r15
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0x3330
cmpl $-0x1, %eax
je 0x7981
movl 0x20(%rbx), %esi
movq %r14, %rdi
callq 0x4092
movl 0x1c(%rbx), %edx
movl 0x24(%rbx), %esi
movq %r14, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x40c6
movl $0x1, %edx
movq %r14, %rdi
movl $0xd, %esi
movl $0x1, %ecx
callq 0x4166
leaq -0x378d(%rip), %r12     # 0x4128
movq %r14, %rdi
movl $0xe, %esi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x4166
movq %r14, %rdi
movl $0xf, %esi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x4166
movl $0x4, %edi
callq 0x3670
leaq 0x5aee(%rip), %rax      # 0xd3d8
movq %r15, (%rax)
movl 0x24(%rbx), %eax
leaq 0x5ae9(%rip), %rcx      # 0xd3e0
movl %eax, (%rcx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x1b93(%rip), %rdi      # 0x949f
leaq 0x1b9c(%rip), %rsi      # 0x94af
leaq 0x1ba3(%rip), %rcx      # 0x94bd
movl $0x65, %edx
callq 0x3290
leaq 0x1bb0(%rip), %rdi      # 0x94db
leaq 0x1b7d(%rip), %rsi      # 0x94af
leaq 0x1b84(%rip), %rcx      # 0x94bd
movl $0x7d, %edx
callq 0x3290
leaq 0x1b91(%rip), %rdi      # 0x94db
leaq 0x1b5e(%rip), %rsi      # 0x94af
leaq 0x1b65(%rip), %rcx      # 0x94bd
movl $0x7f, %edx
callq 0x3290
leaq 0x1b7b(%rip), %rdi      # 0x94e4
leaq 0x1b3f(%rip), %rsi      # 0x94af
leaq 0x1b46(%rip), %rcx      # 0x94bd
movl $0x87, %edx
callq 0x3290
leaq 0x1b6c(%rip), %rdi      # 0x94f4
leaq 0x1b20(%rip), %rsi      # 0x94af
leaq 0x1b27(%rip), %rcx      # 0x94bd
movl $0x8e, %edx
callq 0x3290