// File: tylerkaraszewski[P]Argyle/Server.cpp
// Function: Server::unwatchSockets(std::vector<int, std::allocator<int>> const&)
void Server::unwatchSockets(const vector<int>& socketsToUnwatch)
{
  if (socketsToUnwatch.size() == 0)
  {
    return;
  }

  int shiftBy = 0;
  vector<int>::const_iterator it = socketsToUnwatch.begin();
  for (int i = 0; i < m_socketCount; ++i)
  {
    // If this is one of the sockets we're closing, we'll do that.
    if (m_sockets[i].fd == *it)
    {
      shutdown(*it, SHUT_RDWR);
      close(*it);
      delete m_connections[*it];
      m_connections.erase(*it);
      ++shiftBy;
      ++it;
    }

    // Otherwise, we shift our array entries down.
    else if(shiftBy != 0)
    {
      memcpy(&m_sockets[i - shiftBy], &m_sockets[i], sizeof(struct pollfd));
    }
  }
  m_socketCount -= shiftBy;
  m_sockets = (struct pollfd*)realloc(m_sockets, sizeof(struct pollfd) * m_socketCount);
  if (m_sockets == 0)
  {
    // Seems pretty much impossible since we're *shrinking* it, but whatever.
    m_logger.logError("Unwatchsockets realloc error.");
  }
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x88(%rsp), %rdi
callq 0x6510
cmpq $0x0, %rax
jne 0x5d0c
jmp 0x5f36
movl $0x0, 0x84(%rsp)
movq 0x88(%rsp), %rdi
callq 0x6530
movq %rax, 0x78(%rsp)
movl $0x0, 0x74(%rsp)
movq 0x30(%rsp), %rcx
movl 0x74(%rsp), %eax
cmpl 0x10(%rcx), %eax
jge 0x5e6c
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x74(%rsp), %rcx
movl (%rax,%rcx,8), %eax
movl %eax, 0x2c(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x6560
movq %rax, %rcx
movl 0x2c(%rsp), %eax
cmpl (%rcx), %eax
jne 0x5e26
leaq 0x78(%rsp), %rdi
callq 0x6560
movl (%rax), %edi
movl $0x2, %esi
callq 0x4550
leaq 0x78(%rsp), %rdi
callq 0x6560
movl (%rax), %edi
callq 0x4750
movq 0x30(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x18(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x6560
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x6300
movq (%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
je 0x5de4
movq 0x20(%rsp), %rdi
callq 0x96d0
movq 0x20(%rsp), %rdi
movl $0x80, %esi
callq 0x43c0
movq 0x30(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x10(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x6560
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x6570
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x65a0
jmp 0x5e5a
cmpl $0x0, 0x84(%rsp)
je 0x5e58
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rax
movl 0x74(%rsp), %ecx
subl 0x84(%rsp), %ecx
movslq %ecx, %rcx
movq 0x8(%rdx), %rdx
movslq 0x74(%rsp), %rsi
movq (%rdx,%rsi,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x5e5a
jmp 0x5e5c
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x5d31
movq 0x30(%rsp), %rax
movl 0x84(%rsp), %edx
movl 0x10(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x10(%rax)
movq 0x8(%rax), %rdi
movslq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x4660
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, 0x8(%rax)
jne 0x5f36
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, (%rsp)
leaq 0x4f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x46c0
movq 0x8(%rsp), %rdx
leaq 0xd1e3(%rip), %rsi      # 0x130b3
leaq 0x50(%rsp), %rdi
callq 0x6450
jmp 0x5edc
movq (%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x10f40
jmp 0x5eec
leaq 0x50(%rsp), %rdi
callq 0x4788
leaq 0x4f(%rsp), %rdi
callq 0x4400
jmp 0x5f36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
jmp 0x5f2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x4788
leaq 0x4f(%rsp), %rdi
callq 0x4400
jmp 0x5f3e
addq $0x98, %rsp
retq
movq 0x40(%rsp), %rdi
callq 0x46b0
nopl (%rax,%rax)