// File: metopa[P]HTTP_Server/src/network/CPortObtainer.cpp
// Function: CPortObtainer::CSocketWrapper::CSocketWrapper(addrinfo*, char const*)
CPortObtainer::CSocketWrapper::CSocketWrapper( addrinfo * servinfo, const char * port ) {
	int yes = 1;

	for ( addrinfo * it = servinfo; it != nullptr; it = it->ai_next ) {
		if ( ( sockfd_m = socket( it->ai_family, it->ai_socktype, it->ai_protocol ) ) == -1 ) {
			Log.ger<>( DEBUG_NETWORK, port, "socket() returned error:", strerror( errno ) );
			continue;
		}

		if ( setsockopt( sockfd_m, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof( int ) ) == -1 ) {
			throw PortInitializationException( "setsockopt()", strerror( errno ), port, sockfd_m );
		}

		if ( bind( sockfd_m, it->ai_addr, it->ai_addrlen ) == -1 ) {
			close( sockfd_m );
			sockfd_m = -1;
			Log.ger<>( DEBUG_NETWORK, "Function bind() returned error on port", port, strerror( errno ) );
			continue;
		}
		break;
	}

	if ( sockfd_m == -1 )
		throw PortInitializationException( "socket()", "Function failed on all addrinfo structures", port );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x1, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2484a
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x28(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x6150
movq -0xf0(%rbp), %rcx
movl %eax, (%rcx)
cmpl $-0x1, %eax
jne 0x24659
callq 0x6080
movl (%rax), %edi
callq 0x61f0
movq %rax, -0x30(%rbp)
leaq 0x1b0a5(%rip), %rdi     # 0x3f6e0
movl $0x5, %esi
leaq -0x18(%rbp), %rdx
leaq 0x8416(%rip), %rcx      # 0x2ca61
leaq -0x30(%rbp), %r8
callq 0x24c90
jmp 0x24839
movq -0xf0(%rbp), %rax
movl (%rax), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x1c(%rbp), %rcx
movl $0x4, %r8d
callq 0x6940
cmpl $-0x1, %eax
jne 0x247c2
movb $0x1, -0x8a(%rbp)
movl $0x50, %edi
callq 0x6280
movq %rax, -0x100(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x6930
movq -0xf8(%rbp), %rdx
leaq 0x83c0(%rip), %rsi      # 0x2ca7a
leaq -0x50(%rbp), %rdi
callq 0xa9d0
jmp 0x246c5
callq 0x6080
movl (%rax), %edi
callq 0x61f0
movq %rax, -0x110(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x6930
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rdx
leaq -0x88(%rbp), %rdi
callq 0xa9d0
jmp 0x24707
movq -0x100(%rbp), %rdi
movq -0xf0(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rax), %r8d
leaq -0x50(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x24a00
jmp 0x2472e
movq -0x100(%rbp), %rdi
movb $0x0, -0x8a(%rbp)
leaq 0x1a10d(%rip), %rsi     # 0x3e850
leaq 0x316(%rip), %rdx       # 0x24a60
callq 0x68e0
jmp 0x2499f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2479d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x24788
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x6310
leaq -0x89(%rbp), %rdi
callq 0x6550
leaq -0x50(%rbp), %rdi
callq 0x6310
leaq -0x51(%rbp), %rdi
callq 0x6550
testb $0x1, -0x8a(%rbp)
jne 0x247b1
jmp 0x247bd
movq -0x100(%rbp), %rdi
callq 0x63b0
jmp 0x24996
movq -0xf0(%rbp), %rax
movl (%rax), %edi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x60c0
cmpl $-0x1, %eax
jne 0x24837
movq -0xf0(%rbp), %rax
movl (%rax), %edi
callq 0x69e0
movq -0xf0(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
callq 0x6080
movl (%rax), %edi
callq 0x61f0
movq %rax, -0x98(%rbp)
leaq 0x1aec7(%rip), %rdi     # 0x3f6e0
movl $0x5, %esi
leaq 0x8262(%rip), %rdx      # 0x2ca87
leaq -0x18(%rbp), %rcx
leaq -0x98(%rbp), %r8
callq 0x24d60
jmp 0x24839
jmp 0x2484a
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x245f1
movq -0xf0(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x2498d
movb $0x1, -0xe2(%rbp)
movl $0x50, %edi
callq 0x6280
movq %rax, -0x120(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x6930
movq -0x118(%rbp), %rdx
leaq 0x821b(%rip), %rsi      # 0x2caae
leaq -0xb8(%rbp), %rdi
callq 0xa9d0
jmp 0x248a1
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x6930
movq -0x128(%rbp), %rdx
leaq 0x81f5(%rip), %rsi      # 0x2cab7
leaq -0xe0(%rbp), %rdi
callq 0xa9d0
jmp 0x248d0
movq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rcx
leaq -0xb8(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
movl $0xfffffffe, %r8d       # imm = 0xFFFFFFFE
callq 0x24a00
jmp 0x248f6
movq -0x120(%rbp), %rdi
movb $0x0, -0xe2(%rbp)
leaq 0x19f45(%rip), %rsi     # 0x3e850
leaq 0x14e(%rip), %rdx       # 0x24a60
callq 0x68e0
jmp 0x2499f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x24968
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x24950
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x6310
leaq -0xe1(%rbp), %rdi
callq 0x6550
leaq -0xb8(%rbp), %rdi
callq 0x6310
leaq -0xb9(%rbp), %rdi
callq 0x6550
testb $0x1, -0xe2(%rbp)
jne 0x2497f
jmp 0x2498b
movq -0x120(%rbp), %rdi
callq 0x63b0
jmp 0x24996
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x6920
nop