// File: 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
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x41aaf0
testb $0x1, %al
jne 0x41b984
movq $-0x1, -0x8(%rbp)
jmp 0x41c066
movq -0x290(%rbp), %rdi
callq 0x417410
movq -0x290(%rbp), %rax
movb 0xb9(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x41b9c0
movq -0x290(%rbp), %rdi
callq 0x417380
movq $0x0, -0x8(%rbp)
jmp 0x41c066
movq -0x290(%rbp), %rax
movb $0x1, 0xb9(%rax)
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x410610
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x434d10
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x40ff80
movq %rax, %rcx
movq -0x290(%rbp), %rax
movq %rcx, -0x20(%rbp)
movl 0x34(%rax), %edi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x56e340
movq %rax, -0x28(%rbp)
cmpq $-0x1, -0x28(%rbp)
jne 0x41bbe4
movq $0x668b40, %rdi         # imm = 0x668B40
leaq 0x1bf7d5(%rip), %rsi    # 0x5db220
callq 0x49dd60
movq %rax, -0x298(%rbp)
movb $0x0, -0xb1(%rbp)
movb $0x0, -0xc6(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x41ba6d
jmp 0x41baa3
movq -0x290(%rbp), %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0xb0(%rbp), %rdi
callq *%rax
movb $0x1, -0xb1(%rbp)
leaq -0x78(%rbp), %rsi
leaq 0x1c0aa4(%rip), %rdx    # 0x5dc53a
leaq -0x58(%rbp), %rdi
callq 0x405d00
jmp 0x41baa1
jmp 0x41bad8
leaq -0xc5(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x435b90
movq -0x2a0(%rbp), %rdx
movb $0x1, -0xc6(%rbp)
leaq 0x1e4ed7(%rip), %rsi    # 0x6009a2
leaq -0x58(%rbp), %rdi
callq 0x407e60
jmp 0x41bad6
jmp 0x41bad8
movq -0x298(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x4b05e0
movq %rax, -0x2a8(%rbp)
jmp 0x41baf1
movq -0x2a8(%rbp), %rdi
leaq 0x1bf5d1(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0x2b0(%rbp)
jmp 0x41bb0d
movq -0x2b0(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x41bb22
leaq -0x58(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0xc6(%rbp)
jne 0x41bb36
jmp 0x41bb42
leaq -0xc5(%rbp), %rdi
callq 0x435bb0
testb $0x1, -0xb1(%rbp)
jne 0x41bb4d
jmp 0x41bb59
leaq -0xb0(%rbp), %rdi
callq 0x405650
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
jmp 0x41bbf6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41bbc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41bbaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0xc6(%rbp)
jne 0x41bbba
jmp 0x41bbc6
leaq -0xc5(%rbp), %rdi
callq 0x435bb0
jmp 0x41bbc8
testb $0x1, -0xb1(%rbp)
jne 0x41bbd3
jmp 0x41bbdf
leaq -0xb0(%rbp), %rdi
callq 0x405650
jmp 0x41c073
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq -0x28(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x2b8(%rbp)
cmpq $0x0, %rax
je 0x41bc13
movq -0x2b8(%rbp), %rdi
callq 0x433d00
movq -0x290(%rbp), %rdi
movb $0x0, 0xb9(%rdi)
callq 0x417380
movq $0x668c60, %rdi         # imm = 0x668C60
leaq 0x1bf45d(%rip), %rsi    # 0x5db091
callq 0x49dd60
movq %rax, -0x2c0(%rbp)
movb $0x0, -0x1c1(%rbp)
movb $0x0, -0x1c2(%rbp)
movb $0x0, -0x221(%rbp)
movb $0x0, -0x222(%rbp)
movb $0x0, -0x223(%rbp)
movb $0x0, -0x281(%rbp)
movb $0x0, -0x282(%rbp)
movb $0x0, -0x284(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x41bc83
jmp 0x41bd7b
movq -0x290(%rbp), %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0x1c0(%rbp), %rdi
callq *%rax
movb $0x1, -0x1c1(%rbp)
leaq -0x188(%rbp), %rsi
leaq 0x1c0900(%rip), %rdx    # 0x5dc5af
leaq -0x168(%rbp), %rdi
callq 0x405d00
jmp 0x41bcbd
movb $0x1, -0x1c2(%rbp)
movl -0x28(%rbp), %esi
leaq -0x220(%rbp), %rdi
callq 0x4178a0
jmp 0x41bcd5
movb $0x1, -0x221(%rbp)
leaq -0x1e8(%rbp), %rdx
leaq -0x148(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x409d40
jmp 0x41bcf8
movb $0x1, -0x222(%rbp)
leaq 0x1c08b7(%rip), %rdx    # 0x5dc5bd
leaq -0x128(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x405d00
jmp 0x41bd1b
movb $0x1, -0x223(%rbp)
movl -0x20(%rbp), %esi
leaq -0x280(%rbp), %rdi
callq 0x4178a0
jmp 0x41bd33
movb $0x1, -0x281(%rbp)
leaq -0x248(%rbp), %rdx
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x409d40
jmp 0x41bd56
movb $0x1, -0x282(%rbp)
leaq 0x1c0864(%rip), %rdx    # 0x5dc5c8
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x405d00
jmp 0x41bd79
jmp 0x41bdb3
leaq -0x283(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x435b90
movq -0x2c8(%rbp), %rdx
movb $0x1, -0x284(%rbp)
leaq 0x1e4bff(%rip), %rsi    # 0x6009a2
leaq -0xe8(%rbp), %rdi
callq 0x407e60
jmp 0x41bdb1
jmp 0x41bdb3
movq -0x2c0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x4b05e0
movq %rax, -0x2d0(%rbp)
jmp 0x41bdcf
movq -0x2d0(%rbp), %rdi
leaq 0x1bf2f3(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0x2d8(%rbp)
jmp 0x41bdeb
movq -0x2d8(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x41be00
leaq -0xe8(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x284(%rbp)
jne 0x41be17
jmp 0x41be23
leaq -0x283(%rbp), %rdi
callq 0x435bb0
testb $0x1, -0x282(%rbp)
jne 0x41be2e
jmp 0x41be3a
leaq -0x108(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x281(%rbp)
jne 0x41be45
jmp 0x41be51
leaq -0x280(%rbp), %rdi
callq 0x405650
testb $0x1, -0x223(%rbp)
jne 0x41be5c
jmp 0x41be68
leaq -0x128(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x222(%rbp)
jne 0x41be73
jmp 0x41be7f
leaq -0x148(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x221(%rbp)
jne 0x41be8a
jmp 0x41be96
leaq -0x220(%rbp), %rdi
callq 0x405650
testb $0x1, -0x1c2(%rbp)
jne 0x41bea1
jmp 0x41bead
leaq -0x168(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x1c1(%rbp)
jne 0x41beb8
jmp 0x41bec4
leaq -0x1c0(%rbp), %rdi
callq 0x405650
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x41c066
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41c04d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41c034
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41c01b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41c002
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41bfe9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41bfd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41bfb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x41bf9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x284(%rbp)
jne 0x41bfa9
jmp 0x41bfb5
leaq -0x283(%rbp), %rdi
callq 0x435bb0
jmp 0x41bfb7
testb $0x1, -0x282(%rbp)
jne 0x41bfc2
jmp 0x41bfce
leaq -0x108(%rbp), %rdi
callq 0x4adc60
jmp 0x41bfd0
testb $0x1, -0x281(%rbp)
jne 0x41bfdb
jmp 0x41bfe7
leaq -0x280(%rbp), %rdi
callq 0x405650
jmp 0x41bfe9
testb $0x1, -0x223(%rbp)
jne 0x41bff4
jmp 0x41c000
leaq -0x128(%rbp), %rdi
callq 0x4adc60
jmp 0x41c002
testb $0x1, -0x222(%rbp)
jne 0x41c00d
jmp 0x41c019
leaq -0x148(%rbp), %rdi
callq 0x4adc60
jmp 0x41c01b
testb $0x1, -0x221(%rbp)
jne 0x41c026
jmp 0x41c032
leaq -0x220(%rbp), %rdi
callq 0x405650
jmp 0x41c034
testb $0x1, -0x1c2(%rbp)
jne 0x41c03f
jmp 0x41c04b
leaq -0x168(%rbp), %rdi
callq 0x4adc60
jmp 0x41c04d
testb $0x1, -0x1c1(%rbp)
jne 0x41c058
jmp 0x41c064
leaq -0x1c0(%rbp), %rdi
callq 0x405650
jmp 0x41c073
movq -0x8(%rbp), %rax
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x4deb40
nop