// File: /workspace/github_cpp_makefile_star2_O3/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 0x125a7
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0xb3e0
movl %r12d, 0x28(%rbx)
leaq 0x30b8(%rip), %rdi      # 0x154c2
callq 0xb2e0
testq %rax, %rax
je 0x12419
movl 0x10(%rax), %edx
jmp 0x1241b
xorl %edx, %edx
movl $0x2, %edi
movl $0x1, %esi
callq 0xb130
movl %eax, 0x2c(%rbx)
cmpl $-0x1, %eax
je 0x12602
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 0x12695
leaq 0x74(%rsp), %rdx
movl $0x0, 0x8(%rdx)
movq $0x0, (%rdx)
movw $0x2, -0x4(%rdx)
rolw $0x8, %r12w
movw %r12w, -0x2(%rdx)
movq (%r15), %rsi
movl $0x2, %edi
callq 0xbdf0
testl %eax, %eax
js 0x1272c
movl 0x2c(%rbx), %edi
leaq 0x70(%rsp), %rsi
movl $0x10, %edx
callq 0xb6a0
testl %eax, %eax
jns 0x124c2
callq 0xb070
cmpl $0x73, (%rax)
jne 0x1279d
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 0x12570
movq 0x8a9e(%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 0x1280b
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rbx)
cmpq $0x0, 0xd8(%rbx)
je 0x12597
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 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2eec(%rip), %rsi      # 0x154b0
leaq 0x2ef6(%rip), %rdx      # 0x154c1
leaq 0x50(%rsp), %rdi
callq 0xb270
movb $0x1, %bpl
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0xb960
xorl %ebp, %ebp
movq 0x89e2(%rip), %rsi      # 0x1afd0
movq 0x899b(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x1280b
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2ea7(%rip), %rsi      # 0x154c6
leaq 0x2ea9(%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 0x894f(%rip), %rsi      # 0x1afd0
movq 0x8908(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x1280b
movl $0x48, %edi
callq 0xb360
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2e14(%rip), %rsi      # 0x154c6
leaq 0x2e16(%rip), %rdx      # 0x154cf
leaq 0x8(%rsp), %rdi
callq 0xb270
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2dfc(%rip), %rsi      # 0x154d0
leaq 0x2e23(%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 0x88b8(%rip), %rsi      # 0x1afd0
movq 0x8871(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x1280b
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 0x2d68(%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 0x87dc(%rip), %rsi      # 0x1af68
movq 0x87fd(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
jmp 0x1280b
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 0x2cf8(%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 0x876c(%rip), %rsi      # 0x1af68
movq 0x878d(%rip), %rdx      # 0x1af90
movq %rbx, %rdi
callq 0xbc70
callq 0xb160
movq %rax, %r14
leaq 0x90(%rsp), %rax
jmp 0x12897
jmp 0x128b5
movq %rax, %r14
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12843
callq 0xb730
jmp 0x12843
movq %rax, %r14
movb $0x1, %bpl
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
jne 0x1287e
jmp 0x12883
movq %rax, %r14
leaq 0xf0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12870
callq 0xb730
jmp 0x12870
movq %rax, %r14
movb $0x1, %bpl
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12883
callq 0xb730
movq 0x8(%rsp), %rdi
jmp 0x128ec
jmp 0x128fd
movq %rax, %r14
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x128a5
callq 0xb730
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x128f1
jmp 0x128f6
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x128d7
jmp 0x12900
jmp 0x128ca
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x12900
callq 0xb730
jmp 0x12900
jmp 0x128fd
jmp 0x128fd
jmp 0x128fd
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x128f6
callq 0xb730
testb %bpl, %bpl
jne 0x12900
jmp 0x12908
movq %rax, %r14
movq %rbx, %rdi
callq 0xb5b0
movq %r14, %rdi
callq 0xbce0