// File: /workspace/github_cpp_makefile_star2_O2/Neuromancer2701[P]OpenTool/lib/sockets/Server.cpp
// Function: Server::Available()
int Server::Available() {

	Client client;

	if(error_state == Error::NONE)
	{
		int epoll_events = epoll_wait (event_fd, events, MAX_EVENTS, -1);
		DEBUG("Epoll events, %d\n ",epoll_events);

		for (int i = 0; i < epoll_events; i++)
		{
			if((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN ))) /*Epoll error occured*/
			{
			  perror("epoll wait error\n");
			  error_state = Error::EPOLL_WAIT;
			  close (events[i].data.fd);

			}
			else if(server_fd == events[i].data.fd)
			{
				if(active_connections >= MAX_CONNECTIONS)
				{
					break;
				}

				while (error_state != Error::ACCEPT_DONE)
				{
					error_state = client_list[active_connections].Accept(server_fd);
					if(error_state == Error::NONE)
					{
						AddClientToEvent(client_list[active_connections]);
						active_connections++;
					}
				}
				error_state = Error::NONE;
			}
			else if(isClient(events[i].data.fd, client))
			{
				client.Read(read_buffer);
			}
			else
			{
				perror ("Unknown epoll event");
				error_state = Error::EPOLL_UNKNOWN;
			}
		}
	}
	else
	{
	  perror ("Setup did not work so can't wait for a connection.");
	}

	DEBUG("Active Connections:%d and Error State:%d\n", active_connections, error_state);
	return active_connections;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
leaq -0x88(%rbp), %rdi
callq 0x6390
cmpl $0x2, 0x1b4(%rbx)
jne 0x9a5f
movl 0x1b8(%rbx), %edi
leaq 0x1c8(%rbx), %rsi
pushq $0x10
popq %rdx
pushq $-0x1
popq %rcx
movq %rsi, -0x40(%rbp)
callq 0x6220
movl %eax, %r14d
leaq 0xa3e(%rip), %rdi       # 0xa366
xorl %r12d, %r12d
movl %eax, %esi
xorl %eax, %eax
callq 0x6050
leaq 0x190(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x10(%rbx), %r15
testl %r14d, %r14d
cmovlel %r12d, %r14d
leaq -0xc8(%rbp), %r13
movq %r14, -0x30(%rbp)
cmpq %r14, %r12
je 0x9a6b
movq %r12, -0x48(%rbp)
imulq $0xc, %r12, %rax
movq -0x40(%rbp), %rcx
leaq (%rcx,%rax), %r14
movl (%rcx,%rax), %eax
andl $0x19, %eax
cmpl $0x1, %eax
jne 0x9a2a
movl 0x4(%r14), %esi
cmpl %esi, 0x1a8(%rbx)
jne 0x99ec
cmpl $0x5, 0x8(%rbx)
movq -0x30(%rbp), %r14
jg 0x9a6b
cmpl $0x10, 0x1b4(%rbx)
je 0x9a15
movslq 0x8(%rbx), %rdi
shlq $0x6, %rdi
addq %r15, %rdi
movl 0x1a8(%rbx), %esi
callq 0x6780
movl %eax, 0x1b4(%rbx)
cmpl $0x2, %eax
jne 0x9997
movslq 0x8(%rbx), %rsi
shlq $0x6, %rsi
addq %r15, %rsi
movq %r13, %rdi
callq 0x6080
movq %rbx, %rdi
movq %r13, %rsi
callq 0x65c0
movq %r13, %rdi
callq 0x60f0
incl 0x8(%rbx)
jmp 0x9997
movq %rbx, %rdi
leaq -0x88(%rbp), %rdx
callq 0x63e0
movq -0x30(%rbp), %r14
testb %al, %al
je 0x9a4f
leaq -0x88(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x6250
jmp 0x9a1e
pushq $0x2
popq %rax
movl %eax, 0x1b4(%rbx)
movq -0x48(%rbp), %r12
incq %r12
jmp 0x9955
leaq 0x878(%rip), %rdi       # 0xa2a9
callq 0x63c0
movl $0xd, 0x1b4(%rbx)
movl 0x4(%r14), %edi
callq 0x6810
movq -0x30(%rbp), %r14
jmp 0x9a1e
leaq 0x923(%rip), %rdi       # 0xa379
callq 0x63c0
pushq $0xe
jmp 0x9a17
leaq 0x927(%rip), %rdi       # 0xa38d
callq 0x63c0
movl 0x8(%rbx), %esi
movl 0x1b4(%rbx), %edx
leaq 0x945(%rip), %rdi       # 0xa3c0
xorl %eax, %eax
callq 0x6050
movl 0x8(%rbx), %ebx
leaq -0x88(%rbp), %rdi
callq 0x60f0
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9aa9
jmp 0x9aa9
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x60f0
movq %rbx, %rdi
callq 0x6740