// File: /workspace/github_cpp_makefile_star2_O3/llefranc[P]42_webserv/srcs/server/HttpServer.cpp
// Function: HttpServer::requestHandler()
void HttpServer::requestHandler()
{
	for (std::list<ClientSocket>::iterator it = _clientSocks.begin(); it != _clientSocks.end() && _nbReadyFds; ++it)
	{
		if (FD_ISSET(it->getFd(), &_readFds))
		{
			char buffer[REQUEST_BUFFER_SIZE + 1];
			bzero(buffer, REQUEST_BUFFER_SIZE + 1);
			int n = recv(it->getFd(), buffer, REQUEST_BUFFER_SIZE, 0);

			if (n < 0)
            {
                printLog(" >> FD " + convertNbToString(it->getFd()) + ": Error on recv function, connection closed\n");
                std::list<ClientSocket>::iterator tmp = it--;
                closeConnection(&tmp);
            }

			// Client closed the connection
			else if (!n)
			{
				printLog(" >> FD " + convertNbToString(it->getFd()) + ": recv function returned 0, connection closed\n");
                std::list<ClientSocket>::iterator tmp = it--;
                closeConnection(&tmp);
			}

			// Concatenate buffer to actual stored request
            else
                it->receiveRequest(buffer);
	
			// Exit for loop if no other sockets are ready
			--_nbReadyFds;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x898, %rsp            # imm = 0x898
leaq 0x18(%rdi), %rax
movq 0x18(%rdi), %r15
movq %rax, -0x90(%rbp)
cmpq %rax, %r15
je 0xb653
movq %rdi, %rbx
leaq -0x58(%rbp), %r14
movq %rdi, -0xb8(%rbp)
cmpl $0x0, 0x130(%rbx)
je 0xb653
leaq 0x10(%r15), %r13
movq %r13, %rdi
callq 0xc01e
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
movq 0x30(%rbx,%rax,8), %r12
movq %r13, %rdi
callq 0xc01e
btq %rax, %r12
jae 0xb3b1
movl $0x7ff, %edx            # imm = 0x7FF
leaq -0x8c0(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x4250
movq %r13, %rdi
callq 0xc01e
movl $0x7fe, %edx            # imm = 0x7FE
movl %eax, %edi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x4170
testl %eax, %eax
leaq -0x38(%rbp), %r12
js 0xb3bd
je 0xb410
movq %r13, %rdi
leaq -0x8c0(%rbp), %rsi
callq 0xc04c
jmp 0xb636
movq -0xb8(%rbp), %rbx
jmp 0xb643
movq %r13, %rdi
callq 0xc01e
movslq %eax, %rsi
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
callq 0x136be
movl $0x7, %r8d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0xa019(%rip), %rcx      # 0x15404
callq 0x4440
movq %r12, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xb46a
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0xb472
movq %r13, %rdi
callq 0xc01e
movslq %eax, %rsi
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
callq 0x136be
movl $0x7, %r8d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x9fc6(%rip), %rcx      # 0x15404
callq 0x4440
movq %r12, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xb50c
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0xb514
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x48(%rbp), %rdi
leaq 0x9feb(%rip), %rsi      # 0x1547f
callq 0x4760
movq %r14, -0x68(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq -0x88(%rbp), %rbx
je 0xb4c0
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0xb4c7
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq %rbx, %rdi
leaq 0xa20e(%rip), %rdx      # 0x15701
movq %rdx, %rsi
callq 0x5796
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x13da7
jmp 0xb5a9
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x48(%rbp), %rdi
leaq 0x9f76(%rip), %rsi      # 0x154ac
callq 0x4760
movq %r14, -0x68(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq -0x88(%rbp), %rbx
je 0xb562
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0xb569
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq %rbx, %rdi
leaq 0xa16c(%rip), %rdx      # 0x15701
movq %rdx, %rsi
callq 0x5796
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x13da7
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xb5c5
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0xb5da
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xb5ef
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0xb611
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x43e0
movq 0x8(%r15), %r12
movq %r13, %rdi
callq 0xc01e
movl %eax, %edi
callq 0x4780
movq -0x90(%rbp), %rdi
movq %r15, %rsi
callq 0xbafe
movq %r12, %r15
movq -0xb8(%rbp), %rbx
decl 0x130(%rbx)
movq (%r15), %r15
cmpq -0x90(%rbp), %r15
jne 0xb32a
addq $0x898, %rsp            # imm = 0x898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb66d
jmp 0xb68e
jmp 0xb6a8
jmp 0xb6c6
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xb691
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xb691
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0xb6ab
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xb6ab
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xb6c9
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xb6c9
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0xb6eb
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %rbx, %rdi
callq 0x46d0
nop