// File: /workspace/github_cpp_makefile_star2_O1/llefranc[P]42_webserv/srcs/server/ServerSocket.cpp
// Function: ServerSocket::createSocket()
void ServerSocket::createSocket()
{
	// Creating a TCP socket
	if ((_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
		throw std::runtime_error("Fatal error: socket function failed\n");

	// Setting its options
	int yes = true;
	if (setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1)
		throw std::runtime_error("Fatal error: setsockopt function failed\n");
	
	// Initializing structure for socket information (IP, port..)
	struct sockaddr_in socketAddr;
	bzero((char *) &socketAddr, sizeof(socketAddr));
	socketAddr.sin_family = AF_INET;
	socketAddr.sin_addr.s_addr = INADDR_ANY;
	socketAddr.sin_port = htons(_port);
	
	// Binding the socket to a port
	if (bind(_fd, (struct sockaddr *) &socketAddr, sizeof(socketAddr)) < 0)
		throw std::runtime_error("Fatal error: bind function failed\n");

	listen(_fd, _maxClient);
	printLog(" >> PORT " + convertNbToString(_port) + ": HTTP socket created\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rdi, %rbx
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x40f0
movl %eax, 0x8(%rbx)
testl %eax, %eax
js 0xbd82
leaq -0x64(%rbp), %rcx
movl $0x1, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x46e0
cmpl $-0x1, %eax
je 0xbda0
xorps %xmm0, %xmm0
leaq -0xc0(%rbp), %rsi
movaps %xmm0, (%rsi)
movw $0x2, (%rsi)
movl $0x0, 0x4(%rsi)
movzwl (%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rsi)
movl 0x8(%rbx), %edi
movl $0x10, %edx
callq 0x4090
testl %eax, %eax
js 0xbdbe
movl 0x4(%rbx), %esi
movl 0x8(%rbx), %edi
callq 0x4430
movslq (%rbx), %rsi
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x1378a
leaq 0x9961(%rip), %rcx      # 0x1559d
movl $0x9, %r8d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4440
leaq -0x50(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xbc72
movq %rdx, -0x60(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x50(%rbp)
jmp 0xbc79
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x60(%rbp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x990c(%rip), %rsi      # 0x155a7
callq 0x4760
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xbcc4
movq %rdx, -0x40(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x30(%rbp)
jmp 0xbccb
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, -0x38(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x78(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x9a0f(%rip), %rdx      # 0x15701
leaq -0x88(%rbp), %rdi
movq %rdx, %rsi
callq 0x5790
leaq -0x40(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x13ed0
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xbd29
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xbd3e
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0xbd53
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xbd72
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x43e0
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x41f0
movq %rax, %r14
leaq 0x9796(%rip), %rsi      # 0x1552c
movq %rax, %rdi
callq 0x41b0
jmp 0xbdda
movl $0x10, %edi
callq 0x41f0
movq %rax, %r14
leaq 0x979d(%rip), %rsi      # 0x15551
movq %rax, %rdi
callq 0x41b0
jmp 0xbdda
movl $0x10, %edi
callq 0x41f0
movq %rax, %r14
leaq 0x97a8(%rip), %rsi      # 0x1557a
movq %rax, %rdi
callq 0x41b0
movq 0x11207(%rip), %rsi     # 0x1cfe8
movq 0x111d0(%rip), %rdx     # 0x1cfb8
movq %r14, %rdi
callq 0x46a0
jmp 0xbdf4
jmp 0xbdf4
movq %rax, %rbx
movq %r14, %rdi
callq 0x42e0
jmp 0xbe74
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xbe21
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xbe21
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xbe3b
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xbe3b
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0xbe55
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xbe55
movq %rax, %rbx
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xbe74
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %rbx, %rdi
callq 0x46d0