// File: /workspace/github_cpp_makefile_star2_O2/enbock[P]Warp10Server/ulib/src/Socket.cpp
// Function: u::Socket::connect()
bool u::Socket::connect()
{
	if(isConnected()) return false;

	lock();
	switch(_domain)
	{
		case AF_UNIX:
		{
			_con = ::connect(
				_descriptor
				, (const sockaddr*)_addr
				, _addrLen
			);
		} break;
		case AF_INET:
		case AF_INET6:
		default:
		{
			struct addrinfo hints, *servinfo, *p;
			memset(&hints, 0, sizeof hints);
			hints.ai_family = _domain;
			hints.ai_socktype = _type;

			if(::getaddrinfo(_hostname.c_str(), int2string((int)_port).c_str(), &hints, &servinfo) != 0)
			{
				error(className()+"::connect: Can't resolv hostname "+_hostname+":"
					+int2string(_port));
				return false;
			}

			for(p = servinfo; p != NULL; p = p->ai_next)
			{
				((struct sockaddr_in *)_addr)->sin_addr = ((struct sockaddr_in*)p->ai_addr)->sin_addr;
				_con = ::connect(_descriptor, (const struct sockaddr*)_addr, _addrLen);
				if(isConnected())
				{
					break;
				}
			}

			freeaddrinfo(servinfo);
		} break;
	}
	unlock();
	return isConnected();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x170, %rsp            # imm = 0x170
movq %rdi, %rbx
callq 0x40dc34
testb %al, %al
jne 0x40defd
movq %rbx, %rdi
callq 0x40c442
movl 0x38(%rbx), %eax
cmpl $0x1, %eax
jne 0x40dd92
movl 0x34(%rbx), %edi
movq 0x48(%rbx), %rsi
movl 0x50(%rbx), %edx
callq 0x559f80
movl %eax, 0x54(%rbx)
jmp 0x40df3f
xorps %xmm0, %xmm0
leaq 0x140(%rsp), %r15
movaps %xmm0, (%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, 0x20(%r15)
movl %eax, 0x4(%r15)
movl 0x40(%rbx), %eax
movl %eax, 0x8(%r15)
movq 0x90(%rbx), %r12
movl 0xb0(%rbx), %esi
leaq 0x90(%rsp), %r14
movq %r14, %rdi
callq 0x40c712
movq 0x38(%r14), %rsi
leaq 0x8(%rsp), %r14
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x5544c0
movl %eax, %ebp
leaq 0x90(%rsp), %rdi
callq 0x4050e8
testl %ebp, %ebp
je 0x40df2d
movq $0x64eb00, %rdi         # imm = 0x64EB00
leaq 0x1b9344(%rip), %rsi    # 0x5c7153
callq 0x489b70
movq %rax, %r14
movq (%rbx), %rax
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
callq *0x8(%rax)
leaq 0xc8(%rsp), %rsi
leaq 0x1b9e92(%rip), %rdx    # 0x5c7cc9
leaq 0x10(%rsp), %rdi
callq 0x405349
leaq 0x90(%rbx), %rdx
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4068ac
leaq 0x1c176f(%rip), %rdx    # 0x5cf5cd
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x405349
movl 0xb0(%rbx), %esi
leaq 0xe8(%rsp), %rdi
callq 0x40c712
leaq 0x120(%rsp), %rdx
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x406c55
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x49c3f0
leaq 0x1b9200(%rip), %rsi    # 0x5c70ab
movq %rax, %rdi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
leaq 0x70(%rsp), %rdi
callq 0x499a70
leaq 0xe8(%rsp), %rdi
callq 0x4050e8
leaq 0x50(%rsp), %rdi
callq 0x499a70
leaq 0x30(%rsp), %rdi
callq 0x499a70
leaq 0x10(%rsp), %rdi
callq 0x499a70
leaq 0x90(%rsp), %rdi
callq 0x4050e8
xorl %eax, %eax
jmp 0x40df4f
movq 0x18(%r14), %rax
movq 0x48(%rbx), %rsi
movl 0x4(%rax), %eax
movl %eax, 0x4(%rsi)
movl 0x34(%rbx), %edi
movl 0x50(%rbx), %edx
callq 0x559f80
movl %eax, 0x54(%rbx)
movq %rbx, %rdi
callq 0x40dc34
addq $0x28, %r14
testb %al, %al
jne 0x40df35
movq (%r14), %r14
testq %r14, %r14
jne 0x40df01
movq 0x8(%rsp), %rdi
callq 0x556a40
movq %rbx, %rdi
callq 0x40c3fe
movq %rbx, %rdi
callq 0x40dc34
addq $0x170, %rsp            # imm = 0x170
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x40df87
movq %rax, %rbx
jmp 0x40df94
movq %rax, %rbx
jmp 0x40df9e
movq %rax, %rbx
jmp 0x40dfa8
jmp 0x40df75
movq %rax, %rbx
jmp 0x40dfb2
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x499a70
leaq 0xe8(%rsp), %rdi
callq 0x4050e8
leaq 0x50(%rsp), %rdi
callq 0x499a70
leaq 0x30(%rsp), %rdi
callq 0x499a70
leaq 0x10(%rsp), %rdi
callq 0x499a70
leaq 0x90(%rsp), %rdi
callq 0x4050e8
movq %rbx, %rdi
callq 0x4ca950
nop