// File: /workspace/github_cpp_makefile_star2_O3/nightmeng[P]net/src/socket.cpp
// Function: socket::async_connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned short, std::function<void (int)>)
void socket::async_connect(const std::string &ip, unsigned short port,
		ccallback ccb){
	if(-1 == sock){
		open();
		register_epoll_req();
	}

	if(!update_addr(ip, port)){
		return;
	}
	
	connect_status = PRECONNECT;
	if(-1 == ::connect(sock, 
				reinterpret_cast<struct sockaddr*>(addr.get()), 
				sizeof(struct sockaddr))){
		if(EINPROGRESS == errno){
			connect_status = CONNECTING;
			std::lock_guard<std::mutex> locker(conn_mutex);
			conn_request.push_back(
					std::bind(&socket::async_conn_action, this, ccb));
			if(rdable){
				rd_worker.active();
			}
			else if(wrable){
				wr_worker.active();
			}
		}
		else{
			singleton<scheduler>::instance()->arrange(std::bind(ccb, errno));
		}
	}
	else{
		singleton<scheduler>::instance()->arrange(std::bind(ccb, 0));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rcx, %r12
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
cmpl $-0x1, 0x8(%rdi)
jne 0x59ca
movq %r14, %rdi
callq 0x7ce0
movq %r14, %rdi
callq 0x7b96
movzwl %r15w, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5636
testb %al, %al
je 0x5bc9
movl $0x0, 0x1f4(%r14)
movl 0x8(%r14), %edi
movq 0x1e0(%r14), %rsi
movl $0x10, %edx
callq 0x31b0
cmpl $-0x1, %eax
je 0x5a74
callq 0x427a
movq %rax, %rbx
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x6f0c
movl $0x0, 0x20(%r14)
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x6a7c
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
callq 0x4a32
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x5a54
leaq -0x78(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x5bc9
leaq -0x58(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5bc9
callq 0x3040
cmpl $0x73, (%rax)
jne 0x5b56
movl $0x1, 0x1f4(%r14)
leaq 0x170(%r14), %rbx
movq %rbx, %rdi
callq 0x32a0
testl %eax, %eax
jne 0x5bd9
leaq 0x22d(%rip), %rax       # 0x5cd8
leaq -0x48(%rbp), %r15
movq %rax, -0x10(%r15)
movq $0x0, -0x8(%r15)
movq %r15, %rdi
movq %r12, %rsi
callq 0x6f0c
leaq -0x58(%rbp), %rsi
movq %r14, 0x30(%rsi)
leaq -0xb8(%rbp), %rdi
callq 0x6a1e
leaq 0x1c8(%r14), %rdi
leaq -0xb8(%rbp), %rdx
movq %rdi, %rsi
callq 0x6de0
movq -0xa8(%rbp), %rax
testq %rax, %rax
je 0x5b0d
leaq -0xb8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x5b23
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
movl $0x10, %eax
cmpb $0x0, 0x1f0(%r14)
jne 0x5b41
movl $0x98, %eax
cmpb $0x1, 0x1f1(%r14)
jne 0x5b4c
addq %rax, %r14
movq %r14, %rdi
callq 0x819c
movq %rbx, %rdi
callq 0x3180
jmp 0x5bc9
movq %rax, %r15
callq 0x427a
movq %rax, %rbx
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x6f0c
movl (%r15), %eax
movl %eax, 0x20(%r14)
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
callq 0x6a7c
leaq -0x98(%rbp), %rsi
movq %rbx, %rdi
callq 0x4a32
movq -0x88(%rbp), %rax
testq %rax, %rax
je 0x5bb2
leaq -0x98(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x5bc9
leaq -0x58(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x3140
jmp 0x5cd0
jmp 0x5cd0
jmp 0x5cd0
jmp 0x5cd0
jmp 0x5c61
movq %rax, %r14
movq -0xa8(%rbp), %rax
testq %rax, %rax
je 0x5c20
leaq -0xb8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5c20
jmp 0x5cd0
movq %rax, %r14
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x5c64
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5c64
jmp 0x5cd0
movq %rax, %r14
movq -0x88(%rbp), %rax
testq %rax, %rax
je 0x5c71
leaq -0x98(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5c71
jmp 0x5cd0
movq %rax, %r14
movq %rbx, %rdi
callq 0x3180
jmp 0x5cc8
movq %rax, %r14
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x5cc8
leaq -0x58(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5cc8
jmp 0x5cd0
jmp 0x5cd0
jmp 0x5cd0
movq %rax, %r14
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x5cb1
leaq -0x78(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5cb1
jmp 0x5cd0
movq %rax, %r14
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x5cc8
leaq -0x58(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %r14, %rdi
callq 0x3330
movq %rax, %rdi
callq 0x3a01