// File: nmmmnu[P]HM3/main/db_net.cc
// Function: main
int main(int argc, char **argv){
	constexpr const char	*HOSTNAME		= "localhost.not.used.yet";
	constexpr int		PORT			= 2000;

	constexpr size_t	MAX_CLIENTS		= 1024;
	constexpr uint32_t	CONNECTION_TIMEOUT	= 30;
	const     size_t	MAX_PACKET_SIZE		= hm3::Pair::MAX_SIZE * 2;

	// ----------------------------------

	if (argc <= 1){
		printUsage(argv[0]);
		return 1;
	}

	const auto path = argv[1];

	// ----------------------------------

	using MyTableLoader	= hm3::tableloader::DirectoryTableLoader;
	using MyLSMTable	= hm3::LSMTable<MyTableLoader::container_type>;

	MyTableLoader loader{ path };
	MyLSMTable list(*loader);

	// ----------------------------------

	using MyAdapter = DBAdapter<MyLSMTable, MyTableLoader>;
	MyAdapter adapter(list, loader);

	// ----------------------------------

	using MySelector	= net::selector::PollSelector;
	using MyProtocol	= net::protocol::RedisProtocol;
	using MyWorker		= net::worker::KeyValueWorker<MyProtocol, MyAdapter>;

	using MyLoop		= net::AsyncLoop<MySelector, MyWorker>;

	int const fd1 = net::socket_create(net::SOCKET_TCP{}, HOSTNAME, PORT);

	MyLoop loop( MySelector{ MAX_CLIENTS }, MyWorker{ adapter }, { fd1 },
							CONNECTION_TIMEOUT, MAX_PACKET_SIZE);

	while(loop.process());
}

// Assembly:
subq $0x11d8, %rsp           # imm = 0x11D8
movl $0x0, 0x11d4(%rsp)
movl %edi, 0x11d0(%rsp)
movq %rsi, 0x11c8(%rsp)
leaq 0x158ec(%rip), %rax     # 0x19064
movq %rax, 0x11c0(%rsp)
movl $0x7d0, 0x11bc(%rsp) # imm = 0x7D0
movq $0x400, 0x11b0(%rsp) # imm = 0x400
movl $0x1e, 0x11ac(%rsp)
leaq 0x15c53(%rip), %rax     # 0x193fc
movl (%rax), %eax
shll %eax
movl %eax, %eax
movq %rax, 0x11a0(%rsp)
cmpl $0x1, 0x11d0(%rsp)
jg 0x37e1
movq 0x11c8(%rsp), %rax
movq (%rax), %rdi
callq 0x39f0
movl $0x1, 0x11d4(%rsp)
jmp 0x39ba
movq 0x11c8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x1198(%rsp)
movq 0x1198(%rsp), %rsi
leaq 0x1150(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x3aa0
movq 0x10(%rsp), %rsi
leaq 0x1160(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x3af0
movq 0x18(%rsp), %rdi
callq 0x3b70
movq %rax, 0x20(%rsp)
jmp 0x3837
movq 0x20(%rsp), %rsi
leaq 0x1148(%rsp), %rdi
callq 0x3b80
jmp 0x384b
leaq 0x1120(%rsp), %rdi
leaq 0x1148(%rsp), %rsi
leaq 0x1160(%rsp), %rdx
movl $0x32, %ecx
callq 0x3ba0
jmp 0x386f
leaq 0x157ee(%rip), %rdi     # 0x19064
movl $0x7d0, %esi            # imm = 0x7D0
xorl %edx, %edx
movl $0x7, %ecx
callq 0x18030
movl %eax, 0x111c(%rsp)
leaq 0x60(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x15fd0
jmp 0x389f
leaq 0x40(%rsp), %rdi
leaq 0x1120(%rsp), %rsi
callq 0x3be0
jmp 0x38b3
movl 0x111c(%rsp), %eax
movl %eax, 0x2c(%rsp)
leaq 0x2c(%rsp), %rax
movq %rax, 0x30(%rsp)
movq $0x1, 0x38(%rsp)
movq 0x11a0(%rsp), %r9
leaq 0x78(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movl $0x1e, %r8d
callq 0x3c10
jmp 0x38fa
leaq 0x40(%rsp), %rdi
callq 0x3e80
leaq 0x60(%rsp), %rdi
callq 0x16150
leaq 0x78(%rsp), %rdi
callq 0x3e90
movb %al, 0xf(%rsp)
jmp 0x391e
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x3928
jmp 0x39a3
jmp 0x390e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1140(%rsp)
movl %eax, 0x113c(%rsp)
jmp 0x39c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1140(%rsp)
movl %eax, 0x113c(%rsp)
jmp 0x3977
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1140(%rsp)
movl %eax, 0x113c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x3e80
leaq 0x60(%rsp), %rdi
callq 0x16150
jmp 0x39c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1140(%rsp)
movl %eax, 0x113c(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x4000
jmp 0x39c9
leaq 0x78(%rsp), %rdi
callq 0x4000
leaq 0x1160(%rsp), %rdi
callq 0x40c0
movl 0x11d4(%rsp), %eax
addq $0x11d8, %rsp           # imm = 0x11D8
retq
leaq 0x1160(%rsp), %rdi
callq 0x40c0
movq 0x1140(%rsp), %rdi
callq 0x34c0
nopw %cs:(%rax,%rax)