// File: enbock[P]Warp10Server/ulib/src/Socket.cpp
// Function: u::Socket::init(int, u::String, long, int, int)
void u::Socket::init(
	int32 domain
	, String hostname
	, int64 port
	, int32 type
	, int32 protocol
)
{
	//trace("Max connections: " + int2string(FD_SETSIZE));
	char reuse = 1;

	_type = type;
	_domain = domain;
	_protocol = protocol;
	_con = -1;
	_hostname = hostname;
	_port = port;
	maxWaitingClients = SOCKET_MAX_CLIENTS;
	receiveBufferSize = SOCKET_RECV_BUFFER;
	_neverUsed = true;
	_isSending = false;

	switch(_domain)
	{
		case AF_UNIX:
		{
			//trace("Create file socket at "+_hostname);
			_addr = new (struct sockaddr_un);

			memset(_addr, 0, sizeof(struct sockaddr_un));

			((struct sockaddr_un *)_addr)->sun_family = _domain;
			strcpy(
				((struct sockaddr_un *)_addr)->sun_path
				, _hostname.c_str()
			);
			_addrLen = sizeof(*((struct sockaddr_un *)_addr));

		} break;
		default:
		{
			_addr = new (struct sockaddr_in);
			_addrLen = sizeof(struct sockaddr_in);
			memset(_addr, 0, _addrLen);
			((struct sockaddr_in *)_addr)->sin_family = _domain;
			((struct sockaddr_in *)_addr)->sin_port = htons(_port);
		} break;
	}

	_descriptor = ::socket(_domain, _type, _protocol);
	::setsockopt(_descriptor, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse));

	if(_descriptor == -1) error(className()+": Socket creation error.");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdx, -0xd0(%rbp)
movl %esi, %eax
movq -0xd0(%rbp), %rsi
movq %rdi, -0x8(%rbp)
movl %eax, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
movb $0x1, -0x29(%rbp)
movl -0x24(%rbp), %eax
movl %eax, 0x40(%rdi)
movl -0xc(%rbp), %eax
movl %eax, 0x38(%rdi)
movl -0x28(%rbp), %eax
movl %eax, 0x3c(%rdi)
movl $0xffffffff, 0x54(%rdi) # imm = 0xFFFFFFFF
addq $0x58, %rdi
callq 0x4180d0
movq -0xc8(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0xb0(%rax)
movl $0xc350, 0xbc(%rax)     # imm = 0xC350
movq $0x400, 0xc0(%rax) # imm = 0x400
movb $0x1, 0xb8(%rax)
movb $0x0, 0xb9(%rax)
movl 0x38(%rax), %eax
subl $0x1, %eax
jne 0x41a5c9
jmp 0x41a552
movl $0x6e, %edi
callq 0x434cd0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq 0x48(%rax), %rdi
xorl %esi, %esi
movl $0x6e, %edx
callq 0x401090
movq -0xc8(%rbp), %rdi
movl 0x38(%rdi), %eax
movw %ax, %cx
movq 0x48(%rdi), %rax
movw %cx, (%rax)
movq 0x48(%rdi), %rax
addq $0x2, %rax
movq %rax, -0xd8(%rbp)
addq $0x58, %rdi
addq $0x38, %rdi
callq 0x4af6a0
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0x4010a0
movq -0xc8(%rbp), %rax
movl $0x6e, 0x50(%rax)
jmp 0x41a62d
movl $0x10, %edi
callq 0x434cd0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, 0x48(%rax)
movl $0x10, 0x50(%rax)
movq 0x48(%rax), %rdi
movl 0x50(%rax), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x401090
movq -0xc8(%rbp), %rax
movl 0x38(%rax), %ecx
movw %cx, %dx
movq 0x48(%rax), %rcx
movw %dx, (%rcx)
movq 0xb0(%rax), %rax
movzwl %ax, %edi
callq 0x56ee70
movw %ax, %cx
movq -0xc8(%rbp), %rax
movq 0x48(%rax), %rax
movw %cx, 0x2(%rax)
movq -0xc8(%rbp), %rax
movl 0x38(%rax), %edi
movl 0x40(%rax), %esi
movl 0x3c(%rax), %edx
callq 0x56e470
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movl %ecx, 0x34(%rax)
movl 0x34(%rax), %edi
movl $0x1, %r8d
movl $0x2, %edx
leaq -0x29(%rbp), %rcx
movl %r8d, %esi
callq 0x56e400
movq -0xc8(%rbp), %rax
cmpl $-0x1, 0x34(%rax)
jne 0x41a80c
movq $0x668b40, %rdi         # imm = 0x668B40
leaq 0x1c0b99(%rip), %rsi    # 0x5db220
callq 0x49dd60
movq %rax, -0xe0(%rbp)
movb $0x0, -0xa9(%rbp)
movb $0x0, -0xbe(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x41a6a9
jmp 0x41a6df
movq -0xc8(%rbp), %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0xa8(%rbp), %rdi
callq *%rax
movb $0x1, -0xa9(%rbp)
leaq -0x70(%rbp), %rsi
leaq 0x1c1cd8(%rip), %rdx    # 0x5dc3aa
leaq -0x50(%rbp), %rdi
callq 0x405d00
jmp 0x41a6dd
jmp 0x41a714
leaq -0xbd(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x435b90
movq -0xe8(%rbp), %rdx
movb $0x1, -0xbe(%rbp)
leaq 0x1e629b(%rip), %rsi    # 0x6009a2
leaq -0x50(%rbp), %rdi
callq 0x407e60
jmp 0x41a712
jmp 0x41a714
movq -0xe0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4b05e0
movq %rax, -0xf0(%rbp)
jmp 0x41a72d
movq -0xf0(%rbp), %rdi
leaq 0x1c0995(%rip), %rsi    # 0x5db0d0
callq 0x49dd60
movq %rax, -0xf8(%rbp)
jmp 0x41a749
movq -0xf8(%rbp), %rdi
movq $0x49d640, %rsi         # imm = 0x49D640
callq 0x49c850
jmp 0x41a75e
leaq -0x50(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0xbe(%rbp)
jne 0x41a772
jmp 0x41a77e
leaq -0xbd(%rbp), %rdi
callq 0x435bb0
testb $0x1, -0xa9(%rbp)
jne 0x41a789
jmp 0x41a795
leaq -0xa8(%rbp), %rdi
callq 0x405650
jmp 0x41a80c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x41a7f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x41a7da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4adc60
testb $0x1, -0xbe(%rbp)
jne 0x41a7e5
jmp 0x41a7f1
leaq -0xbd(%rbp), %rdi
callq 0x435bb0
jmp 0x41a7f3
testb $0x1, -0xa9(%rbp)
jne 0x41a7fe
jmp 0x41a80a
leaq -0xa8(%rbp), %rdi
callq 0x405650
jmp 0x41a815
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xb8(%rbp), %rdi
callq 0x4deb40
nopw %cs:(%rax,%rax)