// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdi, %rbx
leaq 0x18(%rdi), %r15
movq %r15, -0x38(%rbp)
movq (%r15), %r15
cmpq -0x38(%rbp), %r15
je 0xa16f
cmpl $0x0, 0x130(%rbx)
je 0xa16f
leaq 0x10(%r15), %r13
movq %r13, %rdi
callq 0xac4c
cltd
pushq $0x40
popq %r12
idivl %r12d
cltq
movq 0x30(%rbx,%rax,8), %r14
movq %r13, %rdi
callq 0xac4c
cltd
idivl %r12d
btq %rdx, %r14
jae 0x9fcb
movl $0x7ff, %edx            # imm = 0x7FF
leaq -0x8c0(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4280
movq %r13, %rdi
callq 0xac4c
movl $0x7fe, %edx            # imm = 0x7FE
movl %eax, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x4190
movq %r13, %rdi
testl %eax, %eax
js 0xa05b
je 0xa0c5
leaq -0x8c0(%rbp), %rsi
callq 0xac7a
jmp 0xa164
callq 0xac4c
movslq %eax, %rsi
leaq -0x58(%rbp), %r14
movq %r14, %rdi
callq 0xfc62
leaq -0xb8(%rbp), %r12
movq %r12, %rdi
leaq 0x737d(%rip), %rsi      # 0x113fd
movq %r14, %rdx
callq 0x4f60
leaq -0x78(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
leaq 0x73df(%rip), %rdx      # 0x11478
callq 0x4f37
leaq -0x98(%rbp), %r14
movq %r14, %rdi
leaq 0x764b(%rip), %rsi      # 0x116fa
leaq -0x29(%rbp), %rdx
callq 0x4ec8
movq %r13, %rdi
movq %r14, %rsi
callq 0x10271
jmp 0xa12d
callq 0xac4c
movslq %eax, %rsi
leaq -0x58(%rbp), %r14
movq %r14, %rdi
callq 0xfc62
leaq -0xb8(%rbp), %r12
movq %r12, %rdi
leaq 0x7313(%rip), %rsi      # 0x113fd
movq %r14, %rdx
callq 0x4f60
leaq -0x78(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
leaq 0x73a2(%rip), %rdx      # 0x114a5
callq 0x4f37
leaq -0x98(%rbp), %r14
movq %r14, %rdi
leaq 0x75e1(%rip), %rsi      # 0x116fa
leaq -0x29(%rbp), %rdx
callq 0x4ec8
movq %r13, %rdi
movq %r14, %rsi
callq 0x10271
movq %r14, %rdi
callq 0x47d8
movq %r13, %rdi
callq 0x47d8
movq %r12, %rdi
callq 0x47d8
leaq -0x58(%rbp), %rdi
callq 0x47d8
movq 0x8(%r15), %r14
movq %r15, -0x78(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xa1ce
movq %r14, %r15
decl 0x130(%rbx)
jmp 0x9fcb
addq $0x898, %rsp            # imm = 0x898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa189
jmp 0xa19a
jmp 0xa1a8
jmp 0xa1b9
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x47d8
jmp 0xa19d
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x47d8
jmp 0xa1ab
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x47d8
jmp 0xa1bc
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x47d8
movq %rbx, %rdi
callq 0x46d0
nop