// File: roberty65[P]bServer/frame/main/Connector.cpp
// Function: beyondy::Async::Connector::onWritable(int)
int Connector::onWritable(int fd)
{
	SYSLOG_DEBUG("connector(%s) is onWritable", address);
	assert(this->fd == fd);

	if (status == CONN_ESTABLISHED) {
		return Connection::onWritable(fd);
	}
	else if (status == CONN_OPENNING) {
			int err = XbsGetError(this->fd);
			if (err != 0) {
				errno = err;
				SYSLOG_ERROR("connect to %s failed: %m", address);
				return -1;
			}

			cntRetryConnect = 0;	// reset it
			status = CONN_ESTABLISHED;
			if (emgr->modifyConnection(this, EVENT_IN, 0) < 0) {
				SYSLOG_ERROR("connector(%s) fd=%d flow=%d add EVENT_IN failed: %m", address, fd, flow);
				return -1;
			}

			SYSLOG_ERROR("connector(%s) establish done: fd=%d flow=%d", address, fd, flow);
			return Connection::onWritable(fd);
	}

	SYSLOG_ERROR("connector %s is writable but in CLOSE state", address);
	return 0; // why here?
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq 0xf74a(%rip), %rax      # 0x1a5e8
movq (%rax), %rdi
movl $0x5, %esi
callq 0x4b50
cmpl $0x0, %eax
je 0xaed8
movq -0x20(%rbp), %rcx
leaq 0xf72d(%rip), %rax      # 0x1a5e8
movq (%rax), %rdi
addq $0xb8, %rcx
movl $0x5, %esi
leaq 0x80ea(%rip), %rdx      # 0x12fbb
movb $0x0, %al
callq 0xbf40
jmp 0xaeda
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0xaee8
jmp 0xaf07
leaq 0x79ed(%rip), %rdi      # 0x128dc
leaq 0x80e1(%rip), %rsi      # 0x12fd7
movl $0x21, %edx
leaq 0x80e3(%rip), %rcx      # 0x12fe5
callq 0x3250
movq -0x20(%rbp), %rax
cmpl $0x2, 0xb4(%rax)
jne 0xaf28
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xa100
movl %eax, -0x4(%rbp)
jmp 0xb0e5
movq -0x20(%rbp), %rax
cmpl $0x1, 0xb4(%rax)
jne 0xb097
movq -0x20(%rbp), %rax
movl 0x8(%rax), %edi
callq 0xc7e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0xafad
movl -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
callq 0x3060
movl -0x24(%rbp), %ecx
movl %ecx, (%rax)
leaq 0xf683(%rip), %rax      # 0x1a5e8
movq (%rax), %rdi
movl $0x2, %esi
callq 0x4b50
cmpl $0x0, %eax
je 0xaf9f
movq -0x20(%rbp), %rcx
leaq 0xf666(%rip), %rax      # 0x1a5e8
movq (%rax), %rdi
addq $0xb8, %rcx
movl $0x2, %esi
leaq 0x8084(%rip), %rdx      # 0x1301c
movb $0x0, %al
callq 0xbf40
jmp 0xafa1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb0e5
movq -0x20(%rbp), %rsi
movl $0x0, 0xb0(%rsi)
movl $0x2, 0xb4(%rsi)
movq 0x70(%rsi), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x7b20
cmpl $0x0, %eax
jge 0xb036
jmp 0xafdc
leaq 0xf605(%rip), %rax      # 0x1a5e8
movq (%rax), %rdi
movl $0x2, %esi
callq 0x4b50
cmpl $0x0, %eax
je 0xb028
movq -0x20(%rbp), %rax
leaq 0xf5e8(%rip), %rcx      # 0x1a5e8
movq (%rcx), %rdi
movq %rax, %rcx
addq $0xb8, %rcx
movl -0x14(%rbp), %r8d
movl 0x10(%rax), %r9d
movl $0x2, %esi
leaq 0x8014(%rip), %rdx      # 0x13035
movb $0x0, %al
callq 0xbf40
jmp 0xb02a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb0e5
jmp 0xb038
leaq 0xf5a9(%rip), %rax      # 0x1a5e8
movq (%rax), %rdi
movl $0x2, %esi
callq 0x4b50
cmpl $0x0, %eax
je 0xb084
movq -0x20(%rbp), %rax
leaq 0xf58c(%rip), %rcx      # 0x1a5e8
movq (%rcx), %rdi
movq %rax, %rcx
addq $0xb8, %rcx
movl -0x14(%rbp), %r8d
movl 0x10(%rax), %r9d
movl $0x2, %esi
leaq 0x7fec(%rip), %rdx      # 0x13069
movb $0x0, %al
callq 0xbf40
jmp 0xb086
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xa100
movl %eax, -0x4(%rbp)
jmp 0xb0e5
jmp 0xb099
jmp 0xb09b
leaq 0xf546(%rip), %rax      # 0x1a5e8
movq (%rax), %rdi
movl $0x2, %esi
callq 0x4b50
cmpl $0x0, %eax
je 0xb0dc
movq -0x20(%rbp), %rcx
leaq 0xf529(%rip), %rax      # 0x1a5e8
movq (%rax), %rdi
addq $0xb8, %rcx
movl $0x2, %esi
leaq 0x7fc0(%rip), %rdx      # 0x13095
movb $0x0, %al
callq 0xbf40
jmp 0xb0de
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop