// File: 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:
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rsi, 0x98(%rsp)
movq %rdi, 0x2a0(%rsp)
movq %rsi, 0x298(%rsp)
movl %edx, 0x294(%rsp)
movq 0x2a0(%rsp), %rax
movq %rax, 0xa0(%rsp)
cmpl $0x0, 0x294(%rsp)
jle 0x3f061
cmpl $0xffff, 0x294(%rsp) # imm = 0xFFFF
jle 0x3f14f
movb $0x1, 0x243(%rsp)
movl $0x48, %edi
callq 0x28e70
movq %rax, 0x88(%rsp)
leaq 0x257(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x2b730
movq 0x90(%rsp), %rdx
leaq 0x74b1(%rip), %rsi      # 0x46550
leaq 0x258(%rsp), %rdi
callq 0x2aa80
jmp 0x3f0ae
movq 0x88(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x2a7b0
jmp 0x3f0c5
movq 0x88(%rsp), %rdi
movb $0x0, 0x243(%rsp)
movq 0x13eec(%rip), %rsi     # 0x52fc8
movq 0x13e65(%rip), %rdx     # 0x52f48
callq 0x2b540
jmp 0x3f9cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f124
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x29360
leaq 0x257(%rsp), %rdi
callq 0x2a210
testb $0x1, 0x243(%rsp)
jne 0x3f13d
jmp 0x3f14a
movq 0x88(%rsp), %rdi
callq 0x29690
jmp 0x3f9be
movq 0xa0(%rsp), %rdi
movq 0x98(%rsp), %rsi
addq $0x8, %rdi
callq 0x28090
movq 0xa0(%rsp), %rax
movl 0x294(%rsp), %ecx
movl %ecx, 0x28(%rax)
leaq 0x73e1(%rip), %rdi      # 0x46562
callq 0x28ba0
movq %rax, 0x278(%rsp)
cmpq $0x0, 0x278(%rsp)
je 0x3f1ad
movq 0x278(%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, 0x84(%rsp)
jmp 0x3f1b8
xorl %eax, %eax
movl %eax, 0x84(%rsp)
jmp 0x3f1b8
movl 0x84(%rsp), %edx
movl $0x2, %edi
movl $0x1, %esi
callq 0x285a0
movq 0xa0(%rsp), %rcx
movl %eax, 0x2c(%rcx)
cmpl $-0x1, %eax
jne 0x3f38d
movb $0x1, 0x1d6(%rsp)
movl $0x48, %edi
callq 0x28e70
movq %rax, 0x70(%rsp)
leaq 0x1ff(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x2b730
movq 0x78(%rsp), %rdx
leaq 0x734f(%rip), %rsi      # 0x46566
leaq 0x200(%rsp), %rdi
callq 0x2aa80
jmp 0x3f226
callq 0x3f9d0
movl %eax, 0x6c(%rsp)
jmp 0x3f231
movl 0x6c(%rsp), %edi
callq 0x28970
movq %rax, 0x58(%rsp)
leaq 0x1d7(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x2b730
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x1d8(%rsp), %rdi
callq 0x2aa80
jmp 0x3f26a
leaq 0x220(%rsp), %rdi
leaq 0x200(%rsp), %rsi
leaq 0x1d8(%rsp), %rdx
callq 0x29b70
jmp 0x3f289
movq 0x70(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x2a7b0
jmp 0x3f29d
movq 0x70(%rsp), %rdi
movb $0x0, 0x1d6(%rsp)
movq 0x13d17(%rip), %rsi     # 0x52fc8
movq 0x13c90(%rip), %rdx     # 0x52f48
callq 0x2b540
jmp 0x3f9cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f358
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f34b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f33e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x220(%rsp), %rdi
callq 0x29360
leaq 0x1d8(%rsp), %rdi
callq 0x29360
leaq 0x1d7(%rsp), %rdi
callq 0x2a210
leaq 0x200(%rsp), %rdi
callq 0x29360
leaq 0x1ff(%rsp), %rdi
callq 0x2a210
testb $0x1, 0x1d6(%rsp)
jne 0x3f37e
jmp 0x3f388
movq 0x70(%rsp), %rdi
callq 0x29690
jmp 0x3f9be
movq 0xa0(%rsp), %rax
movl 0x2c(%rax), %edi
callq 0x3f9e0
testb $0x1, %al
jne 0x3f520
movb $0x1, 0x166(%rsp)
movl $0x48, %edi
callq 0x28e70
movq %rax, 0x48(%rsp)
leaq 0x18f(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x2b730
movq 0x50(%rsp), %rdx
leaq 0x718c(%rip), %rsi      # 0x46566
leaq 0x190(%rsp), %rdi
callq 0x2aa80
jmp 0x3f3e9
leaq 0x167(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x2b730
movq 0x40(%rsp), %rdx
leaq 0x7169(%rip), %rsi      # 0x46570
leaq 0x168(%rsp), %rdi
callq 0x2aa80
jmp 0x3f416
leaq 0x1b0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
leaq 0x168(%rsp), %rdx
callq 0x29b70
jmp 0x3f435
movq 0x48(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x2a7b0
jmp 0x3f449
movq 0x48(%rsp), %rdi
movb $0x0, 0x166(%rsp)
movq 0x13b6b(%rip), %rsi     # 0x52fc8
movq 0x13ae4(%rip), %rdx     # 0x52f48
callq 0x2b540
jmp 0x3f9cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f4f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f4de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f4d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x29360
leaq 0x168(%rsp), %rdi
callq 0x29360
leaq 0x167(%rsp), %rdi
callq 0x2a210
leaq 0x190(%rsp), %rdi
callq 0x29360
leaq 0x18f(%rsp), %rdi
callq 0x2a210
testb $0x1, 0x166(%rsp)
jne 0x3f511
jmp 0x3f51b
movq 0x48(%rsp), %rdi
callq 0x29690
jmp 0x3f9be
leaq 0x284(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x29060
movw $0x2, 0x284(%rsp)
movl 0x294(%rsp), %eax
movzwl %ax, %edi
callq 0x28140
movq 0x98(%rsp), %rdi
movw %ax, 0x286(%rsp)
callq 0x28b90
movq %rax, %rsi
leaq 0x284(%rsp), %rdx
addq $0x4, %rdx
movl $0x2, %edi
callq 0x2bbe0
cmpl $0x0, %eax
jge 0x3f6ce
movb $0x1, 0x11e(%rsp)
movl $0x48, %edi
callq 0x28e70
movq %rax, 0x30(%rsp)
callq 0x3f9d0
movl %eax, 0x3c(%rsp)
jmp 0x3f5a6
movl 0x3c(%rsp), %edi
callq 0x28970
movq %rax, 0x20(%rsp)
leaq 0x11f(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x2b730
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x120(%rsp), %rdi
callq 0x2aa80
jmp 0x3f5df
leaq 0x6f80(%rip), %rsi      # 0x46566
leaq 0x140(%rsp), %rdi
leaq 0x120(%rsp), %rdx
callq 0x2b480
jmp 0x3f5fd
movq 0x30(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x2a230
jmp 0x3f611
movq 0x30(%rsp), %rdi
movb $0x0, 0x11e(%rsp)
movq 0x1391b(%rip), %rsi     # 0x52f40
movq 0x13924(%rip), %rdx     # 0x52f50
callq 0x2b540
jmp 0x3f9cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f6b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f6a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f699
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x29360
leaq 0x120(%rsp), %rdi
callq 0x29360
leaq 0x11f(%rsp), %rdi
callq 0x2a210
testb $0x1, 0x11e(%rsp)
jne 0x3f6bf
jmp 0x3f6c9
movq 0x30(%rsp), %rdi
callq 0x29690
jmp 0x3f9be
movq 0xa0(%rsp), %rax
movl 0x2c(%rax), %edi
leaq 0x284(%rsp), %rsi
movl $0x10, %edx
callq 0x29aa0
cmpl $0x0, %eax
jge 0x3f84c
callq 0x280d0
cmpl $0x73, (%rax)
je 0x3f84a
movb $0x1, 0xd6(%rsp)
movl $0x48, %edi
callq 0x28e70
movq %rax, 0x10(%rsp)
callq 0x3f9d0
movl %eax, 0x1c(%rsp)
jmp 0x3f724
movl 0x1c(%rsp), %edi
callq 0x28970
movq %rax, (%rsp)
leaq 0xd7(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x2b730
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0xd8(%rsp), %rdi
callq 0x2aa80
jmp 0x3f75b
leaq 0x6e04(%rip), %rsi      # 0x46566
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rdx
callq 0x2b480
jmp 0x3f779
movq 0x10(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x2a230
jmp 0x3f78d
movq 0x10(%rsp), %rdi
movb $0x0, 0xd6(%rsp)
movq 0x1379f(%rip), %rsi     # 0x52f40
movq 0x137a8(%rip), %rdx     # 0x52f50
callq 0x2b540
jmp 0x3f9cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f82f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f822
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x3f815
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x29360
leaq 0xd8(%rsp), %rdi
callq 0x29360
leaq 0xd7(%rsp), %rdi
callq 0x2a210
testb $0x1, 0xd6(%rsp)
jne 0x3f83b
jmp 0x3f845
movq 0x10(%rsp), %rdi
callq 0x29690
jmp 0x3f9be
jmp 0x3f84c
jmp 0x3f84e
movq 0xa0(%rsp), %rax
addq $0xe8, %rax
movq %rax, 0xc8(%rsp)
movl $0x0, 0xd0(%rsp)
movl 0xd0(%rsp), %eax
cmpq $0x10, %rax
jae 0x3f8a6
movq 0xc8(%rsp), %rax
movl 0xd0(%rsp), %ecx
movq $0x0, (%rax,%rcx,8)
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x3f86f
jmp 0x3f8a8
movq 0xa0(%rsp), %rdi
movl 0x2c(%rdi), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl 0x2c(%rdi), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq 0xe8(%rdi,%rax,8), %rcx
movq %rcx, 0xe8(%rdi,%rax,8)
addq $0x168, %rdi            # imm = 0x168
movl $0x1, %esi
callq 0x289c0
movq 0xa0(%rsp), %rdi
addq $0x30, %rdi
callq 0x28560
testb $0x1, %al
jne 0x3f97b
movq 0xa0(%rsp), %rax
movq 0x136b4(%rip), %rcx     # 0x52fd0
movq %rcx, 0xb0(%rsp)
movq $0x0, 0xb8(%rsp)
movq %rax, 0xa8(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x2b750
movq 0xa0(%rsp), %rdi
addq $0x30, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x2b350
leaq 0xc0(%rsp), %rdi
callq 0x2b010
movq 0xa0(%rsp), %rdi
addq $0xc8, %rdi
callq 0x2a1e0
testb $0x1, %al
jne 0x3f995
jmp 0x3f9b6
movq 0xa0(%rsp), %rsi
movq %rsi, %rdi
addq $0xc8, %rdi
movq %rsi, %rdx
addq $0x8, %rdx
movl 0x28(%rsi), %ecx
callq 0x29630
addq $0x2a8, %rsp            # imm = 0x2A8
retq
movq 0x248(%rsp), %rdi
callq 0x2b6f0
nopl (%rax,%rax)