// File: /workspace/github_cpp_makefile_star2_O3/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 0x410b04
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 0x411dbe
movl $0x6e, %edi
callq 0x427e10
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 0x4010a8
movl $0x6e, %eax
jmp 0x411ded
movl $0x10, %edi
callq 0x427e10
movq %rax, 0x48(%rbx)
movq $0x0, 0x4(%rax)
movl $0x0, 0xc(%rax)
movw %bp, (%rax)
rolw $0x8, %r14w
movw %r14w, 0x2(%rax)
movl $0x10, %eax
movl %eax, 0x50(%rbx)
movl 0x3c(%rbx), %edx
movl 0x40(%rbx), %esi
movl %ebp, %edi
callq 0x5609f0
movl %eax, 0x34(%rbx)
leaq 0x7(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x1, %r8d
callq 0x560980
cmpl $-0x1, 0x34(%rbx)
jne 0x411f2c
movq $0x653b20, %rdi         # imm = 0x653B20
leaq 0x1bc31f(%rip), %rsi    # 0x5ce153
movl $0x7, %edx
callq 0x490910
movq (%rbx), %rax
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq *0x8(%rax)
leaq 0x60(%rsp), %rdi
leaq 0x1bce99(%rip), %rsi    # 0x5cecf1
callq 0x4a24f0
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x411e84
movq %rsi, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x411e8e
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %r14, %rsi
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq $0x653b20, %rdi         # imm = 0x653B20
callq 0x490910
movq %rax, %rbx
leaq 0x1bc1ef(%rip), %rsi    # 0x5ce0ab
movl $0x4, %edx
movq %rax, %rdi
callq 0x490910
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x471a60
movsbl %al, %esi
movq %rbx, %rdi
callq 0x490410
movq %rax, %rdi
callq 0x48f9e0
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x411f07
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x426e30
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x411f22
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x426e30
leaq 0x28(%rsp), %rdi
callq 0x410332
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
jmp 0x411f57
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x411f57
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x426e30
leaq 0x28(%rsp), %rdi
callq 0x40512c
movq %rbx, %rdi
callq 0x4d10c0
nop