// File: /workspace/github_cpp_makefile_star2_O1/Unreality3D[P]Unreality3D/indie-studio/source/Network/sockets/Client.cpp
// Function: Socket::Client::start(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void  Client::start(std::string address, int port)
  {
    SOCKADDR_IN	addr;
    PROTOENT	*proto;

    // port checking
    if (port <= 0 || port > 0xFFFF)
      throw SocketCreateError(std::string("client : bad port"));
    _address = address;
    _port = port;

    // create socket
    proto = getprotobyname("tcp");

    if ((_fd = socket(AF_INET, SOCK_STREAM, proto ? proto->p_proto : 0)) == -1)
      throw SocketCreateError(std::string("client : ") +
			      std::string(strerror(getError())));

    if (!setNonBloccking(_fd))
      throw SocketCreateError(std::string("client : ") +
			      std::string("cannot set non blocking mode for the client fd"));

    // bind
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    if (inet_pton(AF_INET, address.c_str(), &addr.sin_addr) < 0)
      throw SocketConnectError("client : " + std::string(strerror(getError())));

    if (connect(_fd, (SOCKADDR *)&addr, sizeof(addr)) < 0)
      {
	if (errno != EINPROGRESS)
	  throw SocketConnectError("client : " + std::string(strerror(getError())));
      }

    // create select() sets
    FD_ZERO(&_fd_set);
    FD_SET(_fd, &_fd_set);

    // run the event loop
    _isRunning = true;
    if (!_stateThread.joinable())
      _stateThread = std::thread(&Client::stateChecker, this);

    // start event
    if (_OnStart)
      _OnStart(*this, _address, _port);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movl %edx, %r12d
movl $0xffff0000, %eax       # imm = 0xFFFF0000
leal (%r12,%rax), %ecx
cmpl %eax, %ecx
jbe 0x126d0
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0xb3e0
movl %r12d, 0x28(%rbx)
leaq 0x2f88(%rip), %rdi      # 0x154c2
callq 0xb2e0
testq %rax, %rax
je 0x12549
movl 0x10(%rax), %edx
jmp 0x1254b
xorl %edx, %edx
movl $0x2, %edi
movl $0x1, %esi
callq 0xb130
movl %eax, 0x2c(%rbx)
cmpl $-0x1, %eax
je 0x1272b
movl %eax, %ebp
movl %eax, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0xb410
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0xb410
cmpl $-0x1, %eax
je 0x127be
xorps %xmm0, %xmm0
leaq 0x54(%rsp), %rdx
movaps %xmm0, -0x4(%rdx)
movw $0x2, -0x4(%rdx)
rolw $0x8, %r12w
movw %r12w, -0x2(%rdx)
movq (%r15), %rsi
movl $0x2, %edi
callq 0xbdf0
testl %eax, %eax
js 0x12855
movl 0x2c(%rbx), %edi
leaq 0x50(%rsp), %rsi
movl $0x10, %edx
callq 0xb6a0
testl %eax, %eax
jns 0x125eb
callq 0xb070
cmpl $0x73, (%rax)
jne 0x128c6
xorps %xmm0, %xmm0
movups %xmm0, 0x158(%rbx)
movups %xmm0, 0x148(%rbx)
movups %xmm0, 0x138(%rbx)
movups %xmm0, 0x128(%rbx)
movups %xmm0, 0x118(%rbx)
movups %xmm0, 0x108(%rbx)
movups %xmm0, 0xf8(%rbx)
movups %xmm0, 0xe8(%rbx)
movl 0x2c(%rbx), %ecx
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movl %eax, %edx
andl $-0x40, %edx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0xe8(%rbx,%rax,8)
movb $0x1, %al
xchgb %al, 0x168(%rbx)
cmpq $0x0, 0x30(%rbx)
jne 0x12699
movq 0x8975(%rip), %rax      # 0x1afd8
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
leaq 0x48(%rsp), %rdx
movq %rbx, (%rdx)
leaq 0x28(%rsp), %rdi
callq 0xbd10
cmpq $0x0, 0x30(%rbx)
jne 0x12934
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rbx)
cmpq $0x0, 0xd8(%rbx)
je 0x126c0
leaq 0xc8(%rbx), %rdi
movl 0x28(%rbx), %eax
leaq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq %rbx, %rsi
movq %r14, %rdx
callq *0xe0(%rbx)
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x70(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2dc3(%rip), %rsi      # 0x154b0
leaq 0x2dcd(%rip), %rdx      # 0x154c1
leaq 0x60(%rsp), %rdi
callq 0xb270
movb $0x1, %bpl
leaq 0x60(%rsp), %rsi
movq %rbx, %rdi
callq 0xb960
xorl %ebp, %ebp
movq 0x88b9(%rip), %rsi      # 0x1afd0
movq 0x8872(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x12934
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2d7e(%rip), %rsi      # 0x154c6
leaq 0x2d80(%rip), %rdx      # 0x154cf
leaq 0x8(%rsp), %rdi
callq 0xb270
callq 0xb070
movl (%rax), %edi
callq 0xb1e0
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %rax, %rsi
callq 0xb290
leaq 0xe0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xb6b0
movb $0x1, %bpl
leaq 0xe0(%rsp), %rsi
movq %rbx, %rdi
callq 0xb960
xorl %ebp, %ebp
movq 0x8826(%rip), %rsi      # 0x1afd0
movq 0x87df(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x12934
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2ceb(%rip), %rsi      # 0x154c6
leaq 0x2ced(%rip), %rdx      # 0x154cf
leaq 0x8(%rsp), %rdi
callq 0xb270
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2cd3(%rip), %rsi      # 0x154d0
leaq 0x2cfa(%rip), %rdx      # 0x154fe
leaq 0x28(%rsp), %rdi
callq 0xb270
leaq 0xc0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xb6b0
movb $0x1, %bpl
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0xb960
xorl %ebp, %ebp
movq 0x878f(%rip), %rsi      # 0x1afd0
movq 0x8748(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x12934
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
callq 0xb070
movl (%rax), %edi
callq 0xb1e0
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rax, %rsi
callq 0xb290
leaq 0x2c3f(%rip), %rsi      # 0x154c6
leaq 0xa0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xbc30
movb $0x1, %bpl
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
callq 0xb830
xorl %ebp, %ebp
movq 0x86b3(%rip), %rsi      # 0x1af68
movq 0x86d4(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x12934
movq %rax, %r15
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
movl (%r15), %edi
callq 0xb1e0
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rax, %rsi
callq 0xb290
leaq 0x2bcf(%rip), %rsi      # 0x154c6
leaq 0x80(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xbc30
movb $0x1, %bpl
leaq 0x80(%rsp), %rsi
movq %rbx, %rdi
callq 0xb830
xorl %ebp, %ebp
movq 0x8643(%rip), %rsi      # 0x1af68
movq 0x8664(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
callq 0xb160
movq %rax, %r14
leaq 0x90(%rsp), %rax
jmp 0x129bb
jmp 0x129cb
movq %rax, %r14
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1296c
callq 0xb730
jmp 0x1296c
movq %rax, %r14
movb $0x1, %bpl
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
jne 0x129a7
jmp 0x129e9
movq %rax, %r14
leaq 0xf0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12999
callq 0xb730
jmp 0x12999
movq %rax, %r14
movb $0x1, %bpl
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x129e9
callq 0xb730
jmp 0x129e9
jmp 0x12a0a
movq %rax, %r14
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x129d1
callq 0xb730
jmp 0x129d1
movq %rax, %r14
movb $0x1, %bpl
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x12a03
jmp 0x12a10
jmp 0x129e3
movq %rax, %r14
movb $0x1, %bpl
movq 0x8(%rsp), %rdi
jmp 0x129fe
jmp 0x12a0a
jmp 0x12a0a
jmp 0x12a0a
movq %rax, %r14
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x12a10
callq 0xb730
jmp 0x12a10
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x12a1d
movq %rbx, %rdi
callq 0xb5b0
movq %r14, %rdi
callq 0xbce0
nop