// File: 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
subq $0x180, %rsp            # imm = 0x180
movq %rcx, -0x150(%rbp)
movw %dx, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x148(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0x8(%rcx), %eax
jne 0xafd2
movq -0x148(%rbp), %rdi
callq 0x139a0
movq -0x148(%rbp), %rdi
callq 0x13760
movq -0x148(%rbp), %rdi
movq -0x10(%rbp), %rsi
movzwl -0x12(%rbp), %edx
callq 0xaa30
testb $0x1, %al
jne 0xafef
jmp 0xb334
movq -0x148(%rbp), %rdi
movl $0x0, 0x1f4(%rdi)
movl 0x8(%rdi), %eax
movl %eax, -0x154(%rbp)
addq $0x1e0, %rdi            # imm = 0x1E0
callq 0x68f0
movl -0x154(%rbp), %edi
movq %rax, %rsi
movl $0x10, %edx
callq 0x41c0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0xb271
callq 0x4030
movq %rax, %rcx
movl $0x73, %eax
cmpl (%rcx), %eax
jne 0xb1af
movq -0x148(%rbp), %rsi
movl $0x1, 0x1f4(%rsi)
addq $0x170, %rsi            # imm = 0x170
leaq -0x28(%rbp), %rdi
callq 0x7330
movq -0x148(%rbp), %rax
movq -0x150(%rbp), %rcx
movq %rax, %rdx
addq $0x1c8, %rdx            # imm = 0x1C8
movq %rdx, -0x160(%rbp)
leaq 0x2bd(%rip), %rdx       # 0xb350
movq %rdx, -0x90(%rbp)
movq $0x0, -0x88(%rbp)
movq %rax, -0x98(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0xc6c0
jmp 0xb0c5
leaq -0x48(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xc700
jmp 0xb0d4
movq -0x160(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xc4f0
jmp 0xb0e6
leaq -0x48(%rbp), %rdi
callq 0x6b50
leaq -0x80(%rbp), %rdi
callq 0xc7a0
movq -0x148(%rbp), %rax
testb $0x1, 0x1f0(%rax)
je 0xb16a
movq -0x148(%rbp), %rdi
addq $0x10, %rdi
callq 0x144e0
jmp 0xb11a
jmp 0xb193
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xb1a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xb15f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x6b50
leaq -0x80(%rbp), %rdi
callq 0xc7a0
jmp 0xb1a1
movq -0x148(%rbp), %rax
testb $0x1, 0x1f1(%rax)
je 0xb191
movq -0x148(%rbp), %rdi
addq $0x98, %rdi
callq 0x144e0
jmp 0xb18f
jmp 0xb191
jmp 0xb193
leaq -0x28(%rbp), %rdi
callq 0x73e0
jmp 0xb26c
leaq -0x28(%rbp), %rdi
callq 0x73e0
jmp 0xb33d
callq 0x6910
movq %rax, %rdi
callq 0x6a00
movq %rax, -0x170(%rbp)
callq 0x4030
movq -0x150(%rbp), %rsi
movq %rax, %rdx
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0xc7c0
movq -0x168(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0xc800
jmp 0xb1fa
movq -0x170(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x8e20
jmp 0xb20f
leaq -0xc8(%rbp), %rdi
callq 0x6b50
leaq -0xf0(%rbp), %rdi
callq 0xc8a0
jmp 0xb26c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xb25b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x6b50
leaq -0xf0(%rbp), %rdi
callq 0xc8a0
jmp 0xb33d
jmp 0xb334
callq 0x6910
movq %rax, %rdi
callq 0x6a00
movq -0x150(%rbp), %rsi
movq %rax, -0x180(%rbp)
movl $0x0, -0x13c(%rbp)
leaq -0x138(%rbp), %rdi
movq %rdi, -0x178(%rbp)
leaq -0x13c(%rbp), %rdx
callq 0xc8c0
movq -0x178(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0xc800
jmp 0xb2c5
movq -0x180(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x8e20
jmp 0xb2da
leaq -0x110(%rbp), %rdi
callq 0x6b50
leaq -0x138(%rbp), %rdi
callq 0xc8a0
jmp 0xb334
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xb326
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x6b50
leaq -0x138(%rbp), %rdi
callq 0xc8a0
jmp 0xb33d
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x4360
nopl (%rax)