// File: guoxuanhan[P]NetServer/main.cpp
// Function: main
int main(int argc, char *argv[])
{
    signal(SIGUSR1, sighandler1);
    signal(SIGUSR2, sighandler2);
    signal(SIGINT, sighandler2);
    signal(SIGPIPE, SIG_IGN);  //SIG_IGN,系统函数，忽略信号的处理程序,客户端发送RST包后，服务器还调用write会触发

    int port = 80;
    int iothreadnum = 4;
    int workerthreadnum = 4;
    if(argc == 4)
    {
        port = atoi(argv[1]);
        iothreadnum = atoi(argv[2]);
        workerthreadnum = atoi(argv[3]);
    }

    EventLoop loop;
    lp = &loop;
    HttpServer httpserver(&loop, port, iothreadnum, workerthreadnum);
    httpserver.Start();

    try
    {
        loop.loop();
    }
    catch (std::bad_alloc& ba)
    {
        std::cerr << "bad_alloc caught in ThreadPool::ThreadFunc task: " << ba.what() << '\n';
    }
    //loop.loop();

    // EventLoop loop;
    // lp = &loop;
    // EchoServer echoserver(&loop, port, iothreadnum);
    // echoserver.Start();
    // loop.loop();
    // return 0;
}

// Assembly:
subq $0x4f8, %rsp            # imm = 0x4F8
movl $0x0, 0x4f4(%rsp)
movl %edi, 0x4f0(%rsp)
movq %rsi, 0x4e8(%rsp)
movl $0xa, %edi
leaq 0x223(%rip), %rsi       # 0x181c0
callq 0x5450
movl $0xc, %edi
leaq 0x222(%rip), %rsi       # 0x181d0
callq 0x5450
movl $0x2, %edi
leaq 0x211(%rip), %rsi       # 0x181d0
callq 0x5450
movl $0xd, %edi
movl $0x1, %esi
callq 0x5450
movl $0x50, 0x4e4(%rsp)
movl $0x4, 0x4e0(%rsp)
movl $0x4, 0x4dc(%rsp)
cmpl $0x4, 0x4f0(%rsp)
jne 0x18046
movq 0x4e8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x5580
movl %eax, 0x4e4(%rsp)
movq 0x4e8(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x5580
movl %eax, 0x4e0(%rsp)
movq 0x4e8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x5580
movl %eax, 0x4dc(%rsp)
leaq 0x350(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x8100
movq 0x18(%rsp), %rsi
movq %rsi, 0x2336c(%rip)     # 0x3b3d0
movl 0x4e4(%rsp), %edx
movl 0x4e0(%rsp), %ecx
movl 0x4dc(%rsp), %r8d
leaq 0x38(%rsp), %rdi
callq 0xbf80
jmp 0x18086
leaq 0x38(%rsp), %rdi
callq 0xd020
jmp 0x18092
leaq 0x350(%rsp), %rdi
callq 0x8560
jmp 0x180a1
jmp 0x18150
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
jmp 0x18197
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
jmp 0x1818d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1818d
movq 0x30(%rsp), %rdi
callq 0x5180
movq %rax, 0x20(%rsp)
movq 0x22edf(%rip), %rdi     # 0x3afe0
leaq 0x10db1(%rip), %rsi     # 0x28eb9
callq 0x53a0
movq %rax, 0x10(%rsp)
jmp 0x18114
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x53a0
movq %rax, 0x8(%rsp)
jmp 0x18136
movq 0x8(%rsp), %rdi
movl $0xa, %esi
callq 0x5430
jmp 0x18147
callq 0x55e0
jmp 0x1814e
jmp 0x18150
leaq 0x38(%rsp), %rdi
callq 0xcee0
leaq 0x350(%rsp), %rdi
callq 0x84e0
movl 0x4f4(%rsp), %eax
addq $0x4f8, %rsp            # imm = 0x4F8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
callq 0x55e0
jmp 0x1818b
jmp 0x1818d
leaq 0x38(%rsp), %rdi
callq 0xcee0
leaq 0x350(%rsp), %rdi
callq 0x84e0
movq 0x30(%rsp), %rdi
callq 0x5660
movq %rax, %rdi
callq 0x5fd0
nopw %cs:(%rax,%rax)