// File: /workspace/github_cpp_makefile_star2_O1/tylerkaraszewski[P]Argyle/Server.cpp
// Function: Server::start()
bool Server::start()
{
  if (listen(m_mainSocket, 10))
  {
    m_logger.logError("Listen error(" + Utils::llToString(errno) + "): " + strerror(errno));
    close(m_mainSocket);
    return false;
  }

  initSocketList();

  while (m_shouldQuit == false)
  {
    int n = poll(m_sockets, m_socketCount, 1000);
    if (n == -1)
    {
      if (errno == EINTR)
      {
        // This happens when we try and exit. For a legit exit, m_shouldQuit should be set. For some other signal,
        // we'll just try and continue.
        continue;
      }
      m_logger.logError("Poll error(" + Utils::llToString(errno) + "): " + strerror(errno));
      close(m_mainSocket);
      return false;
    }
    // No socket activity, just start the next loop.
    if (n == 0)
    {
      continue;
    }

    int socketToWatch = -1;
    vector<int> socketsToUnwatch;
    for (int i = 0; i < m_socketCount; ++i)
    {
      // General error check.
      if (m_sockets[i].revents & POLLERR)
      {
        socketsToUnwatch.push_back(m_sockets[i].fd);
        continue;
      }
      if (m_sockets[i].revents & POLLHUP)
      {
        socketsToUnwatch.push_back(m_sockets[i].fd);
        continue;
      }
      if (m_sockets[i].revents & POLLNVAL)
      {
        socketsToUnwatch.push_back(m_sockets[i].fd);
        continue;
      }

      // Special socket.
      if (m_sockets[i].fd == m_mainSocket)
      {
        if (m_sockets[i].revents & POLLIN)
        {
          struct sockaddr_in newAddress;
          socklen_t newAddressSize = sizeof(newAddress);
          int newSocket = accept(m_mainSocket, (struct sockaddr*)&m_address, &newAddressSize);
          if (newSocket != -1)
          {
            socketToWatch = newSocket;
          }
          else
          {
            m_logger.logError("Accept error(" + Utils::llToString(errno) + "): " + strerror(errno));
          }
        }
      }
      else
      {
        bool isFinished = m_connections[m_sockets[i].fd]->process(m_sockets[i].events, m_sockets[i].revents);
        if (isFinished)
        {
          socketsToUnwatch.push_back(m_sockets[i].fd);
        }
      }
    }

    // @TODO: Timeout expiration goes here (or possibly after the 'unwatchSockets' call below).

    // Rebuild our socket list if anything has changed.
    unwatchSockets(socketsToUnwatch);
    watchSocket(socketToWatch);
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movl (%rdi), %edi
movl $0xa, %esi
callq 0x32d0
testl %eax, %eax
je 0x4100
movq 0x58(%rbx), %r14
callq 0x3040
movq %rax, %r15
movslq (%rax), %rsi
leaq 0x88(%rsp), %r12
movq %r12, %rdi
callq 0xac34
leaq 0x7f90(%rip), %rcx      # 0xc050
movl $0xd, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq 0x20(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x44a0
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x44a8
movq %rbx, %rdi
callq 0x4954
movb $0x1, %al
cmpb $0x0, 0x16(%rbx)
jne 0x45ef
leaq 0x18(%rbx), %r14
leaq 0x48(%rbx), %rax
movq %rax, 0xc0(%rsp)
leaq 0x70(%rsp), %r13
movq %r14, 0xb0(%rsp)
movq 0x8(%rbx), %rdi
movslq 0x10(%rbx), %rsi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x3410
testl %eax, %eax
je 0x448f
cmpl $-0x1, %eax
jne 0x4163
callq 0x3040
cmpl $0x4, (%rax)
je 0x448f
jmp 0x4601
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
cmpl $0x0, 0x10(%rbx)
jle 0x4456
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x8(%rbx), %rdx
movzwl 0x6(%rdx,%rbp), %eax
addq %rbp, %rdx
testb $0x8, %al
jne 0x425c
testb $0x10, %al
jne 0x425c
testb $0x20, %al
jne 0x425c
movl (%rbx), %edi
cmpl %edi, (%rdx)
jne 0x429b
testb $0x1, %al
je 0x4282
movl $0x10, 0xac(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0xac(%rsp), %rdx
callq 0x3100
cmpl $-0x1, %eax
jne 0x444d
movq 0x58(%rbx), %rax
movq %rax, 0xb8(%rsp)
callq 0x3040
movq %rax, %r14
movslq (%rax), %rsi
leaq 0x88(%rsp), %r12
movq %r12, %rdi
callq 0xac34
movl $0xd, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x7e42(%rip), %rcx      # 0xc06a
callq 0x32e0
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x42e6
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x42ec
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0x427a
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x78(%rsp)
jmp 0x4282
movq %r13, %rdi
callq 0x4dfc
incq %r15
movslq 0x10(%rbx), %rax
addq $0x8, %rbp
cmpq %rax, %r15
jl 0x418e
jmp 0x445e
movq %r14, %rdi
movq %rdx, %rsi
callq 0x4d3c
movq (%rax), %rdi
movq 0x8(%rbx), %rax
leaq (%rax,%rbp), %rsi
addq $0x4, %rsi
leaq (%rax,%rbp), %rdx
addq $0x6, %rdx
callq 0x5326
testb %al, %al
je 0x4282
movq 0x8(%rbx), %rdx
addq %rbp, %rdx
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
jne 0x426b
movq %r13, %rdi
callq 0x4dfc
jmp 0x4282
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x10(%rsp), %rdi
leaq 0x7d1e(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x40(%rsp), %rsi
movq %rsi, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x433d
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x4343
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r14), %edi
callq 0x3120
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x60(%rsp), %rsi
movq %rsi, 0x50(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0x20(%rsp), %r14
je 0x439d
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x43a3
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xb8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xac26
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x43e9
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4405
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x441c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
movq 0xb0(%rsp), %r14
je 0x4449
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
movl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
jmp 0x4282
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4a00
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x4b60
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x448f
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
cmpb $0x0, 0x16(%rbx)
je 0x4131
movb $0x1, %al
jmp 0x45ef
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x7b63(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x40(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x44f7
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x44fe
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
leaq 0x30(%rsp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r15), %edi
callq 0x3120
movq %r12, %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4555
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x455c
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x50(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0xac26
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x4597
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x45ae
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x45c5
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x45e6
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
movl (%rbx), %edi
callq 0x3580
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq 0x58(%rbx), %r14
movslq (%rax), %rsi
leaq 0x88(%rsp), %r12
movq %r12, %rdi
callq 0xac34
leaq 0x7a3c(%rip), %rcx      # 0xc05e
movl $0xb, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x465c
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x4662
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x79a9(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x40(%rsp), %rsi
movq %rsi, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x46b2
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x46b8
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x30(%rsp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r15), %edi
callq 0x3120
movq %r12, %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x60(%rsp), %rsi
movq %rsi, 0x50(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4710
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x4716
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x50(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0xac26
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
leaq 0x20(%rsp), %r14
je 0x475b
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4777
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x478e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
jmp 0x45d1
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x47c7
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x47c7
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x47e8
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x47e8
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4809
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4809
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
jmp 0x4917
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4842
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4842
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4863
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4863
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4884
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4884
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x4932
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4932
jmp 0x492f
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x48d3
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x48d3
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x48ef
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x48ef
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x490b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x490b
movq %rax, %rbx
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x494c
movq 0x98(%rsp), %rsi
incq %rsi
jmp 0x4947
jmp 0x492f
jmp 0x492f
jmp 0x492f
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x494c
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x3520