// File: /workspace/github_cpp_makefile_star2_O1/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 0x5a5e
movq %r14, %rdi
callq 0x7dd8
movq %r14, %rdi
callq 0x7c8e
movzwl %r15w, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x56ca
testb %al, %al
je 0x5c5d
movl $0x0, 0x1f4(%r14)
movl 0x8(%r14), %edi
movq 0x1e0(%r14), %rsi
movl $0x10, %edx
callq 0x31b0
cmpl $-0x1, %eax
je 0x5b08
callq 0x42be
movq %rax, %rbx
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x6fd4
movl $0x0, 0x20(%r14)
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x6b38
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
callq 0x4a9e
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x5ae8
leaq -0x78(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x5c5d
leaq -0x58(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5c5d
callq 0x3040
cmpl $0x73, (%rax)
jne 0x5bea
movl $0x1, 0x1f4(%r14)
leaq 0x170(%r14), %rbx
movq %rbx, %rdi
callq 0x32a0
testl %eax, %eax
jne 0x5c6d
leaq 0x22d(%rip), %rax       # 0x5d6c
leaq -0x48(%rbp), %r15
movq %rax, -0x10(%r15)
movq $0x0, -0x8(%r15)
movq %r15, %rdi
movq %r12, %rsi
callq 0x6fd4
leaq -0x58(%rbp), %rsi
movq %r14, 0x30(%rsi)
leaq -0xb8(%rbp), %rdi
callq 0x6ada
leaq 0x1c8(%r14), %rdi
leaq -0xb8(%rbp), %rdx
movq %rdi, %rsi
callq 0x6ea2
movq -0xa8(%rbp), %rax
testq %rax, %rax
je 0x5ba1
leaq -0xb8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x5bb7
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
movl $0x10, %eax
cmpb $0x0, 0x1f0(%r14)
jne 0x5bd5
movl $0x98, %eax
cmpb $0x1, 0x1f1(%r14)
jne 0x5be0
addq %rax, %r14
movq %r14, %rdi
callq 0x82aa
movq %rbx, %rdi
callq 0x3180
jmp 0x5c5d
movq %rax, %r15
callq 0x42be
movq %rax, %rbx
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x6fd4
movl (%r15), %eax
movl %eax, 0x20(%r14)
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
callq 0x6b38
leaq -0x98(%rbp), %rsi
movq %rbx, %rdi
callq 0x4a9e
movq -0x88(%rbp), %rax
testq %rax, %rax
je 0x5c46
leaq -0x98(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x5c5d
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 0x5d64
jmp 0x5d64
jmp 0x5d64
jmp 0x5d64
jmp 0x5cf5
movq %rax, %r14
movq -0xa8(%rbp), %rax
testq %rax, %rax
je 0x5cb4
leaq -0xb8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5cb4
jmp 0x5d64
movq %rax, %r14
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x5cf8
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5cf8
jmp 0x5d64
movq %rax, %r14
movq -0x88(%rbp), %rax
testq %rax, %rax
je 0x5d05
leaq -0x98(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5d05
jmp 0x5d64
movq %rax, %r14
movq %rbx, %rdi
callq 0x3180
jmp 0x5d5c
movq %rax, %r14
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x5d5c
leaq -0x58(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5d5c
jmp 0x5d64
jmp 0x5d64
jmp 0x5d64
movq %rax, %r14
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x5d45
leaq -0x78(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x5d45
jmp 0x5d64
movq %rax, %r14
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x5d5c
leaq -0x58(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %r14, %rdi
callq 0x3330
movq %rax, %rdi
callq 0x3a3f