// File: /workspace/github_cpp_makefile_star2_O3/roberty65[P]bServer/frame/main/Connection.cpp
// Function: beyondy::Async::Connection::sendMessage(beyondy::Async::Message*)
int Connection::sendMessage(Message *msg) 
{
	BPROF_TRACE(BPT_CONN_SENDMESSAGE)
	if (outMsg == NULL && outQueue->empty()) {
		/* send out directly as can as possible */
		gettimeofday(&msg->ts_byte_first, NULL);

		size_t rest = msg->getWptr() - msg->getRptr();
		ssize_t wlen = writeN(msg, rest);

		if ((size_t)wlen == rest) {
			SYSLOG_DEBUG("connection fd=%d flow=%d sendMessage %ld bytes done", fd, flow, (long)rest);

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

			return 0;
		}
		else if ((size_t)wlen < rest) {
			/* send later */
			SYSLOG_ERROR("connection fd=%d flow=%d sendMessage %ld bytes, done=%ld ", fd, flow, (long)rest, (long)wlen);
			outMsg = msg;
			emgr->modifyConnection(this, EVENT_OUT, 0); // watch out-able
			return 0;
		}
		
		SYSLOG_ERROR("connection fd=%d flow=%d sendMessage %ld bytes failed", fd, flow, (long)rest);
		proc->onSent(msg, SS_IO_ERROR);
		return -1;
	}

	// otherwise, outQueue is not empty (so need queue after them)
	// or outMsg is in sending, need queue too
	if (outQueue->size() >= (size_t)emgr->getConnectionOutQueueSize()) {
		SYSLOG_ERROR("connection fd=%d flow=%d sendMessge over-flow, out-queue-size=%ld", fd, flow, (long)outQueue->size());
		proc->onSent(msg, SS_QUEUE_FULL);
		return -1;
	}
	else {
		outQueue->push_back(msg);
	}

	SYSLOG_DEBUG("connection fd=%d flow=%d sendMessge en-outQueue(qsize=%ld) OK",
		fd, flow, (long)(outQueue->size() + (outMsg == NULL ? 0 : 1)));
	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x8(%rsp)
cmpq $0x0, 0x60(%rdi)
movq 0x68(%rdi), %rdi
je 0x639f
movq 0x10(%rdi), %rcx
movq 0x30(%rdi), %rax
jmp 0x63b0
movq 0x10(%rdi), %rcx
movq 0x30(%rdi), %rax
cmpq %rcx, %rax
je 0x64d9
movq 0x20(%rdi), %r9
movq 0x48(%rdi), %rdx
movq %rdx, %rsi
subq 0x28(%rdi), %rsi
shrq $0x3, %rsi
cmpq $0x1, %rdx
adcq $-0x1, %rsi
shlq $0x6, %rsi
movq %rax, %rdx
subq 0x38(%rdi), %rdx
sarq $0x3, %rdx
subq %rcx, %r9
sarq $0x3, %r9
addq %rsi, %r9
addq %rdx, %r9
movq 0x70(%rbx), %rcx
movslq 0x64(%rcx), %rcx
cmpq %rcx, %r9
jae 0x640b
movq 0x40(%rdi), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x6451
movq %r14, (%rax)
addq $0x8, 0x30(%rdi)
jmp 0x645b
leaq 0xa0f6(%rip), %rax      # 0x10508
movq (%rax), %rdi
cmpl $0x2, (%rdi)
jl 0x6434
movl 0x8(%rbx), %ecx
movl 0x10(%rbx), %r8d
leaq 0x4905(%rip), %rdx      # 0xad2d
movl $0x2, %esi
xorl %eax, %eax
callq 0x71fc
movq 0x78(%rbx), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movl $0x3, %edx
callq *0x38(%rax)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x6598
leaq 0x8(%rsp), %rsi
callq 0x5952
leaq 0xa0a6(%rip), %rax      # 0x10508
movq (%rax), %rdi
xorl %r15d, %r15d
cmpl $0x5, (%rdi)
jl 0x6598
movl 0x8(%rbx), %ecx
movq 0x68(%rbx), %rax
movq 0x48(%rax), %rdx
movq %rdx, %rsi
subq 0x28(%rax), %rsi
shrq $0x3, %rsi
cmpq $0x1, %rdx
adcq $-0x1, %rsi
movl 0x10(%rbx), %r8d
shlq $0x6, %rsi
movq 0x20(%rax), %r9
movq 0x30(%rax), %rdx
subq 0x38(%rax), %rdx
subq 0x10(%rax), %r9
sarq $0x3, %rdx
sarq $0x3, %r9
addq %rdx, %r9
addq %rsi, %r9
cmpq $0x1, 0x60(%rbx)
sbbq $-0x1, %r9
leaq 0x48aa(%rip), %rdx      # 0xad6f
xorl %r15d, %r15d
movl $0x5, %esi
xorl %eax, %eax
callq 0x71fc
jmp 0x6598
leaq 0x30(%r14), %rdi
xorl %esi, %esi
callq 0x3570
movq 0x10(%r14), %r15
subq 0x8(%r14), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x6284
cmpq %r15, %rax
jne 0x654a
leaq 0xa002(%rip), %rax      # 0x10508
movq (%rax), %rdi
cmpl $0x5, (%rdi)
jl 0x652b
movl 0x8(%rbx), %ecx
movl 0x10(%rbx), %r8d
leaq 0x476d(%rip), %rdx      # 0xac89
movl $0x5, %esi
movq %r15, %r9
xorl %eax, %eax
callq 0x71fc
leaq 0x60(%r14), %rdi
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x3570
movq 0x78(%rbx), %rdi
movq (%rdi), %rax
movq %r14, %rsi
xorl %edx, %edx
callq *0x38(%rax)
jmp 0x6598
leaq 0x9fb7(%rip), %rcx      # 0x10508
movq (%rcx), %rdi
movl (%rdi), %ecx
jae 0x65a5
cmpl $0x2, %ecx
jl 0x657e
movl 0x8(%rbx), %ecx
movl 0x10(%rbx), %r8d
movq %rax, (%rsp)
leaq 0x474e(%rip), %rdx      # 0xacbd
movl $0x2, %esi
movq %r15, %r9
xorl %eax, %eax
callq 0x71fc
movq %r14, 0x60(%rbx)
movq 0x70(%rbx), %rdi
xorl %r15d, %r15d
movq %rbx, %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x4f38
movl %r15d, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
cmpl $0x2, %ecx
jl 0x65c7
movl 0x8(%rbx), %ecx
movl 0x10(%rbx), %r8d
leaq 0x473f(%rip), %rdx      # 0xacf7
movl $0x2, %esi
movq %r15, %r9
xorl %eax, %eax
callq 0x71fc
movq 0x78(%rbx), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movl $0x2, %edx
jmp 0x6443
nop