// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x108, %rsp            # imm = 0x108
movl %esi, %r14d
movl $0xffff0000, %eax       # imm = 0xFFFF0000
leal (%r14,%rax), %ecx
cmpl %eax, %ecx
jbe 0x1686d
movq %rdi, %rbx
movl %r14d, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
leaq 0x1d47(%rip), %rdi      # 0x18482
callq 0xf420
testq %rax, %rax
je 0x1674a
movl 0x10(%rax), %edx
jmp 0x1674c
xorl %edx, %edx
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
callq 0xf1e0
movl %eax, 0x18(%rbx)
cmpl $-0x1, %eax
je 0x168c1
movl %eax, %edi
callq 0x16b2b
testb %al, %al
je 0x16947
leaq 0xf8(%rsp), %rsi
andq $0x0, 0x8(%rsi)
movw $0x2, (%rsi)
andl $0x0, 0x4(%rsi)
rolw $0x8, %r14w
movw %r14w, 0x2(%rsi)
movl 0x18(%rbx), %edi
pushq $0x10
popq %rdx
callq 0xf0e0
cmpl $-0x1, %eax
je 0x169c5
movl 0x10(%rbx), %esi
movl 0x18(%rbx), %edi
callq 0xfbf0
cmpl $-0x1, %eax
je 0x16a2e
pushq $0x1e
popq %rax
cmpq $0x2e, %rax
je 0x167cd
andq $0x0, (%rbx,%rax,8)
incq %rax
jmp 0x167bd
movl 0x18(%rbx), %ecx
movl %ecx, 0x170(%rbx)
pushq $0x40
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
movslq %eax, %rdx
shll $0x6, %eax
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, 0xf0(%rbx,%rdx,8)
movb $0x1, %al
xchgb %al, 0x174(%rbx)
cmpq $0x0, 0x38(%rbx)
jne 0x16843
movq 0x877e(%rip), %rax      # 0x1ef88
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
leaq 0x38(%rbx), %r14
leaq 0x30(%rsp), %rdx
movq %rbx, (%rdx)
leaq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0xf170
movq %r14, %rdi
movq %r15, %rsi
callq 0x101a0
movq %r15, %rdi
callq 0x10040
cmpq $0x0, 0xe0(%rbx)
je 0x1685f
leaq 0xd0(%rbx), %rdi
movl 0x8(%rbx), %edx
movq %rbx, %rsi
callq 0xfbc0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
leaq 0x1d5d(%rip), %rsi      # 0x185dc
leaq 0xd8(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0xf3f0
movb $0x1, %bpl
leaq 0xd8(%rsp), %rsi
movq %rbx, %rdi
callq 0xfd80
xorl %ebp, %ebp
movq 0x8723(%rip), %rsi      # 0x1efd0
movq 0x86dc(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
jmp 0x16a95
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
leaq 0x1d1b(%rip), %rsi      # 0x185ee
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xf3f0
callq 0x16b21
movl %eax, %edi
callq 0xf330
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %rax, %rsi
callq 0xf3f0
leaq 0xb8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0xf9a0
movb $0x1, %bpl
leaq 0xb8(%rsp), %rsi
movq %rbx, %rdi
callq 0xfd80
xorl %ebp, %ebp
movq 0x869d(%rip), %rsi      # 0x1efd0
movq 0x8656(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
jmp 0x16a95
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
leaq 0x1c95(%rip), %rsi      # 0x185ee
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xf3f0
leaq 0x1c89(%rip), %rsi      # 0x185f8
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0xf3f0
leaq 0x98(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0xf9a0
movb $0x1, %bpl
leaq 0x98(%rsp), %rsi
movq %rbx, %rdi
callq 0xfd80
xorl %ebp, %ebp
movq 0x861f(%rip), %rsi      # 0x1efd0
movq 0x85d8(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
jmp 0x16a95
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
callq 0x16b21
movl %eax, %edi
callq 0xf330
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
movq %rax, %rsi
callq 0xf3f0
leaq 0x1bf9(%rip), %rsi      # 0x185ee
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x10210
movb $0x1, %bpl
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0xfb90
xorl %ebp, %ebp
movq 0x854b(%rip), %rsi      # 0x1ef68
movq 0x856c(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
jmp 0x16a95
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
callq 0x16b21
movl %eax, %edi
callq 0xf330
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
movq %rax, %rsi
callq 0xf3f0
leaq 0x1b90(%rip), %rsi      # 0x185ee
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x10210
movb $0x1, %bpl
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0xfb90
xorl %ebp, %ebp
movq 0x84e2(%rip), %rsi      # 0x1ef68
movq 0x8503(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
movq %rax, %r14
leaq 0x98(%rsp), %rdi
jmp 0x16aaf
jmp 0x16ab6
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0xf450
jmp 0x16abc
movq %rax, %r14
movb $0x1, %bpl
leaq 0x38(%rsp), %rdi
jmp 0x16ad7
movq %rax, %r14
leaq 0x58(%rsp), %rdi
jmp 0x16ad7
jmp 0x16ae2
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0xf450
jmp 0x16ae8
jmp 0x16ae2
jmp 0x16ae2
movq %rax, %r14
movb $0x1, %bpl
leaq 0x10(%rsp), %rdi
jmp 0x16b02
jmp 0x16b0e
jmp 0x16b0e
jmp 0x16b0e
jmp 0x16b0e
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0xf450
testb %bpl, %bpl
jne 0x16b11
jmp 0x16b19
movq %rax, %r14
movq %rbx, %rdi
callq 0xf820
movq %r14, %rdi
callq 0x102f0