// File: nickgammon[P]tinymudserver/comms.cpp
// Function: MainLoop()
void MainLoop ()
{
  // loop processing input, output, events
  do
    {

    // We will go through this loop roughly every COMMS_WAIT_SEC/COMMS_WAIT_USEC
    // seconds (at present 0.5 seconds).
    PeriodicUpdates ();   // do things that don't rely on player input
      
    // delete players who have closed their comms - have to do it outside other loops to avoid 
    // access violations (iterating loops that have had items removed)
    RemoveInactivePlayers ();
      
    // get ready for "select" function ... 
    FD_ZERO (&in_set);
    FD_ZERO (&out_set);
    FD_ZERO (&exc_set);

    // add our control socket (for new connections)
    FD_SET (iControl, &in_set);

    // set bits in in_set, out_set etc. for each connected player
    int iMaxdesc = for_each (playerlist.begin (), playerlist.end (), 
                             setUpDescriptors (iControl)).GetMax ();
    
    // set up timeout interval
    struct timeval timeout;
    timeout.tv_sec = COMMS_WAIT_SEC;    // seconds
    timeout.tv_usec = COMMS_WAIT_USEC;  // + 1000th. of second

    // check for activity, timeout after 'timeout' seconds
    if (select (iMaxdesc + 1, &in_set, &out_set, &exc_set, &timeout) > 0)
      {
      // New connection on control port?
      if (FD_ISSET (iControl, &in_set))
        ProcessNewConnection ();
      
      // handle all player input/output
      for_each (playerlist.begin (), playerlist.end (), 
                processDescriptors ());      
      } // end of something happened
  
    }  while (!bStopNow);   // end of looping processing input

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
callq 0x65b0
callq 0x1a3e0
leaq 0xf4e4(%rip), %rax      # 0x29b70
movq %rax, -0x10(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpq $0x10, %rax
jae 0x1a6ba
movq -0x10(%rbp), %rax
movl -0x4(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x1a697
jmp 0x1a6bc
jmp 0x1a6be
leaq 0xf52b(%rip), %rax      # 0x29bf0
movq %rax, -0x20(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpq $0x10, %rax
jae 0x1a6f3
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1a6d0
jmp 0x1a6f5
jmp 0x1a6f7
leaq 0xf572(%rip), %rax      # 0x29c70
movq %rax, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpq $0x10, %rax
jae 0x1a72c
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1a709
jmp 0x1a72e
leaq 0xeceb(%rip), %rax      # 0x29420
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x80(%rbp)
leaq 0xecca(%rip), %rax      # 0x29420
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x80(%rbp), %rdx
movslq %eax, %rcx
leaq 0xf402(%rip), %rax      # 0x29b70
orq (%rax,%rcx,8), %rdx
leaq 0xf3f7(%rip), %rax      # 0x29b70
movq %rdx, (%rax,%rcx,8)
leaq 0xf1ac(%rip), %rdi      # 0x29930
callq 0x8a40
movq %rax, -0x40(%rbp)
leaq 0xf19c(%rip), %rdi      # 0x29930
callq 0x8a70
movq %rax, -0x48(%rbp)
leaq 0xec7c(%rip), %rax      # 0x29420
movl (%rax), %esi
leaq -0x4c(%rbp), %rdi
callq 0x1af90
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x4c(%rbp), %edx
callq 0x1af30
movl %eax, -0x38(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1afb0
movl %eax, -0x34(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x7a120, -0x58(%rbp)   # imm = 0x7A120
movl -0x34(%rbp), %edi
addl $0x1, %edi
leaq 0xf385(%rip), %rsi      # 0x29b70
leaq 0xf3fe(%rip), %rdx      # 0x29bf0
leaq 0xf477(%rip), %rcx      # 0x29c70
leaq -0x60(%rbp), %r8
callq 0x43f0
cmpl $0x0, %eax
jle 0x1a891
leaq 0xec0e(%rip), %rax      # 0x29420
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movslq %eax, %rcx
leaq 0xf34a(%rip), %rax      # 0x29b70
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
leaq 0xebe8(%rip), %rax      # 0x29420
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x88(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x1a864
callq 0x19f60
leaq 0xf0c5(%rip), %rdi      # 0x29930
callq 0x8a40
movq %rax, -0x68(%rbp)
leaq 0xf0b5(%rip), %rdi      # 0x29930
callq 0x8a70
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x1afc0
jmp 0x1a893
leaq 0xf086(%rip), %rax      # 0x29920
movb (%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1a67b
addq $0x90, %rsp
popq %rbp
retq
nop