// File: /workspace/github_cpp_makefile_star2_O3/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 0xbdc0
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 0xbdde
leaq -0xb8(%rbp), %rsi
movq $0x0, 0x8(%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 0xbdfc
movl 0x4(%rbx), %esi
movl 0x8(%rbx), %edi
callq 0x4430
movslq (%rbx), %rsi
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x136be
leaq 0x9923(%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 0xbcb0
movq %rdx, -0x60(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x50(%rbp)
jmp 0xbcb7
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 0x98ce(%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 0xbd02
movq %rdx, -0x40(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x30(%rbp)
jmp 0xbd09
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 0x99d1(%rip), %rdx      # 0x15701
leaq -0x88(%rbp), %rdi
movq %rdx, %rsi
callq 0x5796
leaq -0x40(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x13da7
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xbd67
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xbd7c
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0xbd91
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xbdb0
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 0x9758(%rip), %rsi      # 0x1552c
movq %rax, %rdi
callq 0x41b0
jmp 0xbe18
movl $0x10, %edi
callq 0x41f0
movq %rax, %r14
leaq 0x975f(%rip), %rsi      # 0x15551
movq %rax, %rdi
callq 0x41b0
jmp 0xbe18
movl $0x10, %edi
callq 0x41f0
movq %rax, %r14
leaq 0x976a(%rip), %rsi      # 0x1557a
movq %rax, %rdi
callq 0x41b0
movq 0x111c9(%rip), %rsi     # 0x1cfe8
movq 0x11192(%rip), %rdx     # 0x1cfb8
movq %r14, %rdi
callq 0x46a0
jmp 0xbe32
jmp 0xbe32
movq %rax, %rbx
movq %r14, %rdi
callq 0x42e0
jmp 0xbeb2
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xbe5f
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xbe5f
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0xbe79
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xbe79
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0xbe93
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xbe93
movq %rax, %rbx
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xbeb2
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %rbx, %rdi
callq 0x46d0
nop