// File: /workspace/github_cpp_makefile_star2_O2/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 0x156f0
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0xf590
movl %r12d, 0x28(%rbx)
leaq 0x2eea(%rip), %rdi      # 0x18482
callq 0xf420
testq %rax, %rax
je 0x155a7
movl 0x10(%rax), %edx
jmp 0x155a9
xorl %edx, %edx
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
callq 0xf1e0
movl %eax, 0x2c(%rbx)
cmpl $-0x1, %eax
je 0x15744
movl %eax, %ebp
pushq $0x3
popq %rsi
movl %eax, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0xf600
orl $0x800, %eax            # imm = 0x800
pushq $0x4
popq %rsi
movl %ebp, %edi
movl %eax, %edx
xorl %eax, %eax
callq 0xf600
cmpl $-0x1, %eax
je 0x157ca
leaq 0x54(%rsp), %rdx
andl $0x0, 0x8(%rdx)
andq $0x0, (%rdx)
movw $0x2, -0x4(%rdx)
rolw $0x8, %r12w
movw %r12w, -0x2(%rdx)
movq (%r15), %rsi
pushq $0x2
popq %rdi
callq 0x10450
testl %eax, %eax
js 0x15848
movl 0x2c(%rbx), %edi
leaq 0x50(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0xf990
testl %eax, %eax
jns 0x1563e
callq 0xf070
cmpl $0x73, (%rax)
jne 0x158b7
pushq $0x1d
popq %rax
cmpq $0x2d, %rax
je 0x15651
andq $0x0, (%rbx,%rax,8)
incq %rax
jmp 0x15641
movl 0x2c(%rbx), %ecx
pushq $0x40
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
movslq %eax, %rdx
shll $0x6, %eax
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, 0xe8(%rbx,%rdx,8)
movb $0x1, %al
xchgb %al, 0x168(%rbx)
cmpq $0x0, 0x30(%rbx)
jne 0x156c1
movq 0x9950(%rip), %rax      # 0x1efd8
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
leaq 0x30(%rbx), %r15
leaq 0x28(%rsp), %rdx
movq %rbx, (%rdx)
leaq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x10330
movq %r15, %rdi
movq %r12, %rsi
callq 0x101a0
movq %r12, %rdi
callq 0x10040
cmpq $0x0, 0xd8(%rbx)
je 0x156e0
leaq 0xc8(%rbx), %rdi
movl 0x28(%rbx), %ecx
movq %rbx, %rsi
movq %r14, %rdx
callq 0xf7e0
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
leaq 0x2d6e(%rip), %rsi      # 0x18470
leaq 0xe0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xf3f0
movb $0x1, %bpl
leaq 0xe0(%rsp), %rsi
movq %rbx, %rdi
callq 0xfd80
xorl %ebp, %ebp
movq 0x98a0(%rip), %rsi      # 0x1efd0
movq 0x9859(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
jmp 0x1591e
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
leaq 0x2d30(%rip), %rsi      # 0x18486
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0xf3f0
callq 0x159ad
movl %eax, %edi
callq 0xf330
leaq 0x30(%rsp), %rdi
leaq 0x7(%rsp), %rdx
movq %rax, %rsi
callq 0xf3f0
leaq 0xc0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0xf9a0
movb $0x1, %bpl
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0xfd80
xorl %ebp, %ebp
movq 0x981a(%rip), %rsi      # 0x1efd0
movq 0x97d3(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
jmp 0x1591e
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
leaq 0x2caa(%rip), %rsi      # 0x18486
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0xf3f0
leaq 0x2c9e(%rip), %rsi      # 0x18490
leaq 0x30(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0xf3f0
leaq 0xa0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0xf9a0
movb $0x1, %bpl
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
callq 0xfd80
xorl %ebp, %ebp
movq 0x979c(%rip), %rsi      # 0x1efd0
movq 0x9755(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
jmp 0x1591e
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
callq 0x159ad
movl %eax, %edi
callq 0xf330
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %rax, %rsi
callq 0xf3f0
leaq 0x2c0e(%rip), %rsi      # 0x18486
leaq 0x80(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x10210
movb $0x1, %bpl
leaq 0x80(%rsp), %rsi
movq %rbx, %rdi
callq 0xfb90
xorl %ebp, %ebp
movq 0x96c2(%rip), %rsi      # 0x1ef68
movq 0x96e3(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
jmp 0x1591e
pushq $0x48
popq %rdi
callq 0xf4d0
movq %rax, %rbx
callq 0x159ad
movl %eax, %edi
callq 0xf330
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %rax, %rsi
callq 0xf3f0
leaq 0x2b9f(%rip), %rsi      # 0x18486
leaq 0x60(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x10210
movb $0x1, %bpl
leaq 0x60(%rsp), %rsi
movq %rbx, %rdi
callq 0xfb90
xorl %ebp, %ebp
movq 0x9659(%rip), %rsi      # 0x1ef68
movq 0x967a(%rip), %rdx      # 0x1ef90
movq %rbx, %rdi
callq 0x10260
movq %rax, %r14
leaq 0x60(%rsp), %rdi
jmp 0x15965
jmp 0x15970
movq %rax, %r14
leaq 0xa0(%rsp), %rdi
jmp 0x15944
jmp 0x1594b
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0xf450
jmp 0x15951
movq %rax, %r14
movb $0x1, %bpl
leaq 0x30(%rsp), %rdi
jmp 0x15965
jmp 0x1599a
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0xf450
jmp 0x15976
jmp 0x15970
jmp 0x15970
movq %rax, %r14
movb $0x1, %bpl
leaq 0x8(%rsp), %rdi
jmp 0x1598e
jmp 0x1599a
jmp 0x1599a
jmp 0x1599a
movq %rax, %r14
leaq 0xe0(%rsp), %rdi
callq 0xf450
testb %bpl, %bpl
jne 0x1599d
jmp 0x159a5
movq %rax, %r14
movq %rbx, %rdi
callq 0xf820
movq %r14, %rdi
callq 0x102f0