// File: /workspace/github_cpp_makefile_star2_O3/guoxuanhan[P]NetServer/httpserver.cpp
// Function: HttpServer::HandleMessage(std::shared_ptr<TcpConnection> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void HttpServer::HandleMessage(const spTcpConnection& sptcpconn, std::string &msg)
{
    std::shared_ptr<HttpSession> sphttpsession;
    spTimer sptimer;
    {
        std::lock_guard <std::mutex> lock(mutex_);
        sphttpsession = httpsessionnlist_[sptcpconn];
        sptimer = timerlist_[sptcpconn];
    }
    sptimer->Adjust(5000, Timer::TimerType::TIMER_ONCE, std::bind(&TcpConnection::Shutdown, sptcpconn));

    if(threadpool_.GetThreadNum() > 0)
    {
        //Bug20190320：多线程下，对象的声明周期管理问题，就像在这里，向线程池传入了phttpsession和ptcpconn，怎么知道其指向对象是否已经析构了呢？
        //所以，需要采用智能指针来管理对象,替换原始指针
        //线程池处理业务，处理完后投递回本IO线程执行send
        //std::cout << "threadpool_.AddTask" << std::endl;
        HttpRequestContext httprequestcontext;
        std::string responsecontext;
        bool result = sphttpsession->PraseHttpRequest(msg, httprequestcontext);
        if(result == false)
        {
            sphttpsession->HttpError(400, "Bad request", httprequestcontext, responsecontext); //请求报文解析错误，报400
            sptcpconn->Send(responsecontext);
            return;
        }

        sptcpconn->SetAsyncProcessing(true);
        threadpool_.AddTask([=]() {
            //HttpRequestContext req = httprequestcontext;
            std::string responsemsg;
            sphttpsession->HttpProcess(httprequestcontext, responsemsg);

            sptcpconn->Send(responsemsg); //任务已经处理完成，执行跨线程调度，即回调

            if(!sphttpsession->KeepAlive())
            {
                //短连接，可以告诉框架层数据发完就可以关掉TCP连接，不过这里注释掉，还是交给客户端主动关闭吧
                //sptcpconn->HandleClose();
            }
        });
    }
    else
    {
        //没有开启业务线程池，业务计算直接在IO线程执行
        HttpRequestContext httprequestcontext;
        std::string responsecontext;
        bool result = sphttpsession->PraseHttpRequest(msg, httprequestcontext);
        if(result == false)
        {
            sphttpsession->HttpError(400, "Bad request", httprequestcontext, responsecontext); //请求报文解析错误，报400
            sptcpconn->Send(responsecontext);
            return;
        }

        sphttpsession->HttpProcess(httprequestcontext, responsecontext);

        sptcpconn->Send(responsecontext);

        if(!sphttpsession->KeepAlive())
        {
            //短连接，可以告诉框架层数据发完就可以关掉TCP连接，不过这里注释掉，还是交给客户端主动关闭吧
            //sptcpconn->HandleClose();
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movaps %xmm0, 0xe0(%rsp)
leaq 0x60(%rdi), %r15
movq %r15, %rdi
callq 0x4480
testl %eax, %eax
jne 0x71e8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x76b0
movq (%rax), %rcx
leaq 0x8(%rsp), %rdi
movq %rcx, -0x8(%rdi)
addq $0x8, %rax
movq %rax, %rsi
callq 0x7a48
leaq 0x30(%rbx), %rdi
movq %r14, %rsi
callq 0x7716
movq (%rax), %rcx
leaq 0xe8(%rsp), %r13
movq %rcx, -0x8(%r13)
addq $0x8, %rax
movq %r13, %rdi
movq %rax, %rsi
callq 0x7a48
movq %r15, %rdi
callq 0x42a0
movq -0x8(%r13), %r13
movq (%r14), %rbp
movq 0x8(%r14), %r15
testq %r15, %r15
je 0x6aaf
movq 0x11511(%rip), %rax     # 0x17fb0
cmpb $0x0, (%rax)
je 0x6aaa
incl 0x8(%r15)
jmp 0x6aaf
lock
incl 0x8(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x20, %edi
callq 0x4350
leaq 0x60a3(%rip), %rcx      # 0xcb70
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movq %rbp, 0x10(%rax)
movq %r15, 0x18(%rax)
leaq 0x10(%rsp), %r15
movq %rax, (%r15)
leaq 0x1b7f(%rip), %rax      # 0x866e
movq %rax, 0x18(%r15)
leaq 0x1b90(%rip), %rax      # 0x868a
movq %rax, 0x10(%r15)
movq %r13, %rdi
movl $0x1388, %esi           # imm = 0x1388
xorl %edx, %edx
movq %r15, %rcx
callq 0xf214
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x6b29
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x250, %rbx            # imm = 0x250
movq %rbx, %rdi
callq 0xe9a6
testl %eax, %eax
jle 0x6c14
leaq 0x188(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x1a8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x1c8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x1e0(%rsp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x218(%rsp), %r13
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0x128(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %rax, -0x8(%rbp)
movb %al, (%rbp)
movq (%rsp), %rdi
leaq 0x178(%rsp), %rdx
movq %r12, %rsi
callq 0x8c08
testb %al, %al
je 0x6cbd
movq (%r14), %rax
movb $0x1, 0x36(%rax)
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x6e06
movq 0x113ad(%rip), %rcx     # 0x17fb0
cmpb $0x0, (%rcx)
je 0x6e02
incl 0x8(%rax)
jmp 0x6e06
leaq 0x20(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x40(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x60(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %rax, -0x8(%rbp)
movb %al, (%rbp)
leaq 0x78(%rsp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0xb0(%rsp), %r13
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0x188(%rsp), %r15
movq %r15, -0x10(%r15)
movq %rax, -0x8(%r15)
movb %al, (%r15)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq %r12, %rsi
callq 0x8c08
movq (%rsp), %rbx
testb %al, %al
je 0x6d34
leaq 0x10(%rsp), %rsi
leaq 0x178(%rsp), %rdx
movq %rbx, %rdi
callq 0x912e
jmp 0x6d90
movq (%rsp), %rbx
leaq 0x168(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x98a4(%rip), %rsi      # 0x10578
leaq 0x98a8(%rip), %rdx      # 0x10583
leaq 0x158(%rsp), %rdi
callq 0x6112
leaq 0x158(%rsp), %rdx
leaq 0x178(%rsp), %rcx
leaq 0x118(%rsp), %r8
movq %rbx, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0x9ee0
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0x6d1f
callq 0x4310
movq (%r14), %rdi
leaq 0x118(%rsp), %rsi
callq 0xc820
jmp 0x7137
leaq 0x148(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x9830(%rip), %rsi      # 0x10578
leaq 0x9834(%rip), %rdx      # 0x10583
leaq 0x138(%rsp), %rdi
callq 0x6112
leaq 0x138(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x178(%rsp), %r8
movq %rbx, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0x9ee0
movq 0x138(%rsp), %rdi
cmpq %r12, %rdi
je 0x6d90
callq 0x4310
movq (%r14), %rdi
leaq 0x178(%rsp), %rsi
callq 0xc820
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0x6db2
callq 0x4310
movq 0xa0(%rsp), %rdi
cmpq %r13, %rdi
je 0x6dc4
callq 0x4310
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x7df0
movq -0x20(%rbx), %rdi
cmpq %rbp, %rdi
je 0x6ddf
callq 0x4310
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x6df3
callq 0x4310
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
jmp 0x71ab
lock
incl 0x8(%rax)
leaq 0x20(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x777c
movq (%r14), %rax
movq %rax, 0xd0(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0xd8(%rsp)
testq %rax, %rax
je 0x6e49
movq 0x11175(%rip), %rcx     # 0x17fb0
cmpb $0x0, (%rcx)
je 0x6e45
incl 0x8(%rax)
jmp 0x6e49
lock
incl 0x8(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movl $0xd0, %edi
callq 0x4350
movq %rax, %rcx
leaq 0x30(%rsp), %r14
movaps -0x20(%r14), %xmm0
xorl %edx, %edx
movq %rdx, -0x18(%r14)
movups %xmm0, (%rax)
movq %rdx, -0x20(%r14)
leaq 0x20(%rax), %rdx
movq %rdx, 0x10(%rax)
movq -0x10(%r14), %rsi
cmpq %r14, %rsi
je 0x6ea0
movq %rsi, 0x10(%rcx)
movq 0x30(%rsp), %rdx
movq %rdx, 0x20(%rcx)
jmp 0x6ea7
movups (%r14), %xmm0
movups %xmm0, (%rdx)
leaq 0x50(%rsp), %r12
movq -0x28(%r12), %rdx
movq %rdx, 0x18(%rcx)
movq %r14, -0x30(%r12)
movq $0x0, -0x28(%r12)
movb $0x0, -0x20(%r12)
leaq 0x40(%rax), %rdx
movq %rdx, 0x30(%rcx)
movq -0x10(%r12), %rsi
cmpq %r12, %rsi
je 0x6eea
movq %rsi, 0x30(%rcx)
movq 0x50(%rsp), %rdx
movq %rdx, 0x40(%rcx)
jmp 0x6ef2
movups (%r12), %xmm0
movups %xmm0, (%rdx)
leaq 0x70(%rsp), %rbp
movq -0x28(%rbp), %rdx
movq %rdx, 0x38(%rcx)
movq %r12, -0x30(%rbp)
movq $0x0, -0x28(%rbp)
movb $0x0, -0x20(%rbp)
leaq 0x60(%rax), %rdx
movq %rdx, 0x50(%rcx)
movq -0x10(%rbp), %rsi
cmpq %rbp, %rsi
je 0x6f2f
movq %rsi, 0x50(%rcx)
movq 0x70(%rsp), %rdx
movq %rdx, 0x60(%rcx)
jmp 0x6f36
movups (%rbp), %xmm0
movups %xmm0, (%rdx)
movq 0x68(%rsp), %rdx
movq %rdx, 0x58(%rcx)
movq %rbp, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movb $0x0, 0x70(%rsp)
leaq 0x78(%rax), %rdx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x6fa8
leaq 0x88(%rsp), %r9
movl (%r9), %esi
movq %rdi, 0x80(%rcx)
movq 0x10(%r9), %r10
movq 0x18(%r9), %r8
movq %rdx, 0x8(%rdi)
leaq 0xa8(%rsp), %rdi
movq (%rdi), %rdx
movq %rdx, 0x98(%rcx)
movq $0x0, -0x18(%rdi)
movq %r9, -0x10(%rdi)
movq %r9, -0x8(%rdi)
movq %r10, %rdx
jmp 0x6fbf
movq $0x0, 0x80(%rcx)
leaq 0x98(%rax), %rdi
xorl %esi, %esi
movq %rdx, %r8
movq %rdx, 0x88(%rcx)
movq %r8, 0x90(%rcx)
movq $0x0, (%rdi)
movl %esi, 0x78(%rcx)
movl $0xb0, %esi
addq %rsi, %rax
movq %rax, 0xa0(%rcx)
movq 0xb0(%rsp), %rdx
addq %rsi, %r15
cmpq %r15, %rdx
je 0x700e
movq %rdx, 0xa0(%rcx)
movq 0xc0(%rsp), %rax
movq %rax, 0xb0(%rcx)
jmp 0x7015
movups (%r15), %xmm0
movups %xmm0, (%rax)
movq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rcx)
movq %r15, 0xb0(%rsp)
movq $0x0, 0xb8(%rsp)
movb $0x0, 0xc0(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rcx)
movq 0xd8(%rsp), %rax
movq %rax, 0xc8(%rcx)
testq %rax, %rax
je 0x7078
movq 0x10f46(%rip), %rdx     # 0x17fb0
cmpb $0x0, (%rdx)
je 0x7074
incl 0x8(%rax)
jmp 0x7078
lock
incl 0x8(%rax)
leaq 0xf0(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0x444(%rip), %rax       # 0x74ce
movq %rax, 0x18(%rsi)
leaq 0x4ab(%rip), %rax       # 0x7540
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0xe948
movq 0x100(%rsp), %rax
testq %rax, %rax
je 0x70c0
leaq 0xf0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x70d2
callq 0x795e
movq 0xb0(%rsp), %rdi
cmpq %r15, %rdi
je 0x70e4
callq 0x4310
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x7df0
movq -0x20(%rbx), %rdi
cmpq %rbp, %rdi
je 0x7102
callq 0x4310
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
leaq 0x128(%rsp), %rbp
je 0x7119
callq 0x4310
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x7128
callq 0x4310
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x7137
callq 0x795e
movq 0x118(%rsp), %rdi
cmpq %rbp, %rdi
je 0x7149
callq 0x4310
movq 0x208(%rsp), %rdi
cmpq %r13, %rdi
je 0x715b
callq 0x4310
leaq 0x1d8(%rsp), %rbx
movq %rbx, %rdi
callq 0x7df0
movq -0x20(%rbx), %rdi
leaq 0x1c8(%rsp), %rax
cmpq %rax, %rdi
je 0x7181
callq 0x4310
movq 0x198(%rsp), %rdi
leaq 0x1a8(%rsp), %rax
cmpq %rax, %rdi
je 0x719b
callq 0x4310
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x71b5
callq 0x4310
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x71c7
callq 0x795e
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x71d6
callq 0x795e
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x4220
movq %rax, %rbx
movq 0x138(%rsp), %rdi
cmpq %r12, %rdi
je 0x7277
callq 0x4310
jmp 0x7277
jmp 0x7274
jmp 0x72dc
movq %rax, %rbx
movq 0x100(%rsp), %rax
testq %rax, %rax
je 0x7239
leaq 0xf0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x7239
jmp 0x72dc
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x7444
jmp 0x7293
movq %rax, %rbx
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0x7293
callq 0x4310
jmp 0x7293
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x7293
callq 0x795e
jmp 0x7293
jmp 0x7290
jmp 0x72dc
movq %rax, %rbx
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0x7289
callq 0x4310
leaq 0x10(%rsp), %rdi
jmp 0x72b5
movq %rax, %rbx
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0x72ad
callq 0x4310
leaq 0x178(%rsp), %rdi
callq 0x7886
jmp 0x7306
jmp 0x72f6
movq %rax, %rbx
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x7306
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x7306
movq %rax, %rdi
callq 0x4df2
movq %rax, %rbx
testq %r15, %r15
je 0x7306
movq %r15, %rdi
callq 0x795e
jmp 0x7306
movq %rax, %rbx
jmp 0x7306
movq %rax, %rbx
movq %r15, %rdi
callq 0x42a0
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x7318
callq 0x795e
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x7327
callq 0x795e
movq %rbx, %rdi
callq 0x45a0
nop