// File: /workspace/github_cpp_makefile_star2_O1/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 $0x98, %rsp
movq %rdi, %rbx
leaq 0x88(%rsp), %rsi
callq 0xbda0
movl %eax, 0xc(%rsp)
testl %eax, %eax
jle 0xd979
leaq 0xf8(%rbx), %rax
movq %rax, 0x78(%rsp)
leaq 0x148(%rbx), %rax
movq %rax, 0x70(%rsp)
leaq 0x168(%rbx), %rax
movq %rax, 0x68(%rsp)
leaq 0x188(%rbx), %rax
movq %rax, 0x60(%rsp)
leaq 0x1a8(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0xd0(%rbx), %r14
leaq 0xa0(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x128(%rbx), %rax
movq %rax, 0x48(%rsp)
movq 0xa8ab(%rip), %rbp      # 0x17fb8
leaq 0x88(%rsp), %r15
leaq 0x20(%rsp), %r12
movl $0x13, %edx
movq %rbp, %rdi
leaq 0x3cab(%rip), %rsi      # 0x113d4
callq 0x43a0
movl 0x8c(%rsp), %edi
callq 0x4170
testq %rax, %rax
je 0xd75a
movq %rax, %r13
movq %rax, %rdi
callq 0x4160
movq %rbp, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x43a0
jmp 0xd772
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 0x3c65(%rip), %rsi      # 0x113e6
callq 0x43a0
movzwl 0x8a(%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 0xc(%rsp), %edi
cmpl $0x4e1f, %eax           # imm = 0x4E1F
jl 0xd7eb
callq 0x4600
jmp 0xd962
callq 0xdb4b
movq 0x78(%rsp), %rdi
callq 0x637c
movq %rax, 0x80(%rsp)
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
leaq 0x80(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r15, %r8
callq 0xdd80
movq 0x10(%rsp), %rdi
addq $0x78, %rdi
movq 0x70(%rsp), %rsi
callq 0x5364
movq 0x10(%rsp), %rdi
movl $0x98, %eax
addq %rax, %rdi
movq 0x68(%rsp), %rsi
callq 0x52a0
movq 0x10(%rsp), %rdi
movl $0xb8, %eax
addq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x52a0
movq 0x10(%rsp), %rdi
movl $0xd8, %eax
addq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x52a0
movq 0x10(%rsp), %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movl $0x18, %edi
callq 0x4350
leaq 0x2ea(%rip), %rcx       # 0xdb84
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x20(%rsp)
leaq 0x675(%rip), %rax       # 0xdf2a
movq %rax, 0x38(%rsp)
leaq 0x679(%rip), %rax       # 0xdf3a
movq %rax, 0x30(%rsp)
addq $0xf8, %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x52a0
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xd8ef
movq %r12, %rdi
movq %r12, %rsi
movl $0x3, %edx
callq *%rax
movq %r14, %rdi
callq 0x4480
testl %eax, %eax
jne 0xd990
movq 0x50(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0xdc00
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
addq $0x8, %rax
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x7a6e
movq %r14, %rdi
callq 0x42a0
cmpq $0x0, 0x138(%rbx)
je 0xd98b
movq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq *0x140(%rbx)
movq 0x10(%rsp), %rdi
callq 0xc7b0
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xd962
callq 0x7984
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbda0
movl %eax, 0xc(%rsp)
testl %eax, %eax
jg 0xd71a
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4140
movl %eax, %edi
callq 0x4220
jmp 0xd9c6
jmp 0xd9d2
movq %rax, %rbx
movq %r14, %rdi
callq 0x42a0
jmp 0xd9d5
movq %rax, %rbx
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xd9d5
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xd9d5
movq %rax, %rdi
callq 0x4df2
jmp 0xd9d2
jmp 0xd9d2
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xd9e4
callq 0x7984
movq %rbx, %rdi
callq 0x45a0