// File: /workspace/github_cpp_makefile_star2_O2/DMLfor[P]TinyWebServer/./ServerBase.hpp
// Function: WebServer::ServerBase<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>>>>>::respond(std::shared_ptr<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>>>>>, std::shared_ptr<WebServer::Request>) const
void WebServer::ServerBase<socket_type>::respond(std::shared_ptr<socket_type> socket, std::shared_ptr<Request> request) const
{
	for(auto res_it : all_resources)
	{
		// 对请求路径和方法进行匹配查找, 并生成响应
		std::regex e(res_it->first);
		std::smatch sm_res;
		if(std::regex_match(request->path, sm_res, e))
		{
			if(res_it->second.count(request->method) > 0)
				request->path_match = move(sm_res);
			// 会被推导为 std::shared_ptr<boost::asio::streambuf>
			auto write_buffer = std::make_shared<boost::asio::streambuf>();
			std::ostream respondse(write_buffer.get());
			res_it->second[request->method](respondse, *request);

			// 在 lambda 中不糊 write_buffer 使其不会再 async_write 完成前被销毁
			boost::asio::async_write(*socket, *write_buffer,
					[this, socket, request, write_buffer](const boost::system::error_code &ec, size_t bytes_transferred)
					{
						// HTTP 持久连接(HTTP 1.1), 递归调用
						if(!ec && stof(request->http_version) > 1.05)
							process_request_and_respond(socket);
					});
			return ;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdx, %rbx
movq %rsi, 0x18(%rsp)
movq 0x108(%rdi), %r15
movq %rdi, 0x10(%rsp)
movq 0x110(%rdi), %rbp
leaq 0x78(%rsp), %r13
leaq 0x20(%rsp), %r14
cmpq %rbp, %r15
je 0x18c43
movq (%r15), %r12
leaq 0x20(%r12), %rsi
movq %r13, %rdi
pushq $0x10
popq %rdx
callq 0x266fc
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq (%rbx), %rdi
addq $0x20, %rdi
movq %r14, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x19030
testb %al, %al
jne 0x18b65
movq %r14, %rdi
callq 0x228d2
movq %r13, %rdi
callq 0x1908a
addq $0x8, %r15
jmp 0x18b0e
addq $0x40, %r12
movq (%rbx), %rsi
movq %r12, %rdi
callq 0x267a8
testq %rax, %rax
je 0x18b8b
movl $0xa8, %edi
addq (%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0x24426
movq %rsp, %rdi
callq 0x15caf
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0xa2e0
movq (%rbx), %rsi
movq %r12, %rdi
callq 0x2688c
movq (%rbx), %rdx
leaq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x2675e
movq 0x18(%rsp), %rsi
movq (%rsi), %r14
movq %rsp, %r12
movq (%r12), %r13
leaq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rax, -0x8(%rdi)
callq 0x28de6
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x266c8
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x2895e
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x26771
leaq 0x40(%rsp), %rdi
callq 0x26784
leaq 0xa0(%rsp), %rdi
callq 0xa260
leaq 0x8(%rsp), %rdi
callq 0x18f4e
leaq 0x20(%rsp), %rdi
callq 0x228d2
leaq 0x78(%rsp), %rdi
callq 0x1908a
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x26784
jmp 0x18c70
movq %rax, %rbx
jmp 0x18c7d
jmp 0x18c89
jmp 0x18c89
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0xa260
leaq 0x8(%rsp), %rdi
callq 0x18f4e
jmp 0x18c8c
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x228d2
leaq 0x78(%rsp), %rdi
callq 0x1908a
movq %rbx, %rdi
callq 0xaac0