// File: /workspace/github_cpp_makefile_star2_O1/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 0x7203
movq %rbx, %rdi
movq %r14, %rsi
callq 0x76d6
movq (%rax), %rcx
leaq 0x8(%rsp), %rdi
movq %rcx, -0x8(%rdi)
addq $0x8, %rax
movq %rax, %rsi
callq 0x7a6e
leaq 0x30(%rbx), %rdi
movq %r14, %rsi
callq 0x773c
movq (%rax), %rcx
leaq 0xe8(%rsp), %r13
movq %rcx, -0x8(%r13)
addq $0x8, %rax
movq %r13, %rdi
movq %rax, %rsi
callq 0x7a6e
movq %r15, %rdi
callq 0x42a0
movq -0x8(%r13), %r13
movq (%r14), %rbp
movq 0x8(%r14), %r15
testq %r15, %r15
je 0x6ac3
movq 0x114fd(%rip), %rax     # 0x17fb0
cmpb $0x0, (%rax)
je 0x6abe
incl 0x8(%r15)
jmp 0x6ac3
lock
incl 0x8(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x20, %edi
callq 0x4350
leaq 0x60d7(%rip), %rcx      # 0xcbb8
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movq %rbp, 0x10(%rax)
movq %r15, 0x18(%rax)
leaq 0x10(%rsp), %r15
movq %rax, (%r15)
leaq 0x1ba5(%rip), %rax      # 0x86a8
movq %rax, 0x18(%r15)
leaq 0x1bb6(%rip), %rax      # 0x86c4
movq %rax, 0x10(%r15)
movq %r13, %rdi
movl $0x1388, %esi           # imm = 0x1388
xorl %edx, %edx
movq %r15, %rcx
callq 0xf290
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x6b3d
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x250, %rbx            # imm = 0x250
movq %rbx, %rdi
callq 0xea24
testl %eax, %eax
jle 0x6c28
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 0x8c38
testb %al, %al
je 0x6cd1
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 0x6e1a
movq 0x11399(%rip), %rcx     # 0x17fb0
cmpb $0x0, (%rcx)
je 0x6e16
incl 0x8(%rax)
jmp 0x6e1a
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 0x8c38
movq (%rsp), %rbx
testb %al, %al
je 0x6d48
leaq 0x10(%rsp), %rsi
leaq 0x178(%rsp), %rdx
movq %rbx, %rdi
callq 0x9178
jmp 0x6da4
movq (%rsp), %rbx
leaq 0x168(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9913(%rip), %rsi      # 0x105fb
leaq 0x9917(%rip), %rdx      # 0x10606
leaq 0x158(%rsp), %rdi
callq 0x613c
leaq 0x158(%rsp), %rdx
leaq 0x178(%rsp), %rcx
leaq 0x118(%rsp), %r8
movq %rbx, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0x9f26
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0x6d33
callq 0x4310
movq (%r14), %rdi
leaq 0x118(%rsp), %rsi
callq 0xc866
jmp 0x7152
leaq 0x148(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x989f(%rip), %rsi      # 0x105fb
leaq 0x98a3(%rip), %rdx      # 0x10606
leaq 0x138(%rsp), %rdi
callq 0x613c
leaq 0x138(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x178(%rsp), %r8
movq %rbx, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0x9f26
movq 0x138(%rsp), %rdi
cmpq %r12, %rdi
je 0x6da4
callq 0x4310
movq (%r14), %rdi
leaq 0x178(%rsp), %rsi
callq 0xc866
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0x6dc6
callq 0x4310
movq 0xa0(%rsp), %rdi
cmpq %r13, %rdi
je 0x6dd8
callq 0x4310
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x7e0c
movq -0x20(%rbx), %rdi
cmpq %rbp, %rdi
je 0x6df3
callq 0x4310
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x6e07
callq 0x4310
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
jmp 0x71c6
lock
incl 0x8(%rax)
leaq 0x20(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x77a2
movq (%r14), %rax
movq %rax, 0xd0(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0xd8(%rsp)
testq %rax, %rax
je 0x6e5d
movq 0x11161(%rip), %rcx     # 0x17fb0
cmpb $0x0, (%rcx)
je 0x6e59
incl 0x8(%rax)
jmp 0x6e5d
lock
incl 0x8(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movl $0xd0, %edi
callq 0x4350
movq %rax, %rcx
xorl %edx, %edx
movq %rdx, 0x8(%rax)
leaq 0x30(%rsp), %r14
movaps -0x20(%r14), %xmm0
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 0x6eb8
movq %rsi, 0x10(%rcx)
movq 0x30(%rsp), %rdx
movq %rdx, 0x20(%rcx)
jmp 0x6ebf
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 0x6f02
movq %rsi, 0x30(%rcx)
movq 0x50(%rsp), %rdx
movq %rdx, 0x40(%rcx)
jmp 0x6f0a
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 0x6f47
movq %rsi, 0x50(%rcx)
movq 0x70(%rsp), %rdx
movq %rdx, 0x60(%rcx)
jmp 0x6f4e
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), %rsi
testq %rsi, %rsi
je 0x6fc4
leaq 0x88(%rsp), %rdi
movl (%rdi), %r8d
movl %r8d, 0x78(%rcx)
movq %rsi, 0x80(%rcx)
movups 0x10(%rdi), %xmm0
movups %xmm0, 0x88(%rcx)
movq %rdx, 0x8(%rsi)
leaq 0xa8(%rsp), %rdx
movq (%rdx), %rsi
movq %rsi, 0x98(%rcx)
movq $0x0, -0x18(%rdx)
movq %rdi, -0x10(%rdx)
movq %rdi, -0x8(%rdx)
jmp 0x6feb
movl $0x0, 0x78(%rcx)
movq $0x0, 0x80(%rcx)
movq %rdx, 0x88(%rcx)
movq %rdx, 0x90(%rcx)
leaq 0x98(%rax), %rdx
movq $0x0, (%rdx)
movl $0xb0, %esi
addq %rsi, %rax
movq %rax, 0xa0(%rcx)
movq 0xb0(%rsp), %rdx
addq %rsi, %r15
cmpq %r15, %rdx
je 0x7029
movq %rdx, 0xa0(%rcx)
movq 0xc0(%rsp), %rax
movq %rax, 0xb0(%rcx)
jmp 0x7030
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 0x7093
movq 0x10f2b(%rip), %rdx     # 0x17fb0
cmpb $0x0, (%rdx)
je 0x708f
incl 0x8(%rax)
jmp 0x7093
lock
incl 0x8(%rax)
leaq 0xf0(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0x447(%rip), %rax       # 0x74ec
movq %rax, 0x18(%rsi)
leaq 0x4ae(%rip), %rax       # 0x755e
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0xe9c6
movq 0x100(%rsp), %rax
testq %rax, %rax
je 0x70db
leaq 0xf0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x70ed
callq 0x7984
movq 0xb0(%rsp), %rdi
cmpq %r15, %rdi
je 0x70ff
callq 0x4310
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x7e0c
movq -0x20(%rbx), %rdi
cmpq %rbp, %rdi
je 0x711d
callq 0x4310
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
leaq 0x128(%rsp), %rbp
je 0x7134
callq 0x4310
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x7143
callq 0x4310
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x7152
callq 0x7984
movq 0x118(%rsp), %rdi
cmpq %rbp, %rdi
je 0x7164
callq 0x4310
movq 0x208(%rsp), %rdi
cmpq %r13, %rdi
je 0x7176
callq 0x4310
leaq 0x1d8(%rsp), %rbx
movq %rbx, %rdi
callq 0x7e0c
movq -0x20(%rbx), %rdi
leaq 0x1c8(%rsp), %rax
cmpq %rax, %rdi
je 0x719c
callq 0x4310
movq 0x198(%rsp), %rdi
leaq 0x1a8(%rsp), %rax
cmpq %rax, %rdi
je 0x71b6
callq 0x4310
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x71d0
callq 0x4310
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x71e2
callq 0x7984
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x71f1
callq 0x7984
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 0x7292
callq 0x4310
jmp 0x7292
jmp 0x728f
jmp 0x72fa
movq %rax, %rbx
movq 0x100(%rsp), %rax
testq %rax, %rax
je 0x7254
leaq 0xf0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x7254
jmp 0x72fa
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x7462
jmp 0x72ae
movq %rax, %rbx
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0x72ae
callq 0x4310
jmp 0x72ae
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x72ae
callq 0x7984
jmp 0x72ae
jmp 0x72ab
jmp 0x72fa
movq %rax, %rbx
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0x72a4
callq 0x4310
leaq 0x10(%rsp), %rdi
jmp 0x72d0
movq %rax, %rbx
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0x72c8
callq 0x4310
leaq 0x178(%rsp), %rdi
callq 0x78ac
jmp 0x7324
jmp 0x7314
movq %rax, %rbx
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x72f5
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorl %r15d, %r15d
jmp 0x7305
movq %rax, %rdi
callq 0x4df2
movq %rax, %rbx
testq %r15, %r15
je 0x7324
movq %r15, %rdi
callq 0x7984
jmp 0x7324
movq %rax, %rbx
jmp 0x7324
movq %rax, %rbx
movq %r15, %rdi
callq 0x42a0
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x7336
callq 0x7984
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x7345
callq 0x7984
movq %rbx, %rdi
callq 0x45a0
nop