// File: dak98[P]SocketIO/src/server.cpp
// Function: socket_io::server::server(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, socket_io::ip_protocol const&)
server::server(std::string const& port, ip_protocol const& ip_version)
    : ip_version{ip_version}, main_socket{ip_version},
      address_of_server{ipv4_socket_address{"INADDR_ANY", port}}
{
    if (this->ip_version == ip_protocol::IPv6)
	address_of_server = ipv6_socket_address{"in6addr_any", port};

    bind(main_socket, address_of_server);
    
    if (listen(main_socket.get_native_handle(),
	       std::numeric_limits<int>::max())	== -1)
	throw std::runtime_error{"An error occured on server start: " +
		                 get_errno_as_string()};

    accept_clients_tid = std::thread(&server::accept_clients, this);
    accept_clients_tid.detach();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x130(%rbp)
movq %rdi, %rax
movq %rax, -0x138(%rbp)
callq 0x1e780
movq -0x130(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, 0x8(%rdi)
addq $0xc, %rdi
movq %rdi, -0x128(%rbp)
movq -0x18(%rbp), %rsi
callq 0x20200
jmp 0x260f7
movq -0x138(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x148(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x20850
movq -0x140(%rbp), %rdx
leaq 0xb699(%rip), %rsi      # 0x317c0
leaq -0x60(%rbp), %rdi
callq 0x20640
jmp 0x26132
movq -0x10(%rbp), %rdx
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x20150
jmp 0x26145
movq -0x148(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x1fe20
jmp 0x2615c
leaq -0x60(%rbp), %rdi
callq 0x1ed60
leaq -0x61(%rbp), %rdi
callq 0x1f860
movq -0x138(%rbp), %rdi
addq $0x48, %rdi
movq %rdi, -0x150(%rbp)
callq 0x1f320
jmp 0x26187
movq -0x138(%rbp), %rdi
addq $0x68, %rdi
movq %rdi, -0x158(%rbp)
movl $0x64, %esi
callq 0x1e090
jmp 0x261a5
movq -0x138(%rbp), %rax
cmpl $0xa, 0x8(%rax)
jne 0x262cf
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x20850
movq -0x160(%rbp), %rdx
leaq 0xb5f4(%rip), %rsi      # 0x317cb
leaq -0xb0(%rbp), %rdi
callq 0x20640
jmp 0x261e5
movq -0x10(%rbp), %rdx
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x20730
jmp 0x261fe
movq -0x138(%rbp), %rdi
addq $0x18, %rdi
leaq -0x90(%rbp), %rsi
callq 0x202d0
jmp 0x26217
leaq -0xb0(%rbp), %rdi
callq 0x1ed60
leaq -0xb1(%rbp), %rdi
callq 0x1f860
jmp 0x262cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x264b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x26268
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x1ed60
leaq -0x61(%rbp), %rdi
callq 0x1f860
jmp 0x264a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x2649b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x2648f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x262be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x1ed60
leaq -0xb1(%rbp), %rdi
callq 0x1f860
jmp 0x26483
movq -0x138(%rbp), %rsi
movq %rsi, %rdi
addq $0xc, %rdi
addq $0x18, %rsi
callq 0x1eb80
jmp 0x262e8
movq -0x138(%rbp), %rdi
addq $0xc, %rdi
callq 0x1e990
movl %eax, -0x164(%rbp)
callq 0x1f1c0
movl -0x164(%rbp), %edi
movl %eax, %esi
callq 0x1f9d0
cmpl $-0x1, %eax
jne 0x26403
movb $0x1, -0xf9(%rbp)
movl $0x10, %edi
callq 0x1ea70
movq %rax, -0x170(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x1f040
jmp 0x2633f
leaq 0xb491(%rip), %rsi      # 0x317d7
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rdx
callq 0x20610
jmp 0x2635b
movq -0x170(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x204c0
jmp 0x26370
movq -0x170(%rbp), %rdi
movb $0x0, -0xf9(%rbp)
movq 0x14c6b(%rip), %rsi     # 0x3aff0
movq 0x14b9c(%rip), %rdx     # 0x3af28
callq 0x20690
jmp 0x264c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x26483
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x263e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x263db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x1ed60
leaq -0xf8(%rbp), %rdi
callq 0x1ed60
testb $0x1, -0xf9(%rbp)
jne 0x263f2
jmp 0x263fe
movq -0x170(%rbp), %rdi
callq 0x1efc0
jmp 0x26483
movq -0x138(%rbp), %rax
movq 0x14b27(%rip), %rcx     # 0x3af38
movq %rcx, -0x118(%rbp)
movq $0x0, -0x110(%rbp)
movq %rax, -0x120(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x118(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x1fff0
jmp 0x26446
movq -0x138(%rbp), %rdi
leaq -0x108(%rbp), %rsi
movq %rsi, -0x178(%rbp)
callq 0x20540
movq -0x178(%rbp), %rdi
callq 0x20330
movq -0x138(%rbp), %rdi
callq 0x207b0
jmp 0x2647a
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0x158(%rbp), %rdi
callq 0x1e5f0
movq -0x150(%rbp), %rdi
callq 0x1fb00
movq -0x148(%rbp), %rdi
callq 0x20700
movq -0x128(%rbp), %rdi
callq 0x1f7d0
movq -0x130(%rbp), %rdi
callq 0x20330
movq -0x20(%rbp), %rdi
callq 0x20840
nopl (%rax,%rax)