// File: /workspace/github_cpp_makefile_star2_O2/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 $0xb0, %rsp
movq %rcx, %r15
movl %edx, %r12d
movq %rsi, %r14
movq %rdi, %rbx
cmpl $-0x1, 0x8(%rdi)
jne 0x5592
movq %rbx, %rdi
callq 0x7b04
movq %rbx, %rdi
callq 0x79ce
movzwl %r12w, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x52a6
testb %al, %al
je 0x56ed
andl $0x0, 0x1f4(%rbx)
movl 0x8(%rbx), %edi
movq 0x1e0(%rbx), %rsi
pushq $0x10
popq %rdx
callq 0x31a0
cmpl $-0x1, %eax
je 0x5604
callq 0x3f48
movq %rax, %rbx
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x6900
andl $0x0, 0x20(%r14)
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x6126
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
callq 0x4878
leaq -0x78(%rbp), %rdi
jmp 0x56df
callq 0x3030
cmpl $0x73, (%rax)
jne 0x569d
movl $0x1, 0x1f4(%rbx)
leaq 0x170(%rbx), %r14
movq %r14, %rdi
callq 0x41ca
leaq 0x14c(%rip), %rax       # 0x577e
leaq -0xd0(%rbp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
leaq -0xa0(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x58(%rbp), %rdi
movq %r15, %rcx
callq 0x68c4
leaq -0xc0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x60de
leaq 0x1c8(%rbx), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x606c
leaq -0xc0(%rbp), %rdi
callq 0x3862
leaq -0x48(%rbp), %rdi
callq 0x3862
cmpb $0x0, 0x1f0(%rbx)
je 0x56fd
pushq $0x10
popq %rax
jmp 0x570b
movq %rax, %r14
callq 0x3f48
movq %rax, %rbx
leaq -0x58(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6b9c
leaq -0x98(%rbp), %rdi
movq %r12, %rsi
callq 0x6126
leaq -0x98(%rbp), %rsi
movq %rbx, %rdi
callq 0x4878
leaq -0x98(%rbp), %rdi
callq 0x3862
leaq -0x58(%rbp), %rdi
callq 0x3862
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x98, %eax
cmpb $0x1, 0x1f1(%rbx)
jne 0x5716
addq %rax, %rbx
movq %rbx, %rdi
callq 0x7f4e
movq %r14, %rdi
callq 0x3180
jmp 0x56ed
jmp 0x574f
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x3862
jmp 0x5742
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
jmp 0x5763
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3862
jmp 0x5752
jmp 0x576a
movq %rax, %rbx
movq %r14, %rdi
callq 0x3180
jmp 0x5776
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x3862
jmp 0x576d
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x3862
movq %rbx, %rdi
callq 0x3310