// File: 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>>>>>>::start()
void WebServer::ServerBase<socket_type>::start()
{
	// 默认资源回放在 vector 的末尾，用作默认应答
	// 默认的请求会在找不到匹配请求路径时, 进行访问,故在最后添加
	for(auto it = resource.begin(); it != resource.end(); it++)
		all_resources.push_back(it);

	for(auto it = default_resource.begin(); it != default_resource.end(); it++)
		all_resources.push_back(it);
	// 调用 socket 的连接方式，还需要子类来实现 accept() 逻辑
	accept();
	// 如果 num_threads>1, 那么 m_io_service.run()
	// 将运行 (num_threads-1) 线程成为线程池
	for(size_t c = 1; c<num_threads; c++)
	{
		threads.emplace_back([this]()
				{
					m_io_service.run();
				});
	}
	// 主线程
	m_io_service.run();

	// 等待其他线程, 如果有的话，就等待这些线程的结束
	for(auto &t :threads)
		t.join();
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq 0x70(%rsp), %rdi
movq %rdi, 0x8(%rsp)
addq $0x8, %rdi
callq 0x767e0
movq %rax, 0x68(%rsp)
movq 0x8(%rsp), %rdi
addq $0x8, %rdi
callq 0x738f0
movq %rax, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x76810
testb $0x1, %al
jne 0x73739
jmp 0x73762
movq 0x8(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
leaq 0x68(%rsp), %rsi
callq 0x76830
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
callq 0x768a0
movq %rax, 0x58(%rsp)
jmp 0x73711
movq 0x8(%rsp), %rdi
addq $0x38, %rdi
callq 0x767e0
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rdi
addq $0x38, %rdi
callq 0x738f0
movq %rax, 0x48(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x76810
testb $0x1, %al
jne 0x7379d
jmp 0x737c6
movq 0x8(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
leaq 0x50(%rsp), %rsi
callq 0x76830
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x768a0
movq %rax, 0x40(%rsp)
jmp 0x73775
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq $0x1, 0x38(%rsp)
movq 0x8(%rsp), %rcx
movq 0x38(%rsp), %rax
cmpq 0xe8(%rcx), %rax
jae 0x7381b
movq 0x8(%rsp), %rax
movq %rax, %rdi
addq $0xf0, %rdi
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rsi
callq 0x768e0
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x737da
movq 0x8(%rsp), %rdi
addq $0x68, %rdi
callq 0x76950
movq 0x8(%rsp), %rax
addq $0xf0, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
callq 0x769a0
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rdi
callq 0x769d0
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x76a00
testb $0x1, %al
jne 0x7386c
jmp 0x73891
leaq 0x20(%rsp), %rdi
callq 0x76a40
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0xc3c0
leaq 0x20(%rsp), %rdi
callq 0x76a50
jmp 0x73857
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)