// File: enbock[P]Warp10Server/ulib/src/Socket.cpp
// Function: u::Socket::read(u::ByteArray*)
int64 u::Socket::read(ByteArray *data)
{
	int64 ret				// ammount of received bytes.
		, len					// maximum of read bytes
	;
	char *buffer;		// read buffer

	if(!isConnected()) return -1;

	if(!hasIncomingData()) return 0;

	// set pointer to end for append
	data->position(data->length());

	lock();
	len = receiveBufferSize;
	buffer = new char[len];

	ret = ::recv(_descriptor, buffer, len, 0);
	unlock();

	if(ret > 0)
	{
		data->writeBytes(buffer, ret);
	}

	delete[] buffer;

	data->position(0); // set pointer to begin

	trace(className()+"::read: Received "+int2string(ret)+" bytes.");
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x41aaf0
testb $0x1, %al
jne 0x41c0b4
movq $-0x1, -0x8(%rbp)
jmp 0x41c471
movq -0x168(%rbp), %rdi
callq 0x41c490
testb $0x1, %al
jne 0x41c0d1
movq $0x0, -0x8(%rbp)
jmp 0x41c471
movq -0x18(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq -0x170(%rbp), %rdi
movq %rax, %rsi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x168(%rbp), %rdi
callq 0x417410
movq -0x168(%rbp), %rax
movq 0xc0(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x434d10
movq %rax, %rcx
movq -0x168(%rbp), %rax
movq %rcx, -0x30(%rbp)
movl 0x34(%rax), %edi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
xorl %ecx, %ecx
callq 0x56e280
movq -0x168(%rbp), %rdi
movq %rax, -0x20(%rbp)
callq 0x417380
cmpq $0x0, -0x20(%rbp)
jle 0x41c169
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x40f3a0
movq -0x30(%rbp), %rax
movq %rax, -0x178(%rbp)
cmpq $0x0, %rax
je 0x41c186
movq -0x178(%rbp), %rdi
callq 0x433d00
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
xorl %ecx, %ecx
movl %ecx, %esi
callq *0x20(%rax)
movq $0x668c60, %rdi         # imm = 0x668C60
leaq 0x1beeef(%rip), %rsi    # 0x5db091
callq 0x49dd60
movq %rax, -0x180(%rbp)
movb $0x0, -0xe9(%rbp)
movb $0x0, -0xfd(%rbp)
movb $0x0, -0x159(%rbp)
movb $0x0, -0x15a(%rbp)
movb $0x0, -0x15c(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x41c1dc
jmp 0x41c26d
movq -0x168(%rbp), %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0xe8(%rbp), %rdi
callq *%rax
movb $0x1, -0xe9(%rbp)
leaq -0xb0(%rbp), %rsi
leaq 0x1c0402(%rip), %rdx    # 0x5dc60a
leaq -0x90(%rbp), %rdi
callq 0x405d00
jmp 0x41c216
movb $0x1, -0xfd(%rbp)
movl -0x20(%rbp), %esi
leaq -0x158(%rbp), %rdi
callq 0x4178a0
jmp 0x41c22e
movb $0x1, -0x159(%rbp)
leaq -0x120(%rbp), %rdx
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x409d40
jmp 0x41c24e
movb $0x1, -0x15a(%rbp)
leaq 0x1c036c(%rip), %rdx    # 0x5dc5c8
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x405d00
jmp 0x41c26b
jmp 0x41c2a2
leaq -0x15b(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x435b90
movq -0x188(%rbp), %rdx
movb $0x1, -0x15c(%rbp)
leaq 0x1e470d(%rip), %rsi    # 0x6009a2
leaq -0x50(%rbp), %rdi
callq 0x407e60
jmp 0x41c2a0
jmp 0x41c2a2
movq -0x180(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4b05e0
movq %rax, -0x190(%rbp)
jmp 0x41c2bb
movq -0x190(%rbp), %rdi
leaq 0x1bee07(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0x198(%rbp)
jmp 0x41c2d7
movq -0x198(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x41c2ec
leaq -0x50(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x15c(%rbp)
jne 0x41c300
jmp 0x41c30c
leaq -0x15b(%rbp), %rdi
callq 0x435bb0
testb $0x1, -0x15a(%rbp)
jne 0x41c317
jmp 0x41c320
leaq -0x70(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x159(%rbp)
jne 0x41c32b
jmp 0x41c337
leaq -0x158(%rbp), %rdi
callq 0x405650
testb $0x1, -0xfd(%rbp)
jne 0x41c342
jmp 0x41c34e
leaq -0x90(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0xe9(%rbp)
jne 0x41c359
jmp 0x41c365
leaq -0xe8(%rbp), %rdi
callq 0x405650
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x41c471
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x41c458
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x41c43f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x41c426
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x41c410
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x41c3f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0x15c(%rbp)
jne 0x41c402
jmp 0x41c40e
leaq -0x15b(%rbp), %rdi
callq 0x435bb0
jmp 0x41c410
testb $0x1, -0x15a(%rbp)
jne 0x41c41b
jmp 0x41c424
leaq -0x70(%rbp), %rdi
callq 0x4adc60
jmp 0x41c426
testb $0x1, -0x159(%rbp)
jne 0x41c431
jmp 0x41c43d
leaq -0x158(%rbp), %rdi
callq 0x405650
jmp 0x41c43f
testb $0x1, -0xfd(%rbp)
jne 0x41c44a
jmp 0x41c456
leaq -0x90(%rbp), %rdi
callq 0x4adc60
jmp 0x41c458
testb $0x1, -0xe9(%rbp)
jne 0x41c463
jmp 0x41c46f
leaq -0xe8(%rbp), %rdi
callq 0x405650
jmp 0x41c47e
movq -0x8(%rbp), %rax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0xf8(%rbp), %rdi
callq 0x4deb40
nopw (%rax,%rax)