// File: /workspace/github_cpp_makefile_star2_O3/guoxuanhan[P]NetServer/tcpserver.cpp
// Function: TcpServer::OnNewConnection()
void TcpServer::OnNewConnection()
{
    //循环调用accept，获取所有的建立好连接的客户端fd
    struct sockaddr_in clientaddr;
    int clientfd;
    while( (clientfd = serversocket_.Accept(clientaddr)) > 0)
    {
        std::cout << "New client from IP:" << inet_ntoa(clientaddr.sin_addr)
            << ":" << ntohs(clientaddr.sin_port) << std::endl;

        if(++conncount_ >= MAXCONNECTION)
        {
            close(clientfd);
            continue;
        }
        Setnonblocking(clientfd);

        //选择IO线程loop
        EventLoop *loop = eventloopthreadpool.GetNextLoop();

        //创建连接，注册业务函数
        std::shared_ptr<TcpConnection> sptcpconnection = std::make_shared<TcpConnection>(loop, clientfd, clientaddr);
        sptcpconnection->SetMessaeCallback(messagecallback_);
        sptcpconnection->SetSendCompleteCallback(sendcompletecallback_);
        sptcpconnection->SetCloseCallback(closecallback_);
        sptcpconnection->SetErrorCallback(errorcallback_);
        sptcpconnection->SetConnectionCleanUp(std::bind(&TcpServer::RemoveConnection, this, std::placeholders::_1));
        {
            std::lock_guard<std::mutex> lock(mutex_);
            tcpconnlist_[clientfd] = sptcpconnection;
        }


        newconnectioncallback_(sptcpconnection);
        //Bug，应该把事件添加的操作放到最后,否则bug segement fault,导致HandleMessage中的phttpsession==NULL
        //总之就是做好一切准备工作再添加事件到epoll！！！
        sptcpconnection->AddChannelToLoop();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
leaq 0x78(%rsp), %rsi
callq 0xbd4e
movl %eax, 0x4(%rsp)
testl %eax, %eax
jle 0xd911
leaq 0xf8(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0x148(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x168(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x188(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x1a8(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0xd0(%rbx), %r14
leaq 0xa0(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x128(%rbx), %rax
movq %rax, 0x18(%rsp)
movq 0xa900(%rip), %rbp      # 0x17fb8
leaq 0x78(%rsp), %r15
leaq 0x50(%rsp), %r12
movl $0x13, %edx
movq %rbp, %rdi
leaq 0x3cf3(%rip), %rsi      # 0x113c4
callq 0x43a0
movl 0x7c(%rsp), %edi
callq 0x4170
testq %rax, %rax
je 0xd6ff
movq %rax, %r13
movq %rax, %rdi
callq 0x4160
movq %rbp, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x43a0
jmp 0xd717
movq (%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
movl 0x20(%rbp,%rax), %esi
orl $0x1, %esi
callq 0x4540
movl $0x1, %edx
movq %rbp, %rdi
leaq 0x3cb0(%rip), %rsi      # 0x113d6
callq 0x43a0
movzwl 0x7a(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %esi
movq %rbp, %rdi
callq 0x4230
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4320
movsbl %al, %esi
movq %r13, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4240
movl 0x98(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x98(%rbx)
movl 0x4(%rsp), %edi
cmpl $0x4e1f, %eax           # imm = 0x4E1F
jl 0xd78d
callq 0x4600
jmp 0xd8fa
callq 0xdae3
movq 0x48(%rsp), %rdi
callq 0x6358
movq %rax, 0x70(%rsp)
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
leaq 0x70(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r15, %r8
callq 0xdd16
movq 0x8(%rsp), %rdi
addq $0x78, %rdi
movq 0x40(%rsp), %rsi
callq 0x5354
movq 0x8(%rsp), %rdi
movl $0x98, %eax
addq %rax, %rdi
movq 0x38(%rsp), %rsi
callq 0x5290
movq 0x8(%rsp), %rdi
movl $0xb8, %eax
addq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x5290
movq 0x8(%rsp), %rdi
movl $0xd8, %eax
addq %rax, %rdi
movq 0x28(%rsp), %rsi
callq 0x5290
movq 0x8(%rsp), %r13
movq $0x0, 0x58(%rsp)
movl $0x18, %edi
callq 0x4350
leaq 0x2ea(%rip), %rcx       # 0xdb1c
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x50(%rsp)
leaq 0x66d(%rip), %rax       # 0xdeba
movq %rax, 0x68(%rsp)
leaq 0x671(%rip), %rax       # 0xdeca
movq %rax, 0x60(%rsp)
addq $0xf8, %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x5290
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0xd887
movq %r12, %rdi
movq %r12, %rsi
movl $0x3, %edx
callq *%rax
movq %r14, %rdi
callq 0x4480
testl %eax, %eax
jne 0xd928
movq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0xdb98
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
addq $0x8, %rax
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x7a48
movq %r14, %rdi
callq 0x42a0
cmpq $0x0, 0x138(%rbx)
je 0xd923
movq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq *0x140(%rbx)
movq 0x8(%rsp), %rdi
callq 0xc76a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xd8fa
callq 0x795e
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbd4e
movl %eax, 0x4(%rsp)
testl %eax, %eax
jg 0xd6c2
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4140
movl %eax, %edi
callq 0x4220
jmp 0xd95e
jmp 0xd96a
movq %rax, %rbx
movq %r14, %rdi
callq 0x42a0
jmp 0xd96d
movq %rax, %rbx
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0xd96d
leaq 0x50(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xd96d
movq %rax, %rdi
callq 0x4df2
jmp 0xd96a
jmp 0xd96a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xd97c
callq 0x795e
movq %rbx, %rdi
callq 0x45a0