// File: /workspace/github_cpp_makefile_star2_O2/enbock[P]Warp10Server/ulib/src/Socket.cpp
// Function: u::Socket::send(u::ByteArray*)
int64 u::Socket::send(ByteArray *data)
{
	int64 len				// ammount of byte to send
		, ret					// number of sent bytes
		, pos					// position of the array pointer before send
	;
	char *buffer;		// send buffer

	if(!isConnected()) return -1;
	lock();
	if(_isSending == true) {
		unlock();
		return 0;
	}
	_isSending = true;

	pos = data->position();
	len = data->bytesAvailable();
	buffer = new char[len];
	len = data->readBytes(buffer, len);
	// MSG_NOSIGNAL protected an illegal memory exception on interupted sockets
	ret = ::send(_descriptor, buffer, len, MSG_NOSIGNAL);

	if(ret == -1)
	{
		error(className()+"::send: Sending failed.");
		data->position(pos);
	}
	else
	{
		data->position(pos+ret);
	}

	delete[] buffer;
	_isSending = false;
	unlock();

	trace(
		className() + "::send: Sent " + int2string(ret) + " bytes of "
		+ int2string(len) + " bytes."
	);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rsi, %r12
movq %rdi, %r15
callq 0x40dc34
testb %al, %al
je 0x40e291
movq %r15, %rdi
callq 0x40c442
cmpb $0x1, 0xb9(%r15)
jne 0x40e299
movq %r15, %rdi
callq 0x40c3fe
xorl %ebx, %ebx
jmp 0x40e4e8
pushq $-0x1
popq %rbx
jmp 0x40e4e8
movb $0x1, 0xb9(%r15)
movq (%r12), %rax
movq %r12, %rdi
callq *0x28(%rax)
movq %rax, %r13
movq %r12, %rdi
callq 0x409a36
movq %rax, %rbx
movq %rax, %rdi
callq 0x420b80
movq %rax, %rbp
movq %r12, %rdi
movq %rax, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x40966e
movl 0x34(%r15), %edi
movq %rbp, %rsi
movq %rax, 0x8(%rsp)
movq %rax, %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x55a140
movq %rax, %rbx
cmpq $-0x1, %rax
je 0x40e2fe
addq %rbx, %r13
jmp 0x40e382
movq $0x64eb00, %rdi         # imm = 0x64EB00
leaq 0x1b8e47(%rip), %rsi    # 0x5c7153
callq 0x489b70
movq %rax, %r14
movq (%r15), %rax
leaq 0x108(%rsp), %rdi
movq %r15, %rsi
callq *0x8(%rax)
leaq 0x140(%rsp), %rsi
leaq 0x1b99f7(%rip), %rdx    # 0x5c7d2b
leaq 0xb0(%rsp), %rdi
callq 0x405349
leaq 0xb0(%rsp), %rsi
movq %r14, %rdi
callq 0x49c3f0
leaq 0x1b8d53(%rip), %rsi    # 0x5c70ab
movq %rax, %rdi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
leaq 0xb0(%rsp), %rdi
callq 0x499a70
leaq 0x108(%rsp), %rdi
callq 0x4050e8
movq (%r12), %rax
movq %r12, %rdi
movq %r13, %rsi
callq *0x20(%rax)
movq %rbp, %rdi
callq 0x41fb70
movb $0x0, 0xb9(%r15)
movq %r15, %rdi
callq 0x40c3fe
movq $0x64ec20, %rdi         # imm = 0x64EC20
leaq 0x1b8cdc(%rip), %rsi    # 0x5c7091
callq 0x489b70
movq %rax, %r12
movq (%r15), %rax
leaq 0x108(%rsp), %rdi
movq %r15, %rsi
callq *0x8(%rax)
leaq 0x140(%rsp), %rsi
leaq 0x1b9966(%rip), %rdx    # 0x5c7d43
leaq 0x10(%rsp), %rdi
callq 0x405349
leaq 0xb0(%rsp), %rdi
movl %ebx, %esi
callq 0x40c712
leaq 0xe8(%rsp), %rdx
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x406c55
leaq 0x1b993d(%rip), %rdx    # 0x5c7d51
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x405349
leaq 0x160(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x40c712
leaq 0x198(%rsp), %rdx
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x406c55
leaq 0x1b9909(%rip), %rdx    # 0x5c7d5c
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x405349
leaq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x49c3f0
leaq 0x1b8c2f(%rip), %rsi    # 0x5c70ab
movq %rax, %rdi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
leaq 0x90(%rsp), %rdi
callq 0x499a70
leaq 0x70(%rsp), %rdi
callq 0x499a70
leaq 0x160(%rsp), %rdi
callq 0x4050e8
leaq 0x50(%rsp), %rdi
callq 0x499a70
leaq 0x30(%rsp), %rdi
callq 0x499a70
leaq 0xb0(%rsp), %rdi
callq 0x4050e8
leaq 0x10(%rsp), %rdi
callq 0x499a70
leaq 0x108(%rsp), %rdi
callq 0x4050e8
movq %rbx, %rax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x40e51d
movq %rax, %rbx
jmp 0x40e53f
movq %rax, %rbx
jmp 0x40e549
movq %rax, %rbx
jmp 0x40e556
movq %rax, %rbx
jmp 0x40e560
movq %rax, %rbx
jmp 0x40e56a
movq %rax, %rbx
jmp 0x40e577
movq %rax, %rbx
jmp 0x40e581
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
jmp 0x40e57c
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x499a70
leaq 0x70(%rsp), %rdi
callq 0x499a70
leaq 0x160(%rsp), %rdi
callq 0x4050e8
leaq 0x50(%rsp), %rdi
callq 0x499a70
leaq 0x30(%rsp), %rdi
callq 0x499a70
leaq 0xb0(%rsp), %rdi
callq 0x4050e8
leaq 0x10(%rsp), %rdi
callq 0x499a70
leaq 0x108(%rsp), %rdi
callq 0x4050e8
movq %rbx, %rdi
callq 0x4ca950