// File: /workspace/github_cpp_makefile_star2_O3/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 0x139d3
movq %rdi, %rbx
movl %r14d, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
leaq 0x1c83(%rip), %rdi      # 0x154c2
callq 0xb2e0
testq %rax, %rax
je 0x1384e
movl 0x10(%rax), %edx
jmp 0x13850
xorl %edx, %edx
movl $0x2, %edi
movl $0x1, %esi
callq 0xb130
movl %eax, 0x18(%rbx)
cmpl $-0x1, %eax
je 0x13a2e
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 0x13ac1
leaq 0xf0(%rsp), %rsi
movq $0x0, 0x8(%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 0x13b58
movl 0x10(%rbx), %esi
movl 0x18(%rbx), %edi
callq 0xb850
cmpl $-0x1, %eax
je 0x13bc9
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 0x1399f
movq 0x761f(%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 0x13c32
movq 0x28(%rsp), %rax
movq %rax, 0x38(%rbx)
cmpq $0x0, 0xe0(%rbx)
je 0x139c3
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 0x1c2c(%rip), %rsi      # 0x1561c
leaq 0x1c36(%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 0x75b6(%rip), %rsi      # 0x1afd0
movq 0x756f(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x13c32
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1be3(%rip), %rsi      # 0x1562e
leaq 0x1be5(%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 0x7523(%rip), %rsi      # 0x1afd0
movq 0x74dc(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x13c32
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1b50(%rip), %rsi      # 0x1562e
leaq 0x1b52(%rip), %rdx      # 0x15637
leaq 0x8(%rsp), %rdi
callq 0xb270
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1b38(%rip), %rsi      # 0x15638
leaq 0x1b5f(%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 0x748c(%rip), %rsi      # 0x1afd0
movq 0x7445(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x13c32
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 0x1aa4(%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 0x73b0(%rip), %rsi      # 0x1af68
movq 0x73d1(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x13c32
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 0x1a33(%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 0x7345(%rip), %rsi      # 0x1af68
movq 0x7366(%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 0x13c58
callq 0xb730
jmp 0x13c58
movq %rax, %r14
movb $0x1, %bpl
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
jne 0x13c93
jmp 0x13c98
movq %rax, %r14
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13c85
callq 0xb730
jmp 0x13c85
movq %rax, %r14
movb $0x1, %bpl
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13c98
callq 0xb730
movq 0x8(%rsp), %rdi
jmp 0x13d10
movq %rax, %r14
leaq 0x80(%rsp), %rax
jmp 0x13cb9
jmp 0x13cd7
movq %rax, %r14
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13cc7
callq 0xb730
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x13d15
jmp 0x13d1a
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x13cf9
jmp 0x13d24
jmp 0x13cec
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x13d24
callq 0xb730
jmp 0x13d24
jmp 0x13d21
jmp 0x13d21
jmp 0x13d21
jmp 0x13d21
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x13d1a
callq 0xb730
testb %bpl, %bpl
jne 0x13d24
jmp 0x13d2c
movq %rax, %r14
movq %rbx, %rdi
callq 0xb5b0
movq %r14, %rdi
callq 0xbce0