// File: 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
subq $0x990, %rsp            # imm = 0x990
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x960(%rbp)
addq $0x18, %rdi
callq 0x14660
movq %rax, -0x10(%rbp)
movq -0x960(%rbp), %rdi
addq $0x18, %rdi
callq 0x146c0
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x14690
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x961(%rbp)
jne 0x13c99
jmp 0x13cb0
movq -0x960(%rbp), %rax
cmpl $0x0, 0x130(%rax)
setne %al
movb %al, -0x961(%rbp)
movb -0x961(%rbp), %al
testb $0x1, %al
jne 0x13cbf
jmp 0x140f0
leaq -0x10(%rbp), %rdi
callq 0x146f0
movq %rax, %rdi
callq 0x168f0
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x960(%rbp), %rax
movslq %ecx, %rcx
movq 0x30(%rax,%rcx,8), %rax
movq %rax, -0x970(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x146f0
movq %rax, %rdi
callq 0x168f0
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x970(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x140e0
leaq -0x820(%rbp), %rdi
xorl %esi, %esi
movl $0x7ff, %edx            # imm = 0x7FF
callq 0x52e0
leaq -0x10(%rbp), %rdi
callq 0x146f0
movq %rax, %rdi
callq 0x168f0
movl %eax, %edi
leaq -0x820(%rbp), %rsi
movl $0x7fe, %edx            # imm = 0x7FE
xorl %ecx, %ecx
callq 0x51d0
movl %eax, -0x824(%rbp)
cmpl $0x0, -0x824(%rbp)
jge 0x13f0e
leaq -0x10(%rbp), %rdi
callq 0x146f0
movq %rax, %rdi
callq 0x168f0
movslq %eax, %rsi
leaq -0x888(%rbp), %rdi
movq %rdi, -0x978(%rbp)
callq 0x20c10
movq -0x978(%rbp), %rdx
leaq 0xf664(%rip), %rsi      # 0x2340f
leaq -0x868(%rbp), %rdi
callq 0x6700
jmp 0x13db9
leaq 0xf6ca(%rip), %rdx      # 0x2348a
leaq -0x848(%rbp), %rdi
leaq -0x868(%rbp), %rsi
callq 0x66b0
jmp 0x13dd5
leaq -0x8b9(%rbp), %rdi
movq %rdi, -0x980(%rbp)
callq 0x58f0
movq -0x980(%rbp), %rdx
leaq 0xf916(%rip), %rsi      # 0x2370c
leaq -0x8b8(%rbp), %rdi
callq 0x63e0
jmp 0x13e04
leaq -0x848(%rbp), %rdi
leaq -0x8b8(%rbp), %rsi
callq 0x21750
jmp 0x13e19
leaq -0x8b8(%rbp), %rdi
callq 0x5a08
leaq -0x8b9(%rbp), %rdi
callq 0x55c0
leaq -0x848(%rbp), %rdi
callq 0x5a08
leaq -0x868(%rbp), %rdi
callq 0x5a08
leaq -0x888(%rbp), %rdi
callq 0x5a08
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x147e0
movq -0x960(%rbp), %rdi
movq %rax, -0x8c8(%rbp)
leaq -0x8c8(%rbp), %rsi
callq 0x14110
jmp 0x140ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x890(%rbp)
movl %eax, -0x894(%rbp)
jmp 0x13efd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x890(%rbp)
movl %eax, -0x894(%rbp)
jmp 0x13ef1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x890(%rbp)
movl %eax, -0x894(%rbp)
jmp 0x13ed9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x890(%rbp)
movl %eax, -0x894(%rbp)
leaq -0x8b8(%rbp), %rdi
callq 0x5a08
leaq -0x8b9(%rbp), %rdi
callq 0x55c0
leaq -0x848(%rbp), %rdi
callq 0x5a08
leaq -0x868(%rbp), %rdi
callq 0x5a08
leaq -0x888(%rbp), %rdi
callq 0x5a08
jmp 0x140f9
cmpl $0x0, -0x824(%rbp)
jne 0x140b0
leaq -0x10(%rbp), %rdi
callq 0x146f0
movq %rax, %rdi
callq 0x168f0
movslq %eax, %rsi
leaq -0x928(%rbp), %rdi
movq %rdi, -0x988(%rbp)
callq 0x20c10
movq -0x988(%rbp), %rdx
leaq 0xf4bf(%rip), %rsi      # 0x2340f
leaq -0x908(%rbp), %rdi
callq 0x6700
jmp 0x13f5e
leaq 0xf552(%rip), %rdx      # 0x234b7
leaq -0x8e8(%rbp), %rdi
leaq -0x908(%rbp), %rsi
callq 0x66b0
jmp 0x13f7a
leaq -0x949(%rbp), %rdi
movq %rdi, -0x990(%rbp)
callq 0x58f0
movq -0x990(%rbp), %rdx
leaq 0xf771(%rip), %rsi      # 0x2370c
leaq -0x948(%rbp), %rdi
callq 0x63e0
jmp 0x13fa9
leaq -0x8e8(%rbp), %rdi
leaq -0x948(%rbp), %rsi
callq 0x21750
jmp 0x13fbe
leaq -0x948(%rbp), %rdi
callq 0x5a08
leaq -0x949(%rbp), %rdi
callq 0x55c0
leaq -0x8e8(%rbp), %rdi
callq 0x5a08
leaq -0x908(%rbp), %rdi
callq 0x5a08
leaq -0x928(%rbp), %rdi
callq 0x5a08
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x147e0
movq -0x960(%rbp), %rdi
movq %rax, -0x958(%rbp)
leaq -0x958(%rbp), %rsi
callq 0x14110
jmp 0x140c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x890(%rbp)
movl %eax, -0x894(%rbp)
jmp 0x140a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x890(%rbp)
movl %eax, -0x894(%rbp)
jmp 0x14096
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x890(%rbp)
movl %eax, -0x894(%rbp)
jmp 0x1407e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x890(%rbp)
movl %eax, -0x894(%rbp)
leaq -0x948(%rbp), %rdi
callq 0x5a08
leaq -0x949(%rbp), %rdi
callq 0x55c0
leaq -0x8e8(%rbp), %rdi
callq 0x5a08
leaq -0x908(%rbp), %rdi
callq 0x5a08
leaq -0x928(%rbp), %rdi
callq 0x5a08
jmp 0x140f9
leaq -0x10(%rbp), %rdi
callq 0x146f0
movq %rax, %rdi
leaq -0x820(%rbp), %rsi
callq 0x16960
jmp 0x140ca
movq -0x960(%rbp), %rax
movl 0x130(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x130(%rax)
jmp 0x140e2
leaq -0x10(%rbp), %rdi
callq 0x14810
jmp 0x13c67
addq $0x990, %rsp            # imm = 0x990
popq %rbp
retq
movq -0x890(%rbp), %rdi
callq 0x58e0
nopw %cs:(%rax,%rax)