// File: /workspace/github_cpp_makefile_star2_O2/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)
orl $-0x1, 0x54(%rdi)
addq $0x58, %rdi
movq %rdx, %rsi
callq 0x40cbf6
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 0x40d9b0
pushq $0x6e
popq %rdi
callq 0x420b40
movq %rax, 0x48(%rbx)
leaq 0x2(%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x2(%rax)
movups %xmm0, 0x12(%rax)
movups %xmm0, 0x22(%rax)
movups %xmm0, 0x32(%rax)
movups %xmm0, 0x42(%rax)
movups %xmm0, 0x52(%rax)
movups %xmm0, 0x5e(%rax)
movw $0x1, (%rax)
movq 0x90(%rbx), %rsi
callq 0x4010a0
pushq $0x6e
jmp 0x40d9d4
pushq $0x10
popq %rdi
callq 0x420b40
movq %rax, 0x48(%rbx)
andq $0x0, 0x4(%rax)
andl $0x0, 0xc(%rax)
movw %bp, (%rax)
rolw $0x8, %r14w
movw %r14w, 0x2(%rax)
pushq $0x10
popq %rax
movl %eax, 0x50(%rbx)
movl 0x3c(%rbx), %edx
movl 0x40(%rbx), %esi
movl %ebp, %edi
callq 0x55a270
movl %eax, 0x34(%rbx)
pushq $0x2
popq %rdx
leaq 0x7(%rsp), %rcx
pushq $0x1
popq %rsi
movl %eax, %edi
movl %esi, %r8d
callq 0x55a200
cmpl $-0x1, 0x34(%rbx)
jne 0x40da75
movq $0x64eb00, %rdi         # imm = 0x64EB00
leaq 0x1b9742(%rip), %rsi    # 0x5c7153
callq 0x489b70
movq %rax, %r14
movq (%rbx), %rax
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq *0x8(%rax)
leaq 0x60(%rsp), %rsi
leaq 0x1ba273(%rip), %rdx    # 0x5c7ca6
leaq 0x8(%rsp), %rdi
callq 0x405349
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x49c3f0
leaq 0x1b965a(%rip), %rsi    # 0x5c70ab
movq %rax, %rdi
callq 0x489b70
movq %rax, %rdi
callq 0x489450
leaq 0x8(%rsp), %rdi
callq 0x499a70
leaq 0x28(%rsp), %rdi
callq 0x4050e8
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
jmp 0x40da93
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x499a70
leaq 0x28(%rsp), %rdi
callq 0x4050e8
movq %rbx, %rdi
callq 0x4ca950
nop