// File: /workspace/github_cpp_makefile_star2_O1/roberty65[P]bServer/frame/main/Connection.cpp
// Function: beyondy::Async::Connection::onWritable(int)
int Connection::onWritable(int fd) 
{
	BPROF_TRACE(BPT_CONN_WRITABLE)

	assert(this->fd == fd);
	SYSLOG_DEBUG("connection fd=%d flow=%d onWritable. qsize=%ld", fd, flow, (long)(outQueue->size() + (outMsg == NULL ? 0 : 1)));

	if (outMsg == NULL) {
		if (outQueue->empty()) {
			// do not watch OUT event for it
			emgr->modifyConnection(this, 0, EVENT_OUT);
			return 0;
		}

		outMsg = outQueue->front();
		outQueue->pop_front();

		SYSLOG_DEBUG("connection fd=%d flow=%d start to send out msg(len=%ld)", fd, flow, (long)outMsg->getWptr());

		gettimeofday(&outMsg->ts_byte_first, NULL);
	}

	size_t left = outMsg->getWptr() - outMsg->getRptr();
	ssize_t wlen = writeN(outMsg, left);

	if ((size_t)wlen == left) {
		SYSLOG_DEBUG("connection fd=%d flow=%d send msg done(left=%ld)", fd, flow, (long)left);

		gettimeofday(&outMsg->ts_process_end, NULL);
		proc->onSent(outMsg, SS_OK);
		outMsg = NULL;

		// TODO: send more this time?
		return 0;
	}
	else if ((size_t)wlen < left) {
		/* try next time */
		SYSLOG_DEBUG("connection fd=%d flow=%d partially sent: should=%ld, real=%ld", fd, flow, (long)left, (long)wlen);
		return 0;
	}

	SYSLOG_ERROR("connection fd=%d flow=%d send msg(rest=%d) failed", fd, flow, (long)left);
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpl %esi, 0x8(%rdi)
jne 0x634f
movl %esi, %ebp
movq %rdi, %rbx
leaq 0xa35e(%rip), %r15      # 0x10508
movq (%r15), %rdi
cmpl $0x5, (%rdi)
jl 0x6211
movq 0x68(%rbx), %rax
movq 0x48(%rax), %rcx
movq %rcx, %rdx
subq 0x28(%rax), %rdx
shrq $0x3, %rdx
cmpq $0x1, %rcx
adcq $-0x1, %rdx
movl 0x10(%rbx), %r8d
shlq $0x6, %rdx
movq 0x20(%rax), %r9
movq 0x30(%rax), %rcx
subq 0x38(%rax), %rcx
subq 0x10(%rax), %r9
sarq $0x3, %rcx
sarq $0x3, %r9
addq %rcx, %r9
addq %rdx, %r9
cmpq $0x1, 0x60(%rbx)
sbbq $-0x1, %r9
leaq 0x4928(%rip), %rdx      # 0xab2b
movl $0x5, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x7310
cmpq $0x0, 0x60(%rbx)
jne 0x626e
movq 0x68(%rbx), %rdi
movq 0x10(%rdi), %rax
cmpq %rax, 0x30(%rdi)
je 0x632b
movq (%rax), %rax
movq %rax, 0x60(%rbx)
callq 0x568e
movq (%r15), %rdi
cmpl $0x5, (%rdi)
jl 0x625f
movl 0x10(%rbx), %r8d
movq 0x60(%rbx), %rax
movq 0x10(%rax), %r9
leaq 0x4909(%rip), %rdx      # 0xab5a
movl $0x5, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x7310
movq 0x60(%rbx), %rdi
addq $0x30, %rdi
xorl %esi, %esi
callq 0x3570
movq 0x60(%rbx), %rsi
movq 0x10(%rsi), %r14
subq 0x8(%rsi), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x636e
cmpq %r14, %rax
jne 0x62da
movq (%r15), %rdi
cmpl $0x5, (%rdi)
jl 0x62ae
movl 0x10(%rbx), %r8d
leaq 0x48f5(%rip), %rdx      # 0xab92
movl $0x5, %esi
movl %ebp, %ecx
movq %r14, %r9
xorl %eax, %eax
callq 0x7310
movq 0x60(%rbx), %rdi
addq $0x60, %rdi
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x3570
movq 0x60(%rbx), %rsi
movq 0x78(%rbx), %rdi
movq (%rdi), %rax
xorl %edx, %edx
callq *0x38(%rax)
movq $0x0, 0x60(%rbx)
jmp 0x6341
movq (%r15), %rdi
movl (%rdi), %ecx
jae 0x6302
xorl %r15d, %r15d
cmpl $0x5, %ecx
jl 0x6341
movl 0x10(%rbx), %r8d
movq %rax, (%rsp)
leaq 0x48cb(%rip), %rdx      # 0xabc3
xorl %r15d, %r15d
movl $0x5, %esi
jmp 0x631d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x2, %ecx
jl 0x6341
movl 0x10(%rbx), %r8d
leaq 0x48e9(%rip), %rdx      # 0xac01
movl $0x2, %esi
movl %ebp, %ecx
movq %r14, %r9
xorl %eax, %eax
callq 0x7310
jmp 0x6341
movq 0x70(%rbx), %rdi
xorl %r15d, %r15d
movq %rbx, %rsi
xorl %edx, %edx
movl $0x4, %ecx
callq 0x4f78
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4502(%rip), %rdi      # 0xa858
leaq 0x450a(%rip), %rsi      # 0xa867
leaq 0x478f(%rip), %rcx      # 0xaaf3
movl $0x80, %edx
callq 0x31f0