// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r14
pushq %rbx
subq $0x80, %rsp
movq %rcx, %r14
movq %rdi, %rbx
movb $0x1, 0x7(%rsp)
movl %r8d, 0x40(%rdi)
movl %esi, 0x38(%rdi)
movl %r9d, 0x3c(%rdi)
movl $0xffffffff, 0x54(%rdi) # imm = 0xFFFFFFFF
addq $0x58, %rdi
movq %rdx, %rsi
callq 0x410b12
movq %r14, 0xb0(%rbx)
movl $0xc350, 0xbc(%rbx)     # imm = 0xC350
movq $0x400, 0xc0(%rbx) # imm = 0x400
movw $0x1, 0xb8(%rbx)
movl 0x38(%rbx), %ebp
cmpl $0x1, %ebp
jne 0x411dcb
movl $0x6e, %edi
callq 0x427f00
movq %rax, 0x48(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x5e(%rax)
movw $0x1, (%rax)
leaq 0x2(%rax), %rdi
movq 0x90(%rbx), %rsi
callq 0x4010a8
movl $0x6e, 0x50(%rbx)
jmp 0x411df3
movl $0x10, %edi
callq 0x427f00
movq %rax, 0x48(%rbx)
movl $0x10, 0x50(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movw %bp, (%rax)
rolw $0x8, %r14w
movw %r14w, 0x2(%rax)
movl 0x3c(%rbx), %edx
movl 0x40(%rbx), %esi
movl %ebp, %edi
callq 0x560ab0
movl %eax, 0x34(%rbx)
leaq 0x7(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x1, %r8d
callq 0x560a40
cmpl $-0x1, 0x34(%rbx)
jne 0x411f36
movq $0x653b20, %rdi         # imm = 0x653B20
leaq 0x1bc31c(%rip), %rsi    # 0x5ce153
movl $0x7, %edx
callq 0x490a00
movq (%rbx), %rax
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq *0x8(%rax)
leaq 0x60(%rsp), %rdi
leaq 0x1bce96(%rip), %rsi    # 0x5cecf1
callq 0x4a25e0
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x411e87
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x411e8e
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq $0x653b20, %rdi         # imm = 0x653B20
callq 0x490a00
movq %rax, %rbx
leaq 0x1bc1e5(%rip), %rsi    # 0x5ce0ab
movl $0x4, %edx
movq %rax, %rdi
callq 0x490a00
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x471b50
movsbl %al, %esi
movq %rbx, %rdi
callq 0x490500
movq %rax, %rdi
callq 0x48fad0
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x411f11
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x426f20
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x411f2c
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x426f20
leaq 0x28(%rsp), %rdi
callq 0x410354
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
jmp 0x411f61
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x411f61
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x426f20
leaq 0x28(%rsp), %rdi
callq 0x40512a
movq %rbx, %rdi
callq 0x4d11b0
nop