// File: /workspace/github_cpp_makefile_star2_O1/Unreality3D[P]Unreality3D/indie-studio/source/Network/sockets/Server.cpp
// Function: Socket::Server::start(int, unsigned long)
void  Server::start(int port, size_t maxClients)
	{
		SOCKADDR_IN	addr;
		PROTOENT	*proto;

		// port checking
		if (port <= 0 || port > 0xFFFF)
			throw SocketCreateError(std::string("server : bad port"));
		_port = port;
		_maxClients = maxClients;

		// create socket
		proto = getprotobyname("tcp");

		if ((_fd = socket(AF_INET, SOCK_STREAM, proto ? proto->p_proto : 0)) == -1)
		  throw SocketCreateError(std::string("server : ") +
		  		std::string(strerror(getError())));

		if (!setNonBloccking(_fd))
			throw SocketCreateError(std::string("server : ") +
									std::string("cannot set non blocking mode for the server fd"));

		// bind
		memset(&addr, 0, sizeof(addr));
		addr.sin_family = AF_INET;
		addr.sin_addr.s_addr = htonl(INADDR_ANY);
		addr.sin_port = htons(port);

		if (bind(_fd, (sockaddr *)(&addr), sizeof(addr)) == -1)
		  throw SocketConnectError("server : " + std::string(strerror(getError())));
		if (listen(_fd, _maxClients) == -1)
		  throw SocketConnectError("server : " + std::string(strerror(getError())));

		// create select() sets
		FD_ZERO(&_fd_set);
		_max_fd = _fd;
		FD_SET(_fd, &_fd_set);

		// run the event loop
		_isRunning = true;
		if (!_stateThread.joinable())
			_stateThread = std::thread(&Server::stateChecker, this);

		// start event
		if (_OnStart)
			_OnStart(*this, _port);
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movl %esi, %r14d
movl $0xffff0000, %eax       # imm = 0xFFFF0000
leal (%r14,%rax), %ecx
cmpl %eax, %ecx
jbe 0x13bcd
movq %rdi, %rbx
movl %r14d, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
leaq 0x1a87(%rip), %rdi      # 0x154c2
callq 0xb2e0
testq %rax, %rax
je 0x13a4a
movl 0x10(%rax), %edx
jmp 0x13a4c
xorl %edx, %edx
movl $0x2, %edi
movl $0x1, %esi
callq 0xb130
movl %eax, 0x18(%rbx)
cmpl $-0x1, %eax
je 0x13c28
movl %eax, %ebp
movl %eax, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0xb410
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0xb410
cmpl $-0x1, %eax
je 0x13cbb
xorps %xmm0, %xmm0
leaq 0xf0(%rsp), %rsi
movaps %xmm0, (%rsi)
movw $0x2, (%rsi)
movl $0x0, 0x4(%rsi)
rolw $0x8, %r14w
movw %r14w, 0x2(%rsi)
movl 0x18(%rbx), %edi
movl $0x10, %edx
callq 0xb0c0
cmpl $-0x1, %eax
je 0x13d52
movl 0x10(%rbx), %esi
movl 0x18(%rbx), %edi
callq 0xb850
cmpl $-0x1, %eax
je 0x13dc3
xorps %xmm0, %xmm0
movups %xmm0, 0x160(%rbx)
movups %xmm0, 0x150(%rbx)
movups %xmm0, 0x140(%rbx)
movups %xmm0, 0x130(%rbx)
movups %xmm0, 0x120(%rbx)
movups %xmm0, 0x110(%rbx)
movups %xmm0, 0x100(%rbx)
movups %xmm0, 0xf0(%rbx)
movl 0x18(%rbx), %ecx
movl %ecx, 0x170(%rbx)
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movl %eax, %edx
andl $-0x40, %edx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0xf0(%rbx,%rax,8)
movb $0x1, %al
xchgb %al, 0x174(%rbx)
cmpq $0x0, 0x38(%rbx)
jne 0x13b99
movq 0x7425(%rip), %rax      # 0x1af88
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq 0x48(%rsp), %rdx
movq %rbx, (%rdx)
leaq 0x28(%rsp), %rdi
callq 0xb100
cmpq $0x0, 0x38(%rbx)
jne 0x13e2c
movq 0x28(%rsp), %rax
movq %rax, 0x38(%rbx)
cmpq $0x0, 0xe0(%rbx)
je 0x13bbd
leaq 0xd0(%rbx), %rdi
movl 0x8(%rbx), %eax
leaq 0x8(%rsp), %rdx
movl %eax, (%rdx)
movq %rbx, %rsi
callq *0xe8(%rbx)
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1a32(%rip), %rsi      # 0x1561c
leaq 0x1a3c(%rip), %rdx      # 0x1562d
leaq 0x50(%rsp), %rdi
callq 0xb270
movb $0x1, %bpl
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0xb960
xorl %ebp, %ebp
movq 0x73bc(%rip), %rsi      # 0x1afd0
movq 0x7375(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x13e2c
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x19e9(%rip), %rsi      # 0x1562e
leaq 0x19eb(%rip), %rdx      # 0x15637
leaq 0x8(%rsp), %rdi
callq 0xb270
callq 0xb070
movl (%rax), %edi
callq 0xb1e0
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %rax, %rsi
callq 0xb290
leaq 0xd0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xb6b0
movb $0x1, %bpl
leaq 0xd0(%rsp), %rsi
movq %rbx, %rdi
callq 0xb960
xorl %ebp, %ebp
movq 0x7329(%rip), %rsi      # 0x1afd0
movq 0x72e2(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x13e2c
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1956(%rip), %rsi      # 0x1562e
leaq 0x1958(%rip), %rdx      # 0x15637
leaq 0x8(%rsp), %rdi
callq 0xb270
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x193e(%rip), %rsi      # 0x15638
leaq 0x1965(%rip), %rdx      # 0x15666
leaq 0x28(%rsp), %rdi
callq 0xb270
leaq 0xb0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xb6b0
movb $0x1, %bpl
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0xb960
xorl %ebp, %ebp
movq 0x7292(%rip), %rsi      # 0x1afd0
movq 0x724b(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x13e2c
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
callq 0xb070
movl (%rax), %edi
callq 0xb1e0
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rax, %rsi
callq 0xb290
leaq 0x18aa(%rip), %rsi      # 0x1562e
leaq 0x90(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xbc30
movb $0x1, %bpl
leaq 0x90(%rsp), %rsi
movq %rbx, %rdi
callq 0xb830
xorl %ebp, %ebp
movq 0x71b6(%rip), %rsi      # 0x1af68
movq 0x71d7(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x13e2c
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
callq 0xb070
movl (%rax), %edi
callq 0xb1e0
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rax, %rsi
callq 0xb290
leaq 0x1839(%rip), %rsi      # 0x1562e
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xbc30
movb $0x1, %bpl
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0xb830
xorl %ebp, %ebp
movq 0x714b(%rip), %rsi      # 0x1af68
movq 0x716c(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
callq 0xb160
movq %rax, %r14
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13e52
callq 0xb730
jmp 0x13e52
movq %rax, %r14
movb $0x1, %bpl
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
jne 0x13e8d
jmp 0x13edc
movq %rax, %r14
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13e7f
callq 0xb730
jmp 0x13e7f
movq %rax, %r14
movb $0x1, %bpl
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13edc
callq 0xb730
jmp 0x13edc
movq %rax, %r14
leaq 0x80(%rsp), %rax
jmp 0x13eae
jmp 0x13ebe
movq %rax, %r14
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13ec4
callq 0xb730
jmp 0x13ec4
movq %rax, %r14
movb $0x1, %bpl
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x13ef8
jmp 0x13f05
jmp 0x13ed6
movq %rax, %r14
movb $0x1, %bpl
movq 0x8(%rsp), %rdi
jmp 0x13ef3
jmp 0x13eff
jmp 0x13eff
jmp 0x13eff
jmp 0x13eff
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x13f05
callq 0xb730
jmp 0x13f05
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x13f12
movq %rbx, %rdi
callq 0xb5b0
movq %r14, %rdi
callq 0xbce0